I want to paginate the search result for lucene.net. when I get data from the index, then I need to get only 10 records on each page. so I'm looking for a lucene.net swap trick, and I got an answer that I don't understand. here it is ... please see.
Hits hits = searcher.search(query);
int offset = page * recordsPerPage;
int count = Math.min(hits.length() - offset, recordsPerPage);
for (int i = 0; i < count; ++i) {
Document doc = hits.doc(offset + i);
}
TopDocs topDocs = indexSearcher.Search(query, null, 150);
for(int i=100, i<min(topDocs.totalHits,150); i++) {
Document doc = indexSearcher.doc(topDocs.scoreDocs[i]);
}
I just need to know if there is any better technique for him. please discuss. thank
Hence my starting start
another method I used to search the index. after receiving the code, I tried to settle in my code, but got an error. please review my code and convert it so that as a result I can use your swap logic.
here is my code
int PageIndex=0;
int PageSize=10;
searcher = new IndexSearcher(_directory, false);
Query qry = MultiFieldQueryParser.Parse(Version.LUCENE_29, multiWordPhrase, fieldList, occurs.ToArray(), new StandardAnalyzer(Version.LUCENE_29));
TopDocs topDocs = searcher.Search(qry, null, ((PageIndex + 1) * PageSize), Sort.RELEVANCE);
int resultsCount = topDocs.TotalHits;
lblMatchFound.Text = "Match Found " + resultsCount.ToString();
List<SearchResult> list = new List<SearchResult>();
SearchResult oSr = null;
if (topDocs != null)
{
ScoreDoc[] scoreDocs = topDocs.ScoreDocs;
foreach (ScoreDoc scoreDoc in scoreDocs)
{
Document doc = searcher.Doc(scoreDoc.doc);
oSr = new SearchResult();
oSr.ID = doc.Get("ID");
oSr.Title = doc.Get("Title");
oSr.Description = doc.Get("Description");
string preview =
oSr.Description = AllExtension.HighlightKeywords(oSr.Description, multiWordPhrase);
oSr.Url = doc.Get("Url");
list.Add(oSr);
}
}
, , .