Copied to clipboard

Flag this post as spam?

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


  • John 88 posts 112 karma points
    Nov 30, 2011 @ 09:32
    John
    0

    Examine Search on NodeTypes

    Hi, I want to be able to search an Examine index for a couple of different node type aliases. Unfortunately my searches only search on the first alias passed in.

    var searcher = ExamineManager.Instance.SearchProviderCollection[Model.ExamineSearchProvider];
    var criteria = searcher.CreateSearchCriteria(IndexTypes.Content);
    var filter = (IBooleanOperation)null;
    var nodeTypeQuery = criteria.NodeTypeAlias(Model.DocumentTypesAlias[0]).Or();
    
    foreach (var docTypeAlias in Model.DocumentTypesAlias)
    {
        if (docTypeAlias == Model.DocumentTypesAlias[0]) continue;
    
        nodeTypeQuery.NodeTypeAlias(docTypeAlias).Or();
    }
    
    filter = nodeTypeQuery.OrderByDescending("updateDate");
    
    var results = searcher.Search(filter.Compile());
  • John 88 posts 112 karma points
    Nov 30, 2011 @ 10:26
    John
    0

    An update to this, the document types have some different fields. Can a search not return items of different DocTypes if their properties are not exactly the same?

    If so, is there anyway around this?

  • Carl Lundblad 12 posts 33 karma points
    Jan 04, 2012 @ 11:12
    Carl Lundblad
    0

    Heya, did you find the reason or, even better, a solution for this? Just stumbeled upon the very same problem. I tried it filtering on the field "__NodeTypeAlias", still only getting hits for whichever comes first.

    var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria();
    var filter = criteria.Field("__NodeTypeAlias", "dtevent").Or().Field("__NodeTypeAlias", "artikkel");

     

    No luck.

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jan 04, 2012 @ 12:44
    Tim
    1

    Hi Carl, 

    Have a look at this blog post: http://umbraco.com/follow-us/blog-archive/2011/9/16/examining-examine.aspx

    If you don't specify that the default operator should be OR, the first one will be required and the second will be optional, rather than both being optional!

    To make that happen, just change the first line of your code to the following:

    var criteria = ExamineManager.Instance.SearchProviderCollection["ContentSearcher"].CreateSearchCriteria(BooleanOperation.Or);

    And hopefully it should work how you want it to!

    Hope that helps!

    :)

  • Carl Lundblad 12 posts 33 karma points
    Jan 04, 2012 @ 12:57
    Carl Lundblad
    0

    Thats brilliant! :)

     

    Thank you Tim, worked like a charm. :)

  • Tim 1193 posts 2675 karma points MVP 4x c-trib
    Jan 04, 2012 @ 15:06
    Tim
    0

    No worries! Glad you got it working!

    :)

Please Sign in or register to post replies

Write your reply to:

Draft