Ordering search refiners from managed metadata sources

Hi,

Hoping this is a simple issue on our end. We have several managed metadata term sets we are leveraging for search refiners. All works well except that the refiners from metadata fields are not being ordered correctly when we opt to sort based on Name. Non-managed metadata fields appear to work properly.

Selecting to sort by name does change the order of the refiner options, but in no discernible way. It is not using the ID. We have a custom sort on those term sets which is also alphabetical.

Any ideas? Thanks!

January 17th, 2013 4:38pm

How do you set your KeywordQuery.Refiners property? The refiner specification is different from sort specification and the latter doesn't control sorting of the "RefinementResults" result table but rather "RelevantResults" only.

========

Refiner Specification "Sort" Syntax

sort=<property>/<direction>

The attributes do the following:

  • <property>  Specifies the sorting algorithm. Valid values are as follows (values must be in lowercase letters):

    • frequency  Orders by occurrence within the bins.

    • name Orders by label name.

    • number  Treats the strings as numeric and uses numeric sorting. This value can be useful to specify discrete values, for example, to perform numeric sorting of a value that is contained in a string managed property.

  • <direction>  Specifies the sorting direction. Valid values are as follows:

    • descending

    • ascending

Example

sort=frequency/descending

========

i.e. The following refiner specification will sort refiner "MyTestAuthor" by name (ASCII sorting).

kq.Refiners = "MyTestAuthor(sort=name/descending)";

Free Windows Admin Tool Kit Click here and download it now
January 21st, 2013 5:17pm

Thanks Liang - Can you confirm this should work identically for managed metadata fields? The behavior you describe is working for other types of sort fields but not these.
January 21st, 2013 6:54pm

It should. Can you check if that managed metadata based Managed Property has Sortable enabled in Schema Setting? Don't forget to recrawl after such schema change.
Free Windows Admin Tool Kit Click here and download it now
January 21st, 2013 7:29pm

Just verified the property is sortable and performed a full crawl. No change.
January 22nd, 2013 7:58pm

Had a closer look --- the managed metadata (term) based Managed Property in search index always contain multiple values -- the first entry is a GUID and then the term label text and some other values follow. When doing refiner sorting, only the first entry (GUID) is inspected and sorted since it's a multi-value field, and this is the reason why the labels are not ordered in UI.

It is by design that in Crawled Property, term GUID needs to be used and placed in front of label text in sequence. Unfortunately changing such sequence would actually affect quite many refiner rendering logics across UI. I will report this issue to product group, but there's no guarantee that this behavior will be changed soon.


Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2013 11:01am

Had a closer look --- the managed metadata (term) based Managed Property in search index always contain multiple values -- the first entry is a GUID and then the term label text and some other values follow. When doing refiner sorting, only the first entry (GUID) is inspected and sorted since it's a multi-value field, and this is the reason why the labels are not ordered in UI.

It is by design that in Crawled Property, term GUID needs to be used and placed in front of label text in sequence. Unfortunately changing such sequence would actually affect quite many refiner rendering logics across UI. I will report this issue to product group, but there's no guarantee that this behavior will be changed soon.


January 23rd, 2013 11:01am

Had a closer look --- the managed metadata (term) based Managed Property in search index always contain multiple values -- the first entry is a GUID and then the term label text and some other values follow. When doing refiner sorting, only the first entry (GUID) is inspected and sorted since it's a multi-value field, and this is the reason why the labels are not ordered in UI.

It is by design that in Crawled Property, term GUID needs to be used and placed in front of label text in sequence. Unfortunately changing such sequence would actually affect quite many refiner rendering logics across UI. I will report this issue to product group, but there's no guarantee that this behavior will be changed soon.


Free Windows Admin Tool Kit Click here and download it now
January 23rd, 2013 11:01am

Hi Liang - has a resolution been identified for this yet? I'm having the same issue with sorting managed metadata refiners.

Thanks,

Josh

  • Proposed as answer by ChicagoBrian 16 hours 18 minutes ago
  • Unproposed as answer by ChicagoBrian 16 hours 18 minutes ago
May 24th, 2013 5:22pm

Hi Liang - has a resolution been identified for this yet? I'm having the same issue with sorting managed metadata refiners.

Thanks,

Josh

  • Proposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
  • Unproposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2013 5:22pm

Hi Liang - has a resolution been identified for this yet? I'm having the same issue with sorting managed metadata refiners.

Thanks,

Josh

  • Proposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
  • Unproposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
May 24th, 2013 5:22pm

Hi Liang - has a resolution been identified for this yet? I'm having the same issue with sorting managed metadata refiners.

Thanks,

Josh

  • Proposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
  • Unproposed as answer by ChicagoBrian Wednesday, March 11, 2015 2:57 PM
Free Windows Admin Tool Kit Click here and download it now
May 24th, 2013 5:22pm

Hi Guys,

There is something I used to do back is FAST2010 for these cases:

