Domanda

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?

È stato utile?

Soluzione

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

Altri suggerimenti

We had the same problem. The thing is SOLR will not index nested contents by itself, you have to say whether or not the field should be indexed or not.

For Instance, lets say we have a Event XSD, containing Information concerning the Event and the 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 the companys 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 mapping will give us the Informatione we want

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

When doing this on existing ressources, dont forget to reindex your solar index!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top