Copied to clipboard

Flag this post as spam?

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


  • Dan 13 posts 113 karma points
    Jan 25, 2023 @ 08:58
    Dan
    0

    ExamineManager search in certain tree

    Hi everyone! Guys I need your advice!

    I've few cities on my website. And it needs to make a search in certain city tree. I've current city Id.

    For example, user of city 1 searching for something. It needs to return only page(s) from city 1 tree or from Blog tree:

    • City 1

      • About
      • Services

        • Service 1
          • Description page 1
          • etc.
      • Specialists

        • Specialist 1
    • City 2

      • About
      • Services
        • Service 1
          • Description page 1
          • etc.
      • Specialists
        • Specialist 1
        • etc.
    • Blog
      • Blog Article 1
      • etc.

    Here is what I've tried:

     List<string> ids = new List<string>();
     // Code for searching in certain city by id (rootId)
     ids = index
            .Searcher
            .CreateQuery("content")
            .ParentId(rootId)   //This returns only first child level
            .And()
            .GroupedOr(new[] { "__NodeTypeAlias" }, currentCitySearchTypes)
            .And()
            .ManagedQuery(query)                     
            .Execute().Select(x => x.Id).ToList();
    
        // And additional search for all other elements in the root(Blog etc.)
        ids.AddRange(index
                      .Searcher
                      .CreateQuery("content")
                      .ManagedQuery(query)
                      .And()
                      .GroupedOr(new[] { "__NodeTypeAlias" }, rootTypes)
                      .Execute().Select(x => x.Id).ToList());
    

    So problem is Parent() returns only first level child. It means, it never find Description page 1

    Umbraco 10

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 25, 2023 @ 09:14
    Dave Woestenborghs
    1

    Hi Dan,

    I would install this package : https://our.umbraco.com/packages/website-utilities/search-extensions/

    Umbraco has a path field in the index that is a comma seperated string of ids going from the root to your page. Some like "-1,500,300,600". But you can't query on that out of the box for all pages on that have a are under page with Id 500.

    This package will make that possible. It will index the path as seperate values. See https://github.com/callumbwhyte/umbraco-search-extensions#core-fields

    Than you can do query.Field("path", "500") and it will give you all items that have 500 in their path.

    Dave

  • Dan 13 posts 113 karma points
    Jan 26, 2023 @ 21:33
    Dan
    0

    Hi Dave!

    Appreciate for your answer and I've tried this package. But I can't get the expected result. I definitely do something wrong.

    Can you take a look at this please?

     if (_examineManager.TryGetIndex("ExternalIndex", out IIndex? index))
            {
                var searcher = index.Searcher;
                var searchQuery = searcher.CreatePublishedQuery().And();
                ids = searchQuery
                        .Field("path", rootId.ToString())
                        .And()
                        .ManagedQuery(query)
                        .Execute()
                        .Select(x => x.Id).ToList();
    }
    
  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 27, 2023 @ 07:53
    Dave Woestenborghs
    0

    Hi Dan,

    Just did some checking and I discovered there is a bug in the package I recommend to you.

    Good news I created a PR to fix it : https://github.com/callumbwhyte/umbraco-search-extensions/pulls

    So let's hope it will get merged soon and new release of the package will out.

    If you can't wait for that I would recommend doing the following. Remove the package from your website and over the following files from the package source code :

    And register the options in a composer.

    Dave

  • Dan 13 posts 113 karma points
    Jan 27, 2023 @ 19:06
    Dan
    0

    Hi Dave!

    Thanks for checking this and fixing it quickly

    I see there is no open pull requests and new version is released today. So I installed the new one 3.0.1. But it still returns nothings with my code above.

    Or is fix for this issue not included in this release?

Please Sign in or register to post replies

Write your reply to:

Draft