Each taxonomy/managed metadata used to have a crawled property (maybe even more than one). I created a new managed property (marked as refineable and with multi value) and mapped the crawled property to it. Then I refined on it, not using the OOTB taxonomy/managed metadata on my refinement panel.

I have no idea if that's an option in SP2013, but it's worth checking.

Amir


May 27th, 2013 8:01am

Hi Guys,

There is something I used to do back is FAST2010 for these cases:

Each taxonomy/managed metadata used to have a crawled property (maybe even more than one). I created a new managed property (marked as refineable and with multi value) and mapped the crawled property to it. Then I refined on it, not using the OOTB taxonomy/managed metadata on my refinement panel.

I have no idea if that's an option in SP2013, but it's worth checking.

Amir


Free Windows Admin Tool Kit Click here and download it now
May 27th, 2013 8:01am

Hi Guys,

There is something I used to do back is FAST2010 for these cases:

Each taxonomy/managed metadata used to have a crawled property (maybe even more than one). I created a new managed property (marked as refineable and with multi value) and mapped the crawled property to it. Then I refined on it, not using the OOTB taxonomy/managed metadata on my refinement panel.

I have no idea if that's an option in SP2013, but it's worth checking.

Amir


May 27th, 2013 8:01am

Amir - you rock! That worked PERFECTLY! Still good in 2013!

Thanks a bunch,

Josh

Free Windows Admin Tool Kit Click here and download it now
May 29th, 2013 3:09pm

Oh, and it also helped me get a managed metadata field to appear nicely in a Search Results Display Template. Fantastic!!!
May 30th, 2013 3:05am

If the refiners being used on your search page are a custom metadata term (They have a name like "owstaxId...") you will need to add additional sort options to the "Display template" being used by the Refinement webpart.

The Display Template is choosen within the Refinement configuration popup window when you edit the Refinement web part.  The display template being used here need to be edited. This Display Template is a html file located on the SharePoint server in the _catalogs\masterpage\Display Template\Filters folder.  Do NOT edit the .js file.  It will update automatically when you save your html file. Edit the filter file that is being used by your search page in notepad or an editor of your choice. (notepad++ is ideal for this).

The default code in the filter file only contains sort functions for "FileType." You will have to add code for filtering on your custom "owstaxId..." properties in three sections as shown below.


At about line 314, the filter html file contains the "ctx.RefinementControl.propertyName" code. After this section you need to add additional "if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname")" lines of code as shown below marked by -->. Be sure not to include the --> in the actual code.

            if (ctx.RefinementControl.propertyName == "FileType")
            {
                if (unselectedFilters.length <= shortListSize) {
                    unselectedFilters = unselectedFilters.sort(SortAlphabetically);
                } else {

                    unselectedFilters = unselectedFilters.sort(SortByCountDescending);
                }

                selectedFilters = selectedFilters.sort(SortAlphabetically);
            }

-->            if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname1")
-->            {
-->                unselectedFilters = unselectedFilters.sort(SortAlphabetically);
-->                selectedFilters = selectedFilters.sort(SortAlphabetically);
-->            }   
   
-->            if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname2")
-->            {
-->                unselectedFilters = unselectedFilters.sort(SortAlphabetically);
-->                selectedFilters = selectedFilters.sort(SortAlphabetically);
-->            }      
            if (selectedFilters.length > 0 || hasAnyFiltertokens)
            {

About 50 lines further down you need to add a second section of custom code as shown below for "owstaxIdyourpropertyname".
            if (shortListSize < unselectedFilters.length) {
                numShortList = shortListSize;
                if (ctx.RefinementControl.propertyName == "FileType") {
                    shortList = unselectedFilters.slice(0, numShortList).sort(SortAlphabetically);
                }
-->    if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname1") {
-->                    shortList = unselectedFilters.slice(0, numShortList).sort(SortAlphabetically);
-->                }
-->    if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname2") {
-->                    shortList = unselectedFilters.slice(0, numShortList).sort(SortAlphabetically);
-->                }        
            }

About 30 lines further down you need to add third section of custom code as shown below for "owstaxIdyourpropertyname".
  <!--#_
                if (ctx.RefinementControl.propertyName == "FileType") {
                    unselectedFilters = unselectedFilters.sort(SortAlphabetically);
                }
-->                if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname1") {
-->                    unselectedFilters = unselectedFilters.sort(SortAlphabetically);
-->                }
-->    if (ctx.RefinementControl.propertyName == "owstaxIdyourpropertyname2") {
-->                    unselectedFilters = unselectedFilters.sort(SortAlphabetically);
-->                }
    for (var i = 0;


Save the html file. Wait for the .js to update automatically.
NOTE: If you also made any changes to your display templates, like other assets in the Master Page Gallery, they must be Published in order for all users to use them. Once you have completed your edits, return to the Mater Page Gallery and Publish a Major Version of the files so that your users will be able to see them. 

Free Windows Admin Tool Kit Click here and download it now
March 11th, 2015 11:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics