lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sreedevi s <sreedevi.payik...@gmail.com>
Subject searchAfter in web application
Date Mon, 09 Feb 2015 06:47:54 GMT
Hi,
    I am trying out pagination in lucene. I did it in two ways. The first
one by mentioning the offset position in topdocs(). This is a piece of code
I am trying out to achieve the same scenario using searchAfter().This works
fine but since I have a web appication, how will I do deep paging to be
efficiently since need to use scoredocs returned from previous search.

static ScoreDoc after=null;
public static ArrayList<String> deepSearch(String searchKey, int reqHits) {
ArrayList<String> results = new ArrayList<String>();
try {
Query q = new QueryParser("products", IndexData.analyzer)
.parse(searchKey);
IndexSearcher is = new IndexSearcher(IndexData.ir);
TopScoreDocCollector collector = TopScoreDocCollector.create(
reqHits, true);
TopDocs topdocs = null;
System.out.println("score of last doc=" + after);
topdocs = is.searchAfter(after, q, 10);
ScoreDoc[] docs = topdocs.scoreDocs;
after = docs[(docs.length) - 1];
for (int i = 0; i < docs.length; i++) {
//System.out.println("score details=" + docs[i]);
results.add(is.doc(docs[i].doc).get("id"));
}
} catch (Exception e) {
e.printStackTrace();
}
return results;
}
I believe using this api is suggested over topdocs(offset) method.
Any working code or suggestion would be appreciated.

Best Regards,
Sreedevi S

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message