Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Giant Penguin 5 posts 74 karma points
    6 days ago
    Giant Penguin

    How can paginate with Umbraco 8 Examine

    I could not find out any overload of ISearcher.Search or IQueryExecutor.Execute that support returning paging.

    Any idea about the search result's pagination with Umbraco 8?

    Note that this is a custom search - I want to search on some specific document types.

  • Søren Kottal 430 posts 2622 karma points MVP c-trib
    6 days ago
    Søren Kottal

    Hi there :)

    Check out this article:

    Basically you need to set maxResults to the number of results per page (multiplied by the current pagenumber), and then skip through the ones you have already shown.

    //for example purposes, we want to show page #4 (which is pageIndex of 3)
    var pageIndex = 3;   
    //for this example, the page size is 10 items
    var pageSize = 10;
    var searchResult = searchProvider.Search(criteria, 
       //don't return more results than we need for the paging
       //this is the 'trick' - we need to load enough search results to fill
       //all pages from 1 to the current page of 4
       maxResults: pageSize*(pageIndex + 1));
    //then we use the Skip method to tell Lucene to not allocate search results
    //for the first 3 pages
    var pagedResults = searchResult.Skip(pageIndex*pageSize);
    var totalResults = searchResult.TotalItemCount;
Please Sign in or register to post replies

Write your reply to: