Question

I have a webpage form which carries out a search of all the photos that users have uploaded to the website. The problem is that the Lucene search is currently retrieving all photos that meet the search criteria even though we are only displaying 21 photos on the page. This is causing serious performance issues. Is it possible to limit the number of photos retrieved to 21, in order to improve performance?

In the same way that we can restrict searches to a specific category by using eg (Category: New), is there a similar way to restrict the number of hits?

Was it helpful?

Solution

This is what I do: The search method has number of results as a parameter. I pass pageSize*page. So for page 1, I get only pageSize documents.

Then I only load the document (using searcher.doc()) for the page that I need.

TopDocs hits = searcher.search(lucene_query, pageSize*(page));

ScoreDoc[] scoreDocs = hits.scoreDocs;

int j = startIndex;
int rem = 0;

while (j < scoreDocs.length && (endIndex==0 || j<endIndex)) {

    ScoreDoc sd = scoreDocs[j];
    Document d = searcher.doc(sd.doc);

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top