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


// 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*");

// or using setup / constructors would look like this
        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

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s