[opencms-dev] How to map field of nested choice xsd to property andsolrfield?

Tobias Karrer kartobi at gmail.com
Fri Dec 12 14:24:48 CET 2014


Hi all,

stepped on the same problem with the [index] brackets (version 9.0.1).

Is there a possiblitiy to map a specific subelement directly to solr 
field like Mathias described below:

<searchsetting element="OptionalElements[2]/FeaturedImage" 
searchcontent="true">
     <solrfield targetfield="afeaturedimage" />
</searchsetting>

Maybe in 9.5 ?

Found two things, how it works, but a direct mapping would be preferable 
and straight forward:

1. Use a specific property, as properties always are mapped to Solr,
<mapping element="OptionalElements[2]/FeaturedImage" 
mapto="property:FeaturedImage"/>
and read field FeaturedImage_prop afterwards:
<str name="FeaturedImage_prop">
     /sites/default/_images/image2.png
</str>


2. Map all elements
<searchsetting element="OptionalElements/FeaturedImage" 
searchcontent="true">
     <solrfield targetfield="afeaturedimage" />
</searchsetting>
and select the desired one out of the list afterwards:
<str name="afeaturedimage">
     /sites/default/_images/image1.jpg /sites/default/_images/image2.png 
/sites/default/_images/image3.png
</str>

Regards,
Tobias

Am 26.08.2013 08:19, schrieb Mathias Lin:
> How to map field of nested choice xsd to property andsolrfield?
> How do you configure a field mapping from a nested xsd, which has choices?
>
> Since it's not clear at what position the certain choice element is, I am
> not sure how to configure the mapping.
>
> Furthermore, how do you configure a searchsetting/solrfield for such nested
> choice element? Does it also need to be configured in the parent xsd or in
> the nested xsd?
>
> The OpenCms documentation unfortunately doesn't give that much info about
> those cases.
>
>
> Below is an article.xsd, which embeds a article-choices.xsd.
>
>
>      <xsd:complexType name="OpenCmsMAArticle">
>          <xsd:sequence>
>              <xsd:element name="Title" type="OpenCmsString" minOccurs="1"
> maxOccurs="1"/>
>              <xsd:element name="Subtitle" type="OpenCmsString" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="Teaser" type="OpenCmsString" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="Text" type="OpenCmsHtml" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="DetailViewPage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
> *            <xsd:element name="OptionalElements"
> type="OpenCmsMAArticleChoice" minOccurs="0" maxOccurs="unbounded"/>*
>          </xsd:sequence>
>          <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
>      </xsd:complexType>
>
>
>      <xsd:complexType name="OpenCmsMAArticleChoice">
>          <xsd:choice>
>              <xsd:element name="FeaturedImage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="LandingPageImage" type="OpenCmsVfsFile"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="Image" type="OpenCmsVfsFile" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="IFrame" type="OpenCmsString" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="Video" type="OpenCmsMAVideo" minOccurs="0"
> maxOccurs="1"/>
>              <xsd:element name="LeftButton" type="OpenCmsMAButton"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="RightButton" type="OpenCmsMAButton"
> minOccurs="0" maxOccurs="1"/>
>              <xsd:element name="ReleaseDate" type="OpenCmsDateTime"
> minOccurs="0" maxOccurs="1"/>
>          </xsd:choice>
>          <xsd:attribute name="language" type="OpenCmsLocale" use="optional"/>
>      </xsd:complexType>
>
>
> My question now is, how can I map the nested OptionalElements/ReleaseDate
> to attribute:datereleased ?
>
> The approach below seems to work for the first mapping of a choice element,
> but it doesn't "feel right". Do I really need to configure a mapping for
> all the 7 position at which the choice item could be?
> Assuming that there can be a maximum of 7 choice elements (number of
> elements in my article-choice.xsd), I mapped all of them to the attribute,
> which seems to work that OpenCms only takes the
>
>              <mappings>
>                  <mapping element="Title" mapto="property:Title"/>
>                  <mapping element="OptionalElements[1]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[2]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[3]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[4]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[5]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[6]/ReleaseDate"
> mapto="attribute:datereleased"/>
>                  <mapping element="OptionalElements[7]/ReleaseDate"
> mapto="attribute:datereleased"/>
>
> However, when I want to add further mappings for other choice elements,
> this approach doesn't work.
>
>
> Also, how to map such field to a searchsetting / solrfield? Do I add it to
> the parent or the nested xsd? Because using brackets for the [index]
> doesn't seem to be valid syntax.
>
> This doesn't work:
>
> <searchsetting element="OptionalElements[2]/FeaturedImage"
> searchcontent="true">
>      <solrfield targetfield="afeaturedimage" />
> </searchsetting>
>
> Thanks.
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20141212/31d7a468/attachment.htm>


More information about the opencms-dev mailing list