Sorting results

By default Relatude sorts results based on relevance, but sometimes you want to sort the results differently.

Relatude sorts results based on relevance, so you need to specify if you want it to do things differently. The IndexQuery class has a CustomSort property, which takes a Lucene.Net.Search.Sort object.

https://lucenenet.apache.org/docs/3.0.3/d1/da9/class_lucene_1_1_net_1_1_search_1_1_sort.html

One of the overloads for the Sort class is that you can specify a SortField. SortField has a number of settings that can be useful in a number of situations:

https://lucenenet.apache.org/docs/3.0.3/d7/da5/class_lucene_1_1_net_1_1_search_1_1_sort_field.html

Note that Lucene can't sort on tokenized fields, so you can sort on the Name field in the Lucene index. But we have a NameSorted field as well, that isn't tokenized. 

If you want to sort results alphabetically, this should be sufficient:

indexQuery.CustomSort = new Lucene.Net.Search.Sort(new SortField("NameSorted",System.Threading.Thread.CurrentThread.CurrentCulture));

Note that we're using CurrentCulture. This will only work if you have set the currentculture correctly in your application. This can be done in a number of ways, but doing it in web.config is the easiest for installations with a single language.

Add the following inside <system.web>:

<globalization uiCulture="no" culture="nb-NO" />

 Replace the string values with your correct culture.