I've got 5 records in Lucene index.
-
a.Record 1 contains–tax
analysis.Date field value is March
2009b.Record 2 contains–Senior tax
analyst.Date field value is Aug 2009c.Record 3 contains–Senior tax
analyst.Date field value is July 2009d.Record 4 contains–tax analyst.Date
field value is Feb 2009e.Record 5 contains–Senior tax
analyst.Date field value is Oct 2009
If the input keyword is senior tax analyst,then search results should come up in the following order:
-
a.Record 5–because this record is
has got the most recent date and has
got the matching phraseb.Record 2–because this record has
got second most recent date and has
got the matching phrasec.Record 3–because this record has
got third most recent date and has
got the matching phrased.Record 4
e.Record 1
Basically,I want to show the most relevant records grouped by date and sorted in descending order by date.And then, I want to show remaining records sorted by descending value of relevancy.
How do i achieve this with Lucene?
Please help.
Thanks for reading.
Best Answer
I believe you can do this by first collecting the search results and then sorting them using a CustomSorter. This blog entry explains custom sorting in Lucene Java. You have to translate this to .Net, using .Net's ScoreDocComparator. Your compare() method will have to get the date fields from the documents and compare them. I would first try to get the proper order for the exact matches (Record 5, 2, and 3). Later, you can use the match as well in your comparator. You can generalize my answer to this question in order to do this.