Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store documents based on sort order in lucene index

Tags:

java

.net

lucene

I have two field (name, modifiedDate) in my index. i want to store new document based on modifiedDate and keep index sorted on modifiedDate
doc #1 is the oldest document and (modifiedDate) is oldest too
doc #n is most recent document and (modifiedDate) is near to now

1) how can i create this index structure that documents physically stored base on (modifiedDate) and keep the structure even after any change happened in the index (optimize, delete, update)

2) the following structure let me search for documents in specific date range. but i don't want to search the entire index and then filter. i want to use the following structure to skip all other documents if it goes beyond the date range

Current lucene behavior

for (1 to docCount)
if (modifiedDate is in date range filter)
calculate the score based on query

Accepted behavior

for (1 to docCount)
if (modifiedDate is greater than upper bound of date range)
break
else
calculate the score based on query

if i have 3,000,000 document and my date range only meets 20 top document, in current lucene behavior i need to check all of the documents, but in accepted behavior I am only scoring top 20 document, and you can guess the huge performance gain

like image 454
Ehsan Avatar asked Dec 14 '25 01:12

Ehsan


1 Answers

The existing answers are fine but Lucene 4.3.0 came out this year with a new "SortingMergePolicy" that allows advanced Lucene users to use the algorithm suggested in the original poster to cancel a search early. See the javadocs

like image 122
David Smiley Avatar answered Dec 15 '25 14:12

David Smiley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!