Copied to clipboard

Flag this post as spam?

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


  • Stuart Mullinger 62 posts 288 karma points
    Jun 05, 2021 @ 16:56
    Stuart Mullinger
    0

    Examine Skip/Take

    Just upgraded to beta 3 and pleased to see the upgrade of Examine, so that we can now use skip and take to implement pagination on the search results. Unfortunately, it doesn't seem to be working. If I skip any number of records, then 0 are returned - even if there are valid records to return.

    You can see the same problem in the Examine Management section in the back office.

    1. New install of beta 3.
    2. Create a document type (allowed as root).
    3. Create 21 pages under Content using that document type each with the same word in them (I used "page", e.g. "Page one", "Page two"...).
    4. Search for "page" in the ExternalIndex under Examine Management in Settings.
    5. First 20 pages are displayed, with 2 pages indicated.
    6. Click on page 2.
    7. No results are shown - I'd expect 1 more result to show on page 2.
  • Stuart Mullinger 62 posts 288 karma points
    Jun 05, 2021 @ 16:57
    Stuart Mullinger
    0

    As an aside, is there still a MaxResults setting? How do we go about setting it?

  • Benjamin Carleski 29 posts 246 karma points MVP c-trib
    Jun 05, 2021 @ 17:00
    Benjamin Carleski
    100

    To answer the second question first, there is a Take value you can pass, which is the replacement of the MaxResults setting.

    Regarding the bug you found, I don't see anything already opened for that at https://github.com/Shazwazza/Examine/issues so I'd definitely recommend opening that there. I'm sure Shannon would love to know that people are already playing with the new release!

  • Stuart Mullinger 62 posts 288 karma points
    Jun 05, 2021 @ 17:07
    Stuart Mullinger
    0

    Thanks for the quick reply Benjamin! I'll raise that over there.

    I'm not convinced the Take value is a replacement for MaxResults. Skip/Take shouldn't affect the TotalItemCount, whereas the MaxResults value did. I'll have a bit more of a play and come back when I'm more certain/convinced otherwise :)

  • Stuart Mullinger 62 posts 288 karma points
    Jun 07, 2021 @ 10:26
    Stuart Mullinger
    0

    Got it now thanks Benjamin. MaxResults didn't affect the TotalItemCount in V8 either. Thanks for your help.

  • David Armitage 478 posts 2003 karma points
    Jun 14, 2021 @ 09:04
    David Armitage
    0

    Hi Stuart,

    What was your solution for this the MaxResults.

    V8 Example.

    int pageIndex = blogSearch.CurrentPage - 1;
    int pageSize = blogSearch.ItemsPerPage;
    ISearchResults searchResult = examineQuery.Execute(maxResults: pageSize * (pageIndex + 1));
    IEnumerable<ISearchResult> pagedResults = searchResult.Skip(pageIndex * pageSize);
    

    Since the MaxResults has been replaced did you change it to.

    V9 Example.

    int pageIndex = blogSearch.CurrentPage - 1;
    int pageSize = blogSearch.ItemsPerPage;
    ISearchResults searchResult = examineQuery.Execute();
    IEnumerable<ISearchResult> pagedResults = searchResult.Skip(pageIndex * pageSize).Take(pageSize * (pageIndex + 1));
    

    I have a feeling the take is not the way to go. Looking at the code it seems to be linq that is handling the skip and take and I think this might be bad for performance.

    What solution did you come up with?

    Regards

    David

  • Stuart Mullinger 62 posts 288 karma points
    Jun 14, 2021 @ 09:39
    Stuart Mullinger
    0

    Yes, like that, but you only Take the pageSize - it's the number of records you want returned. I suspect it's more efficient to let Examine do the skip/take, that's certainly the way I'm going.

    I suspect you'll find that this doesn't work in beta 3 (see the first comment above) if skip > 0. Will be interested to hear if you see the same thing.

  • David Armitage 478 posts 2003 karma points
    Jun 14, 2021 @ 10:21
    David Armitage
    0

    Hi Stuart,

    Ok you are right. I looks like there is a bug for this. I will update your ticket you logged regarding this to say I have also tested it.

    For future reference here is the correct code which unfortunately isn't working yet.

    int pageIndex = blogSearch.CurrentPage - 1;
    int pageSize = blogSearch.ItemsPerPage;
    
    QueryOptions queryOptions = new QueryOptions(pageIndex * pageSize, blogSearch.ItemsPerPage);
    ISearchResults searchResult = examineQuery.Execute(queryOptions);
    IEnumerable<ISearchResult> pagedResults = searchResult;
    int totalResults = Convert.ToInt32(searchResult.TotalItemCount);
    blogSearch.TotalItems = totalResults;
    blogSearch.TotalPages = (totalResults + blogSearch.ItemsPerPage - 1) / blogSearch.ItemsPerPage;
    blogSearch.BlogDetailsPages = GetBlogArticlesFromSearch(pagedResults);
    

    I can conform if you are on page 1 it works fine but when you change to anything above this when no data is returned. All the other values like total results etc seem correct.

  • David Armitage 478 posts 2003 karma points
    Jun 14, 2021 @ 12:09
    David Armitage
    0

    Hi,

    I have also followed up by writing two blog articles which might help people trying to get up and running with Examine on Umbraco 9.

    Umbraco 9 Examine - Basic Search https://www.umbrajobs.com/blog/posts/2021/june/umbraco-9-examine-basic-search/

    Umbraco 9 Examine - Creating a Custom Index https://www.umbrajobs.com/blog/posts/2021/june/umbraco-9-examine-creating-a-custom-index/

    Regards

    David

Please Sign in or register to post replies

Write your reply to:

Draft