tags:

views:

1290

answers:

3

I got my lucene index with a field that needs to be sorted on. I have my query and I can make my Sort object. If I understand right from the javadoc I should be able to doe query.SetSort(). But there seems to be no such method...

Sure I'm missing something vital. Any suggestions?

+2  A: 

It looks like the actual method you want is e.g. Searcher.search(Query query, Filter filter, int n, Sort sort). setSort is a method of Sort.

Matthew Flaschen
+2  A: 

There are actually two important points. First, the field must be indexed. Second, pass the Sort object into the overloaded search method.

Last time I looked, the docs didn't do a very good job of pointing out the indexing part, and certainly didn't explain why this is so. It took some digging to find out why.

When a field is sortable, the searcher creates an array with one element for each document in the index. It uses information from the term index to populate this array so that it can perform sorting very quickly. If you have a lot of documents, it can use a lot of memory, so don't make a field sortable unless there is a need.

One more caveat: a sortable field must have no more than one value stored in each field. If there are multiple values, Lucene doesn't know which to use as the sort key.

erickson
the lucene documentation could indeed use some central documentation repository. I really like what the library brings to the table, but there are some weird things I miss (like a "contains", decent startswith and endswith search).Thanks for the explanation. Not at work now, but will check tomorow morning.
borisCallens
+1  A: 

I found search lucene .net index with sort option link interesting to solve ur problem

thanks, I will have a look at it
borisCallens