How to sort by a field that has an alternative value if null in lucene?
Posted
by citizenmatt
on Stack Overflow
See other posts from Stack Overflow
or by citizenmatt
Published on 2010-03-19T00:05:52Z
Indexed on
2010/03/19
0:11 UTC
Read the original article
Hit count: 589
lucene
|lucene.net
Hi folks. I want to sort my lucene(.net) search results by a date field (date1), but if date1 is not set, I'd like to use date2.
The traditional sort method is to sort by date1, and then sort the values that are the same by date 2. This would mean that whenever I did fall back to date2, these values would be at the top (or bottom) of the result set. I'd like to interleave the date2 values with the date1 values.
In other words, I want to sort on (date1 != null ? date1 : date2).
Is this possible in lucene?
I reckon I could do this in the index creation phase (just put the relevant date value in a new field) but I don't have enough control of the indexing process to be able to do this, so would like a sorting solution.
Any ideas?
Thanks Matt
© Stack Overflow or respective owner