开发者

store documents based on sort order in lucene index

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开发者_Python百科) 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


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


Lucene will index and query efficiently on numeric fields, see NumericRangeQuery. The javadoc I linked to above have notes about the TrieRangeQuery implementation.

You can store modifiedDate as a NumericField which contains the modified date as a long in ms. Then use a QueryWrapperFilter around a NumericRangeFilter to limit your search to the appropriate date range.

This should be very efficient.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