Copied to clipboard

Flag this post as spam?

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


  • Thomas 160 posts 335 karma points
    Jun 27, 2021 @ 21:11
    Thomas
    0

    Examine v1.2.1 query problem

    Hi all. I have a news site based on umbraco 8.11.1 with Examine v1.0.6 and i am using the following code in order to query articles.

    // Get the external index with error checking
            //-------------------------------------------
            if (!_examineManager.TryGetIndex(UmbracoIndexes.ExternalIndexName, out IIndex index))
            {
                throw new InvalidOperationException($"No index found by name {UmbracoIndexes.ExternalIndexName}");
            }
    
            try
            {
                var searcher = index.GetSearcher();
                var criteria = searcher.CreateQuery(IndexTypes.Content);
    
                // Search Code to use with the ExternalIndex
                // -----------------------------------------
                var examineQuery = criteria.Field("__NodeTypeAlias", "newsArticle");
                if (model.ParentId.HasValue)
                    examineQuery.And().ParentId(model.ParentId.Value);
                examineQuery.OrderByDescending(new SortableField[] { new SortableField("articleUpdateDate", SortType.Long), new SortableField("__NodeId", SortType.Int) });
    

    The value of the examine query is

    +__NodeTypeAlias:newsarticle

    if the parentID varialble does not have value and

    +__NodeTypeAlias:newsarticle +(parentID:[1063 TO 1063])

    if the parentID variable has a value.

    The results are great and works as expected.

    After upgrading umbraco to 8.14.0 which upgrades the Examine library to 1.2.0 unfortunately i am not getting any results. If a use the umbraco backend examine search interface i am getting results but from the code behind i am not getting anything.

    Any help please?

  • Thomas 160 posts 335 karma points
    Jun 27, 2021 @ 22:10
    Thomas
    0

    Well after a lot of debugging on the following code

    try
            {
                var searcher = index.GetSearcher();
                var criteria = searcher.CreateQuery(IndexTypes.Content);
    
                // Search Code to use with the ExternalIndex
                // -----------------------------------------
                var examineQuery = criteria.Field("__NodeTypeAlias", "newsArticle");
                if (model.ParentId.HasValue)
                    examineQuery.And().ParentId(model.ParentId.Value);
                examineQuery.OrderByDescending(new SortableField[] { new SortableField("articleUpdateDate", SortType.Long), new SortableField("__NodeId", SortType.Int) });
    
                int pageSize = model.ItemsPerPage;
                int pageIndex = model.CurrentPage - 1;
    
                ISearchResults searchResult = examineQuery.Execute(maxResults: pageSize * (pageIndex + 1));
                IEnumerable<ISearchResult> pagedResults = searchResult.Skip(pageIndex * pageSize);
                int totalResults = Convert.ToInt32(searchResult.TotalItemCount);
    
                model.TotalItems = totalResults;
                model.TotalPages = (totalResults + model.ItemsPerPage - 1) / model.ItemsPerPage;
    
                if (pagedResults != null && pagedResults.Count() > 0)
                {
                    model.Articles = GetArticlesFromSearch(pagedResults);
                }
            }
            catch (Exception e)
            {
                _logger.Error(GetType(), "Search | Exception: {0} | Message: {1}", e.InnerException != null ? e.InnerException.ToString() : "", e.Message != null ? e.Message.ToString() : "");
            }
    

    i found that i am getting value for the searchResult.TotalItemCount but i am not getting Results. Using Examine 1.0.6 i was getting the Results also.

  • 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