Lucene.NET result using sql like LIMIT? + 1k question
I agree with this answer and like it but i really would rather have this solved before going live. So i am starting a bounty in hopes my ass isnt bitten later ;).
With Lucene.NET 2.9.x any version using .NET. How might i search and limit/page the results similar to the limit keyword in SQLite and MySql? I'd like to find the top 20 docs that have the word 'Apple' and have a link to page 20 returning 20 results ignoring the first 400 docs with a higher score. Should i implement it this way (credit goes to Pascal Dimassimo answer below)
1k Question
Hey Guys, i currently have 999 questions so this will be my 1000th question! I just wanted to say thank you to all of you who ans开发者_如何学运维wered my questions, left me comments and overall help me learn programming and technologies years sooner then it would have taken me alone.
I also want to mention Edward Tanguay who was leading the most question asked for a long time and more importantly ask great questions with many upvotes. I strike to get my quality as high as his. I also want to mention these guys who are asking many questions as well. ooo, metal-gear-solid, Masi, Blankman
The search method of the Searcher class has a parameter to limit the number of results returned for a query.
Query query = parser.parse("Apple");
TopDocs topDocs = searcher.search(query, 20);
But Lucene does not support pagination. You will have to redo your query and keep the results that fits the range that you need.
See this question.
Searcher.search, you use in second line, has also signature:
Search(Query query, Filter filter, HitCollector results)
Use HitCollector to flush temporary result into fast and temporary storage. For example if user asks first 20 - you need to return it and in background thread start caching all another. Really you need to store only document's ID, so for 1 millions result approximately 4Mb is expected.
When result is in the storage it is simple to support paging.
精彩评论