solropencms

Mapping OpenCMS structured content XML field to a SOLR field


We are trying to map an OpenCMS structured content XML field to a SOLR field in order to perform a search using that field as a filter.

The XML field is described this way in the XSD file:

<xsd:complexType name="OpenCmsContrato">
    <xsd:sequence>
    [...]
        <xsd:element name="numeroExpediente" type="OpenCmsString" minOccurs="1" maxOccurs="1" />
    [...]
    </xsd:sequence>
    <xsd:attribute name="language" type="OpenCmsLocale" use="required"/>
</xsd:complexType>

And these are the search settings for the element, defined in the same XSD file:

<xsd:annotation>
    <xsd:appinfo>
    [...]
        <searchsettings>
            <searchsetting element="numeroExpediente" searchcontent="true">
                <solrfield targetfield="numexp" />
            </searchsetting>
        </searchsettings>
    [...]
    </xsd:appinfo>
</xsd:annotation>

The target SOLR field "numexp" is defined this way in SOLR's schema.xml file:

<fields>
    <field name="numexp"                 type="string"       indexed="true"  stored="true" />
    [...]
</fields>

And this is the way we perform the query to SOLR on a JSP file:

CmsSearchManager manager = OpenCms.getSearchManager();
CmsSolrIndex index = manager.getIndexSolr("Solr Online");

String query = "fq=type:contrato";

if (!"".equals(text))
    query += "&fq=numexp:" + text;

CmsSolrResultList listFiles = index.search(cmso, query);

When we execute this code, we get listFiles.size() = 0, but when we change the filter field to the predifined SOLR field "content", this way:

if (!"".equals(text))
    query += "&fq=content:" + text;

we get the expected result.

With the CmsSearchResource object we get using the "content" SOLR field as filter, we are able to iterate over the fields of its inner I_CmsSearchDocument, getting this list as result:

id
contentblob
path
type
suffix
created
lastmodified
contentdate
relased
expired
res_locales
con_locales
template_prop
default-file_prop
notification-interval_prop
NavPos_prop
enable-notification_prop
locale_prop
NavText_prop
Title_prop
category
ca_excerpt
timestamp
score
link

No presence of the "numexp" field on the list. Why? Are we missing any step? Do we have to configure something else in order to make the mapping work?


Solution

  • Some months ago i had the same problem. I think this is your problem

    <searchsetting element="numeroExpediente" searchcontent="true">
         <solrfield targetfield="numexp" />
    </searchsetting>
    

    you have to change to this

    <searchsetting element="numeroExpediente" searchcontent="true">
         <solrfield targetfield="numexp" sourcefield="*_s" />
    </searchsetting>
    

    You have to set the type of the solrfield, take a look to the differents types, in the SOLR's schema.xml, i do this for some category in the blog element. Work in v9.0.1