Sorting is very easy to achieve with Lucinq – though there is one massive caveat. In order to sort on a field in Lucinq – ** it must be stored in the index **. This is due to the fact that unless stored, lucene will analyze the field, strip whitespace, potentially noise words etc etc.
Single sorting
To sort on a single field, simply use
queryBuilder.Sort(BBCFields.SecondarySort); // or in reverse order - setting the descending parameter to true. queryBuilder.Sort(BBCFields.SecondarySort, true);
Multiple sorting
Wow,that was tricky, what about if you have multiple fields?
queryBuilder..WildCard(BBCFields.Description, "a*"); queryBuilder.Sort(BBCFields.SecondarySort); queryBuilder.Sort(BBCFields.Sortable); // or using setup / constructors would look like this queryBuilder.Setup ( x => x.WildCard(BBCFields.Description, "a*"), x => x.Sort(BBCFields.SecondarySort), x => x.Sort(BBCFields.Sortable) );
Again – the sorts can all have the boolean descending flag set to reverse them. In the case of multiple sort criteria, the sorts are applied in order of declaration.
What Next?
Lets examine Collecting in Lucinq
Advertisements