Field for Faceting/Sorting in Sitecore

In this guide you will learn how to create a field to facet or sort on in the SearchStax Site Search solution.

You may have already tried to create a facet or sort in Site Search, but didn’t get the results you were expecting. This is because fields of type text_general are tokenized. The data in them are broken up into tokens making any Faceting/Sorting behave unpredictably.

As an example, if you want to facet on the field city_t, you would expect the value “Los Angeles” to appear as a facet value. However, since city_t is a text_general type, “Los Angeles” actually becomes “Los” and “Angeles”. Your facet now has values for “Los” and “Angeles” which is not the expectation.

In this example, the solution is to change city_t to a “string type” field. String types are not tokenized. The data remains as in. So, the facet value would be “Los Angeles” as expected.

Now, let’s update your text_general field to a string type in Sitecore.

Change Field Type in Sitecore

  1. Begin by creating a new XML file named Patch.config in the app_config/include directory. Paste the provided XML configuration into this file. The configuration will modify the return types of specific field types in Sitecore. This is how the configuration looks:
<configuration>
    <sitecore>
        <contentsearch>
            <indexconfigurations>
                <defaultsolrindexconfiguration type="Sitecore.ContentSearch.SolrProvider.SolrIndexConfiguration, Sitecore.ContentSearch.SolrProvider">
                    <fieldmap type="Sitecore.ContentSearch.SolrProvider.SolrFieldMap, Sitecore.ContentSearch.SolrProvider">
                        <fieldtypes hint="raw:AddFieldByFieldTypeName">
                            <fieldtype fieldtypename="html|rich text|single-line text|multi-line text|text|memo|image|reference" returntype="text">
                                <patch:attribute name="fieldTypeName">html|rich text|multi-line text|text|memo|image</patch:attribute>
                            </fieldtype>
                            <fieldtype fieldtypename="single-line text|reference" returntype="string"></fieldtype>
                        </fieldtypes>
                    </fieldmap>
                </defaultsolrindexconfiguration>
            </indexconfigurations>
        </contentsearch>
    </sitecore>
</configuration>

Template Manager interface showing Builder tab with Template section and content field configuration options.

Update the Schema

  1. In the Sitecore desktop interface, select the Sitecore button at the bottom left (or the Sitecore logo at the top left if you’re using the newer interface).
  2. Select Control Panel.
  3. In the Control Panel, under the Indexing section, select Populate Solr Managed Schema.

Control Panel interface showing various system modules with Populate Solr Managed Schema option highlighted under the Indexing section.

Reindex the Data

  1. In the Sitecore Content Editor, go to the Control Panel.
  2. Under the Indexing section, select Index Manager.
  3. In the Index Manager screen, select the relevant indexes and click on Rebuild.

Indexing Manager dialog showing the sitecoreintegrationtest-667 index selected for rebuilding, with Rebuild button highlighted.

Create a Facet/Sort in Site Search

  1. Login to the Site Search dashboard at searchstudio.searchstax.com.
  2. Go to App Settings All APIs Search & Indexing. Scroll to the bottom of the page click the Reload Schema button.

alt Search & Indexing section with endpoints and Reload Schema button high..." src="/hc/article_attachments/43836614615949"

Go to the Search Fields and Faceting screens to set up the new facet. A field must first be searchable before it can be a facet.

Faceting configuration panel showing fields, labels, and value sorting options with example facet types displayed on the right.

Articles in this section