Copied to clipboard

Flag this post as spam?

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


  • David Veksler 81 posts 166 karma points
    Dec 31, 2015 @ 21:03
    David Veksler
    0

    how to search for multiple document types with examine?

    I want to search for documents of several types with Examine.

    I have tried the below with And() and Or() but it does not work. Searching for a single document types works fine.

    var latestFreemanCriteria = ExamineManager.Instance.CreateSearchCriteria()
                  .NodeTypeAlias("apples").Or().NodeTypeAlias("bananas").Compile()
                    .OrderByDescending("publicationDate")
                    .Compile();
    
  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jan 04, 2016 @ 10:31
    Ismail Mayat
    0

    David,

    Can you do

    latestFreemanCriteria.ToString()
    

    And report back output this will give you the generated lucene query string and it will give you more information.

    You can also then try running that query directly on the index using luke for lucene tool.

    Regards

    Ismail

  • David Veksler 81 posts 166 karma points
    Jan 05, 2016 @ 16:52
    David Veksler
    0

    Here is the query and lucene string:

    var latestFreemanCriteria = ExamineManager.Instance.CreateSearchCriteria() .NodeTypeAlias("AnythingPeacefulArticle").Or().NodeTypeAlias("FreemanArticle").Or().NodeTypeAlias("ResourcesPage").Compile() .OrderByDescending("publicationDate") .Compile();

    { SearchIndexType: , LuceneQuery: +_NodeTypeAlias:anythingpeacefularticle _NodeTypeAlias:freemanarticle __NodeTypeAlias:resourcespage }

    This only searches the first alias I specify.

  • Ismail Mayat 4511 posts 10090 karma points MVP 2x admin c-trib
    Jan 05, 2016 @ 17:58
    Ismail Mayat
    0

    David,

    You need a GroupedOr. Also you are doing at the end an in memory sort which is not as efficient as getting lucene to do it for you.

    Lets get the groupedor working first then we can look at the sort.

    Regards

    Ismail

  • David Armitage 505 posts 2073 karma points
    Jul 23, 2020 @ 06:35
    David Armitage
    0

    Hi Guys,

    I posted a blog article about this here. https://www.umbrajobs.com/blog/posts/2020/july/umbraco-8-examine-how-to-search-multiple-doctypes/

    This is what you need.

     var searcher = index.GetSearcher();
                    var criteria = searcher.CreateQuery(IndexTypes.Content, BooleanOperation.Or);
                    var examineQuery = criteria.NodeTypeAlias("contentPage").Or().NodeTypeAlias("blogDetailsPage").Or().NodeTypeAlias("eventDetailsPage").Or().NodeTypeAlias("officeDetailsPage").Or().NodeTypeAlias("sectorDetailsPage").Or().NodeTypeAlias("serviceDetailsPage").Or().NodeTypeAlias("staffDetailsPage");
    
Please Sign in or register to post replies

Write your reply to:

Draft