title: Paging Lucene.Net search results asp.net
body: <p>i want to do pagination for lucene.net search result. when i fetch data from index then i need to fetch only 10 records in each page. so i search for lucene.net paging trick and i got a answer which is not clear to me. here it is...please have look.</p>
  
  <pre><code>Hits hits = searcher.search(query);
  int offset = page * recordsPerPage;
  int count = Math.min(hits.length() - offset, recordsPerPage);
  for (int i = 0; i &lt; count; ++i) {
      Document doc = hits.doc(offset + i);
  
  }
  
  TopDocs topDocs = indexSearcher.Search(query, null, 150);
  for(int i=100, i&lt;min(topDocs.totalHits,150); i++) {
  Document doc = indexSearcher.doc(topDocs.scoreDocs[i]);
  
  // Do something with the doc
  }
  </code></pre>
  
  <p>i just need to know is there any better technique for it. please discuss. thanks</p>
  
  <h2>From here my Update start</h2>
  
  <p>different way i was using to search index. after getting your code i tried to incoporate in my code but getting error. please have look at my code and convert it in such way as a result i can use your paging logic.</p>
  
  <h2>here is my code</h2>
  
  <pre><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&lt;SearchResult&gt; list = new List&lt;SearchResult&gt;();
              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);
                  }
              }
  </code></pre>
  
  <p>please have a look and restructure my code in such way i can do the paging. thanks </p>