5

I have a Category field in sitecore and it is currently stored as a text_general in Solr. It has this type because I need it to be tokenized and lowercase for searching.

On the other hand I need to do a grouping of the results by this field and for this the field has to be single-valued (single token).

So I think that the best way would be to duplicate this field in Solr and store it with two different types: category_s for grouping and category_t for searching.

What is the best way to achive this? Is it possible to do this in sitecore config patch without touching the schema.xml file?

I use Solr 6.1 with Sitecore 8.2

5

I figured out that we have two options:

1. Use Solr to copy field

The Solr documentation says:

You might want to interpret some document fields in more than one way. Solr has a mechanism for making copies of fields so that you can apply several distinct field types to a single piece of incoming information.

The name of the field you want to copy is the source, and the name of the copy is the destination.

In schema.xml it's very easy to make copies of the fields:

<copyField source="category_t" dest="category_s"/>

2. Duplicate field definition in sitecore index config file

Inside Sitecore.ContentSearch.Solr.DefaultIndexConfiguration.config or your custom one, you can add your field definition twice. If it is computed field just add it twice like this:

<fields hint="raw:AddComputedIndexField">
    <field fieldName="category" returnType="text">YourNamespace.YourField,YourNamespace</field>
    <field fieldName="category_2" returnType="text">YourNamespace.YourField,YourNamespace</field>
</fields>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.