简体   繁体   中英

Defining a Sitecore Field in Solr's schema.xml

I have a custom text field on a Data Template in my Sitecore 7 instance called CountryName. I've set up a search result item that returns this field.

    [IndexField("CountryName")]
    public string CountryName { get; set; }

The field is being indexed by Solr due to the catchall Sitecore configuration in my Solr schema.xml. However, using the default tokenizer causes calls to sort this field to be problematic and sort out of order. I'd prefer to use a field type of alphaOnlySort in order to mitigate this problem.

I've tried adding the following two lines to my Solr Schema.xml file, with no luck:

<field name="CountryName" type="alphaOnlySort" indexed="true" stored="true" />
<dynamicField name="Country*" type="alphaOnlySort" indexed="true" stored="true" />

This hasn't worked. If I change the *_t DynamicField definition to use alphaOnlySort, it works like a charm. I know I'm simply missing a step somewhere. Can someone please point out where I'm missing a step? Thanks!

You need to match the field name that SiteCore is sending. You can check that in Admin UI or just by querying directly against the Solr index.

I don't know Sitecore, but from your description, it must be adding _t suffixes to the names to make sure they match to the dynamicField definition.

So, you may need to use:

<field name="CountryName_t" type="alphaOnlySort" indexed="true" stored="true" />

And remember to reindex afterwards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM