Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8230925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:18:01+00:00 2026-06-07T17:18:01+00:00

i want to do pagination for lucene.net search result. when i fetch data from

  • 0

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.

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 is there any better technique for it. please discuss. thanks

From here my Update start

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.

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

please have a look and restructure my code in such way i can do the paging. thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:18:03+00:00Added an answer on June 7, 2026 at 5:18 pm

    First of all do not use Hits class since it is deprecated and slow.

    For your paging case:

    make a search for the first page like TopDocs td = s.Search(query, 10);

    and for the second page TopDocs td = s.Search(query, 20); and display the results from 10 to 19

    and so on…

    PS: The costly part in Lucene is reading the results from the index, not the search itself. So above trick should perform very well.

    — EDIT (Untested) —

    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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a pagination helper. The only parameters that it needs are
In my ASP.NET MVC 3 application I want to use Jquery's pagination plugin to
Is there any prefect suggestion for data pagination? I do not want use pure
I want to achieve pagination (5 records per page) for this simple JavaScript array
I'm using the kaminari gem for pagination. I want to only show the 10
I want custom pagination in my gridview control. The first option is to fetch
How can i implement pagination in Asp.net MVC through nopCommere ? I want to
I am using lucene.Net for searching in my application. I have to search in
I want to implement this JSF page with pagination and sorting. Unfortunately Netbeans shows
I want to use ckeditor plugin, and pagination in my application; but there is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.