Working Lucene SearchAfter Example

2019-04-01 01:43发布

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:

Stack Overflow Question: Lucene web paging

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);

I get this exception:

java.lang.IllegalArgumentException: after must be a FieldDoc

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 is an Object array, so I can hardly set that with information I can pass in a URI!

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?

Thanks!

标签: java lucene
1条回答
老娘就宠你
2楼-- · 2019-04-01 01:56

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.

查看更多
登录 后发表回答