Copied to clipboard

Flag this post as spam?

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


  • Daniel Rogers 134 posts 712 karma points
    Oct 07, 2021 @ 23:13
    Daniel Rogers
    0

    Examine get exact doc type

    using Umbraco8

    I have 2 Doctypes that are similarly named.

    IBDeCommerceProduct IBDeCommerceProduct_Folder

    My issue is that when I run the following code I get both doctypes back not the one I want

                ISearcher examineSearcher = ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index) ? index.GetSearcher() : null;
                //restrict the search to the Content section, create our search criteria object
                IQuery criteria = examineSearcher.CreateQuery("content");
    IBooleanOperation queryNodes = criteria.GroupedOr(new string[] { __NodeTypeAlias }, "IBD_eCommerce_Product");
    

    How do I ensure only the exact Doctype is returned?

  • Erik Eelman 79 posts 319 karma points
    Oct 18, 2021 @ 07:08
    Erik Eelman
    0

    Hi Daniel,

    Does this work for you?:

      ISearcher examineSearcher = ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index) ? index.GetSearcher() : null;
                //restrict the search to the Content section, create our search criteria object
                IBooleanOperation queryNodes = examineSearcher.CreateQuery("content").NodeTypeAlias("IBD_eCommerce_Product");
    
  • Daniel Rogers 134 posts 712 karma points
    Oct 18, 2021 @ 13:36
    Daniel Rogers
    100

    This has the same issue it also returns both IBDeCommerceProduct and IBDeCommerceProduct_Folder

    It seams to be treating the query as IBD_eCommerce_Product a work around I have experimented and done this and it works.

    IBooleanOperation queryNodes = examineSearcher.CreateQuery("content").NodeTypeAlias("IBD_eCommerce_Product").Not().NodeTypeAlias("Folder");
    

    I wouldnt same this was the best solution but it is fine for this instance.

  • Bjarne Fyrstenborg 1281 posts 3991 karma points MVP 7x c-trib
    Oct 18, 2021 @ 07:28
    Bjarne Fyrstenborg
    0

    Hi Daniel

    You can use NodeTypeAlias() method like Erik mentioned or if you want to filter on multiple document type alias:

    if (ExamineManager.Instance.TryGetIndex("ExternalIndex", out var index))
    {
         var examineSearcher = index.GetSearcher();
    
         //restrict the search to the Content section, create our search criteria object
         IQuery criteria = examineSearcher.CreateQuery("content");
    
         IBooleanOperation queryNodes = criteria.GroupedOr(new string[] { __NodeTypeAlias }, new string [] { "IBD_eCommerce_Product" });
    }
    

    You could alternatively also use the NodeTypeAlias(string[] aliases) Examine search extension from this package: https://our.umbraco.com/packages/website-utilities/search-extensions/

Please Sign in or register to post replies

Write your reply to:

Draft