Mapping OpenCMS Structured Content XML Field to 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 like this 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 parameters for an 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 SOLR target field "numexp" is defined in this way in the SOLR schema.xml file:

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

      

And this is how we execute the SOLR request in the 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 "SOLR" prefix field, like this:

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

      

we get the expected result.

With the CmsSearchResource object we get the use of the SOLR "content" field as a filter, we can iterate over the fields of our internal I_CmsSearchDocument object, getting this list as a 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

      

The "numexp" field is missing in the list. What for? Did we miss a step? Do we need to configure something else to do mapping?

+3


source to share


2 answers


Several months ago I had the same problem. I think this is your problem.

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

      

you must change to this



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

      

You have to set the type solrfield, take a look at the different types, in the SOLR schema.xml, I am doing this for some category in the blog element. Working in version 9.0.1

+2


source


We had the same problem. The point is that SOLR will not index the nested content on its own, you have to say if the field should be indexed or not.

For an instance, let's say we have an XSD event containing information about an event and company:

<xsd:complexType name="OpenCmsEvent">
    <xsd:sequence>
        <xsd:element name="EventInformation" type="OpenCmsEventInformation" minOccurs="1" maxOccurs="1" />
        <xsd:element name="EventHost" type="OpenCmsEventHost" minOccurs="0" maxOccurs="1" />
    </xsd:sequence>
    <xsd:attribute name="language" type="OpenCmsLocale" use="required" />
</xsd:complexType>

      

We want to know the links to companies from Eventhost



<xsd:complexType name="OpenCmsEventHost">
    <xsd:sequence>
        <xsd:element name="company" type="OpenCmsVfsFile" minOccurs="1" maxOccurs="unbounded" />
    </xsd:sequence>
    <xsd:attribute name="language" type="OpenCmsLocale" use="optional" />
</xsd:complexType>

      

The following display will give us the information we want

<searchsettings>
    <searchsetting element="EventHost/company" searchcontent="true">
            <solrfield targetfield="companyurl"/>
    </searchsetting>
</searchsettings>

      

If you're doing this on existing resources, don't forget to re-index your sun pointer!

+1


source







All Articles