Copied to clipboard

Flag this post as spam?

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


  • Mus'ab 158 posts 387 karma points notactivated
    Nov 06, 2019 @ 18:48
    Mus'ab
    0

    How to pagination with examine umbraco 8 ?

    Hi

    is there any way to identify the number of results that i want returned by examine like skip but before executing the whole query ?

  • S Rupa 8 posts 111 karma points
    Nov 06, 2019 @ 23:52
    S Rupa
    0

    This may help ? Assume you have a publishedDate field for sorting. Update it as required.

    ISearchResults has total count. (TotalItemCount)

    public static ISearchResults GetNodes(string nodeAlias, int parentId = 0)
        {
            if (string.IsNullOrEmpty(nodeAlias))
            {
                return null;
            }
    
            if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
            {
                var searcher = index.GetSearcher();
    
                if (parentId == 0)
                {
                    return searcher.CreateQuery().NodeTypeAlias(nodeAlias)
                        .OrderByDescending(new SortableField("publishedDate", SortType.Long)).Execute();
                }
    
                return searcher.CreateQuery().ParentId(parentId).And().NodeTypeAlias(nodeAlias)
                    .OrderByDescending(new SortableField("publishedDate", SortType.Long)).Execute();
            }
    
            return null;
        }
    
  • Mus'ab 158 posts 387 karma points notactivated
    Nov 07, 2019 @ 08:18
    Mus'ab
    0

    Hi S Rupa

    as i see your code is for sorting by date my case is that i have a huge number of nodes and i don't want examine to return them all at once i want to be able to chose that i want to return 4 results for example and identify witch 4 like first 4 result or second 4 result and so on.

    here is my code

         if (ExamineManager.Instance.TryGetIndex("InternalIndex", out var index))
                {
                    var mainSettings = Umbraco.Content(2564);
                    var searcher = index.GetSearcher();
                    ISearchResults ExamineResults = null;
                    var query = searcher.CreateQuery("content");
                    IBooleanOperation queryOperations = query.Field("__NodeTypeAlias", "newsItem");
                    if (CategoryPath != "")
                    {
                        //CategoryPath = Umbraco.Content(2626).Path;
                        queryOperations = queryOperations.And().Field("path", CategoryPath.MultipleCharacterWildcard());
                    }
                    if (Keyword != "")
                    {
                        queryOperations = queryOperations.And().Field("newsTitle", Keyword);
                    }
                    if (Year != "")
                    {
                        int mon = Month.IsNullOrWhiteSpace() ? 1 : Convert.ToInt32(Month);
                        queryOperations= queryOperations.And().RangeQuery<DateTime>("publish_time".Split(','),new DateTime(Convert.ToInt32(Year), mon, 1),new DateTime(Convert.ToInt32(Year), mon, 31));
                    }
                    ExamineResults=queryOperations.OrderByDescending(new SortableField[] { new SortableField("publish_time") }).Execute();
    }
    

    this search should return more than 500 node so i will waste the time if i make query get all of the node to display just 4 nodes every time any advice ?

  • Jesper Weber 54 posts 170 karma points c-trib
    Jun 16, 2020 @ 14:37
    Jesper Weber
    0

    Hi,

    The execute method takes a maxResults parameter which specifies the number of results to return. The default value is 500.

    Execute(int maxResults = 500)
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies