0
votes

I looking for solution how to cache searching results in Lucene. When i used Solr pagination was much easier

My solr code:

query.setStart(start);
query.setRows(rows);
QueryResponse response = solr.query(query);

Simple wildcard searching it was like 400ms for 1st 100 results and each next page it was like 20-70ms

But when I'm using Lucene each time I have to search again and each page takes 400ms

My Lucene code:

Query query = queryParser.parse(text);

TopScoreDocCollector collector=TopScoreDocCollector.create(1000000);
IndexSearcher = indexSearcher.search(query, collector);

TopDocs results =collector.topDocs(start,rows);
for (ScoreDoc scoreDoc : results.scoreDocs) {
Document document = indexSearcher.doc(scoreDoc.doc);

I tried make TopScoreDocCollector and IndexSearcher static but this don't work

Do you have any other solution?

1

1 Answers

0
votes

I made results static

static TopDocs results;

results = indexSearcher.search(query, 100000);

public ArrayList meakeResult() throws IOException{ ArrayList res = new ArrayList();

ScoreDoc[] hits=results.scoreDocs;

   for (int i=start; i < start+rows; i++) {
       Document document = indexSearcher.doc(hits[i].doc);
       Answer tab = new Answer();
       tab.setAnswer(document.get("answer"));
       tab.setQuestion("question" + document.get("question"));
       tab.setProces("proces" + document.get("proces"));
       tab.setForm("form: " + document.get("form")); 
       res.add(tab);
   }