问题描述
我正在尝试使用Lucene 4.8.1的SearchAfter方法在Web应用程序中实现搜索结果的分页。
I'm trying to use Lucene 4.8.1's SearchAfter methods to implement paging of search results in a web application.
之前已经提出了类似的问题,但是那里接受的答案对我不起作用:
A similar question has been asked before, but the accepted answer given there does not work for me:
当我从头创建一个Lucene ScoreDoc以这种方式用作SearchAfter的参数时:
When I create a Lucene ScoreDoc from scratch in this way to use as an argument for SearchAfter:
ScoreDoc sd = new ScoreDoc(14526, 0.0f);
TopDocs td = indexSearcher.searchAfter(sd, query, null, PAGEHITS);
我得到这个例外:
java.lang.IllegalArgumentException: after must be a FieldDoc
这个出现与文件相反。但无论如何,当我创建一个Field Doc时,我得到:
This appears contrary to the documentation. But in any case, when I create a Field Doc instead, I get:
java.lang.IllegalArgumentException: after.fields wasn't set
after.fields是一个Object数组,所以我很难用信息设置传入一个URI!
after.fields is an Object array, so I can hardly set that with information I can pass in a URI!
我找不到任何使用SearchAfter的工作代码示例。我的原始计划显然是创建一个新的ScoreDoc,如前一个问题所示。任何人都可以建议我可能做错了什么,或链接到SearchAfter的任何工作代码示例?
I cannot find any working code examples using SearchAfter. My original plan was obviously to create a new ScoreDoc as the previous question suggests. Can anybody suggest what I might be doing wrong, or link to any working code examples of SearchAfter?
谢谢!
推荐答案
我不相信你可以创建一个scoredoc然后将它传递给searchAfter。您需要使用先前搜索返回的ScoreDocs。
I don't believe you can create a scoredoc and then pass it to searchAfter. You need to use the ScoreDocs returned from a previous search.
这篇关于工作Lucene SearchAfter示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!