Configure managed property in sort drop-down list of SharePoint Search Results

For this we have to define JSON sort in the available sort orders property in the Search results Web Part.

To add the JSON go into the search results web part properties, expand the “Settings” toggle and enable the “Show sort drop-down” option. By default you can see following sort orders.

[
 {"name":"Relevance","sorts":[]},
 {"name":"Date(Newest)","sorts":[{"p":"Write","d":1}]},
 {"name":"Date(Oldest)","sorts":[{"p":"Write","d":0}]},
 {"name":"Lifetime Views","sorts":[{"p":"ViewsLifeTime","d":1}]},
 {"name":"Recent Views","sorts":[{"p":"ViewsRecent","d":1}]}
]

First let's understand the JSON format.

The “name” property is the display name that you will see in the search drop down. Even though we’re not displaying the search drop down in our Web Part you can still give it a meaningful name.

The “sorts” property contains our sort order for the search results. The “p” is the managed property name and the “d” defines whether descending order is true or false (1 is descending and 0 is ascending).

Knowing what I mentioned above, you can create any sort order you feel like for the search results Web Part. You just have to have the JSON sort order defined in your search results Web Part. For example, if you just want to sort by the name in ascending order then the JSON would look like this:

{"name":"Product Name","sorts":[{"p":"<managed property>","d":0}]}

Comments

Popular posts from this blog

Switch from Classic to Claims Authentication in SharePoint 2010

How to query list data using web service