Ph0en1x
Ph0en1x

Reputation: 10077

How does Lucene order data in composite queries?

I need to know how Lucene orders the records in a result set if I use composite queries.

It looks like it sorts it using "score" value for exact queries and it sorts it lexicographically for range queries. But what if have the query which looks like

q = type:TAG OR type:POST AND date:[111 to 999]

Upvotes: 0

Views: 426

Answers (1)

ffriend
ffriend

Reputation: 28552

You mix together logical search and scoring. When you pass query like date:[111 to 999], Lucene searches for all documents with the date in specified range. But you give it no advice on how to sort them - is date 111 more preferable for you than 555? or is 701 better than 398? Lucene have no idea about it, so the score is the same for all found documents. Just to make some order, Lucene sorts results lexicographically, but that's mostly detail of implementation, not some key idea.

On other hand, if you pass some other parameters with a query - be it keywords or tags - Lucene can apply its similarity algorithm and assign different scores to different docs in results. You may find more on Lucene's scoring here.

So, to give you short answer: Lucene sorts results by score, and only if the score for 2 documents is the same, it uses other types sorting options like lexicographical order.

Upvotes: 1

Related Questions