Copied to clipboard

Flag this post as spam?

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


  • Adriano Fabri 469 posts 1633 karma points
    May 18, 2021 @ 14:52
    Adriano Fabri
    1

    Examine Search: How to query nodes of specific parent

    Hi to all, I'm trying to find a way to search nodes of a specific parent.

    I read the very helpful Shazwazza examine documentation and I think that I must search in the field "__Path" that have a specific Node Id.

    In the documentation I found this code from which I think I could start

    var exactfilter = exactcriteria.Field("__Path", "-1,123,456,789".Escape());
    

    But after some tests, I still don't find the right solution.

    Can anyone help me?

    Thank you for the support

    Adriano

  • Paul Seal 524 posts 2889 karma points MVP 7x c-trib
    May 18, 2021 @ 16:41
    Paul Seal
    0

    Hi You need to add a searchable path to the examine index which essentially takes the path and replaces the commas with spaces. Here is a link to some documentation which has an example for you.

    https://our.umbraco.com/documentation/reference/searching/examine/examine-events#adding-the-path-of-the-node-as-a-searchable-field-into-the-index

    Paul

  • Adriano Fabri 469 posts 1633 karma points
    May 31, 2021 @ 09:44
    Adriano Fabri
    100

    Hi...sorry for delay to answer.

    I try some solutions, including that you suggest, but I resolved using this simple code:

    if(ExamineManager.Instance.TryGetIndex("InternalIndex", out var index))
    {
        var Searcher = index.GetSearcher();
        var textFields = new[] { "nodeName", "title",  "bodyText" };
        var results = ((Searcher.CreateQuery()
                                  .GroupedOr(textFields, searchTerm)
                                  .OrderByDescending(new SortableField("date"))
                                  .Execute())
                                  .Where(w => w["__IndexType"] == "content" &&  
                                              w["__NodeTypeAlias"] == "repository" &&
                                              w["__Path"].Contains("16602") &&
                                              w["__Published"] == "y" &&
                                              w["umbracoNaviHide"] == "0"));
        ...
        ...
    }
    

    Adriano

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    May 31, 2021 @ 10:39
    Bjarne Fyrstenborg
    1

    Just note that this won't work if you have more than 500 results as Execute() by default limit to 500 results and that the LINQ query is more expensive.

    You can add a searchPath like this in Vendr demo store

    https://github.com/vendrhub/vendr-demo-store/blob/a976c4eafefcd3e92acbc9d65d4c73b529746e36/src/Vendr.DemoStore/Composing/DemoStoreComponent.cs#L83-L86

    and then search this field, something like the following:

    query.GroupedOr(new [] { "searchPath" }, new [] { "16602" } );
    

    /Bjarne

  • Adriano Fabri 469 posts 1633 karma points
    Jun 11, 2021 @ 15:41
    Adriano Fabri
    0

    Hi Bjarne,

    thank you for the support.

    I added the search path field like Vendr demo store...but I already have the GroupedOr(textFields, searchTerm) in my query

    How I must change the code to include your change?

    Adriano

  • Josef Henryson 24 posts 98 karma points
    May 05, 2023 @ 09:32
    Josef Henryson
    1

    Hi. I tried to add a piece of your code but VS complains that there is no Add() method taking 2 arguments..

    // Create searchable path
    if (e.ValueSet.Values.ContainsKey("path"))
    {
       e.ValueSet.Add("searchPath", e.ValueSet.GetValue("path").ToString().Replace(',', ' '));
    }
    
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jun 11, 2021 @ 16:31
    Bjarne Fyrstenborg
    3

    Hi Adriano

    Based on your query before, you can filter the results as part of the Examine query something like the following:

    var query = searcher.CreateQuery("content")
            .NodeTypeAlias("repository")
            .And()
            .Field("searchPath", "16602")
            .And()
            .Field("__Published", "y")
            .And()
            .Field("umbracoNaviHide", "0")
            .And()
            .GroupedOr(textFields, searchTerm)
            .Execute();
    
    var results = query
            .OrderByDescending(new SortableField("date"))
            .Execute();
    

    To search path you may need to create a searchPath field: https://our.umbraco.com/documentation/reference/searching/examine/examine-events

    /Bjarne

  • Adriano Fabri 469 posts 1633 karma points
    Jun 11, 2021 @ 16:55
    Adriano Fabri
    0

    Wonderful, I'll try next Monday ;-)

    Thank you and have a good weekend

    Adriano

  • Adriano Fabri 469 posts 1633 karma points
    Jun 14, 2021 @ 14:57
    Adriano Fabri
    0

    Hi Bjarne,

    I tried and all function properly.

    Only for info...to work correctly I had to write the query like that:

     var results = Searcher.CreateQuery("content")
                  .Field("__Published", "y")
                  .And()
                  .Field("umbracoNaviHide", "0")
                  .And()
                  .NodeTypeAlias("repository")
                  .And()
                  .Field("searchPath", Model.Id.ToString())
                  .And()
                  .GroupedOr(textFields, searchTerm)
                  .OrderBy(new SortableField("nodeName"))
                  .Execute();
    

    Thank you again

    Adriano

Please Sign in or register to post replies

Write your reply to:

Draft