Lucene.Net asp.net user list search results

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

// Do something with the doc
}

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");
                    //oSr.WordCount = AllExtension.WordCount(oSr.Description, WordExist(oSr.Title, multiWordPhrase));
                    string preview =
                    oSr.Description = AllExtension.HighlightKeywords(oSr.Description, multiWordPhrase);  //sr.Description;
                    oSr.Url = doc.Get("Url");
                    list.Add(oSr);
                }
            }

, , .

+5
1

, Hits, .

:

, TopDocs td = s.Search(query, 10);

TopDocs td = s.Search(query, 20); 10 19

..

PS: Lucene , . , .

- ( ) -

int page = 2; //starting from 0

TopDocs td = searcher.Search(query, (page+1)*10);
for (int i = page * 10; i < (page + 1) * 10 && i < td.scoreDocs.Length; i++)
{
    Document doc = indexReader.Document(td.scoreDocs[i].doc);
}
+10

All Articles