How to sort by a field that has an alternative value if null in lucene?
- by citizenmatt
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