Adding a Sort field based on a computed field on "Coveo for Sitecore" (Coveo 7)

Posted 08/15/2014 by Debabrata Biswas

When using the page editor (or even the content editor) to add a new coveo Sort field for a search page, it allows you to only select a "template" and a numeric "field" in that template to sort on. But what if you wish to sort on a "computed field" you just added. Following steps describes just that.


As seen from my screenshots I am using Jetstream as an example.

1- In the Coveo.SearchProvider.Config file, add into <fields hint="raw:AddComputedIndexField">:


            <field fieldName="departureairportcity">Coveo.Demos.JetStream.ComputedFields.DepartureAirportCityComputedField, Coveo.Demos.JetStream</field>
            <field fieldName="arrivalairportcity">Coveo.Demos.JetStream.ComputedFields.ArrivalAirportCityComputedField, Coveo.Demos.JetStream</field>

2- In the Coveo.SearchProvider.Config file, add into <fieldMap>/<fieldNames>:
              <fieldType fieldName='departureairportcity' isSortable="true" isFacet="true" includeForFreeTextSearch="false" isMultiValue="false" settingType='Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework' />
              <fieldType fieldName='arrivalairportcity' isSortable="true" isFacet="true" includeForFreeTextSearch="false" isMultiValue="false" settingType='Coveo.Framework.Configuration.FieldConfiguration, Coveo.Framework' />


3- Rebuild indexes from Sitecore index manager.


4- Define your own sort parameters template, similar to existing "Field Sort Parameters" template. Note that "SortField" is now a single-line text type rather than "Sort Field Picker". Review below:

5- You can now create your own sublayout that uses this custom Field Sort parameters template. The "Ascx file" field should point to your own "CustomCoveoFieldSort.ascx" that could be a copy of default "CoveoFieldSort.ascx". Review below:



6- Modify the "coveo sorts" placeholder to allow addition of this new sublayout. Review below:



7- Now when you add a sort component you can select this new custom sort field control. Review below:



8- In the "Sort Field" you can just enter the computed field that you wish to sort on. Please review below:



9- That should be it. You can now view and sort by that field.


Share:

Archive

Syndication