问题
I am creating a web app with Lucene that I need to implement paging. I have seen here the different examples about using an offset on the collector. However, those seem to be old. Lucene 3.5 (or 3.6 can't remember which) added this I believe. I have seen the IndexSearcher method searchAfter. However, it requires you pass it the last ScoreDoc. Because this is a web app, I have no way to pass the last result (as a ScoreDoc object) to the next request. So, my question is how is this typically done?
The only way that I have really come up with is to add in a unique key into the index when building. Then, pass that key as a post parameter when trying to get the next page. Then, I would have to search for that key to get the document id and pull that document to use with searchAfter. I think I have to use my own unique key because I cannot rely on the document id to stay the same. Am I correct on this?
If there are better ways, please let me know. This is my first attempt at Lucene.
回答1:
However, it requires you pass it the last ScoreDoc. Because this is a web app, I have no way to pass the last result (as a ScoreDoc object) to the next request. So, my question is how is this typically done?
I don't understand your problem, if you want to use searchAfter, just make a ScoreDoc to pass to it. your webapp can pass ints and floats right?
/** Constructs a ScoreDoc. */
public ScoreDoc(int doc, float score) {
回答2:
As far as I'm aware, what you are doing at the moment is correct. A ScoreDoc which you construct yourself using ints and floats will not work. See my similar question:
Working Lucene SearchAfter Example
来源:https://stackoverflow.com/questions/12485040/lucene-web-paging