Copied to clipboard

Flag this post as spam?

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


  • Pedro Marinho 10 posts 80 karma points
    Dec 21, 2017 @ 16:32
    Pedro Marinho
    0

    Examine - search properties with multiple values

    Hello,

    i'm using Examine to search for nodes that have multiple values in a property. Example: i have a node called "News" wich has a property called "categories" , this property is a "Dropdown list multiple, publish keys".

    If I have two "News" like these:

    News 1 :

    • categories: categoryId1, categoryId2

    News 2 :

    • categories: categoryId2

    When I do a search for all "news" of categoryId2, I'm expecting to see the two "news", but only "News 2" is listed.

    I'm using this code to do the search

    ISearchCriteria searchCriteria = ExamineManager.Instance.CreateSearchCriteria(BooleanOperation.Or);
        IBooleanOperation queryNodes = null;
        queryNodes = searchCriteria.GroupedNot(new string[] { "Visible" }, "0");
    
    
    queryNodes = queryNodes.And().GroupedOr(new string[] { _docTypeAliasFieldName }, documentTypesAlias);
     queryNodes = queryNodes.And().GroupedOr(new string[] { "categories" }, new[] { querySearch.Category });
    
    var results = Umbraco.TypedSearch(queryNodes.Compile());
    

    How can I achieve what I'm looking for?

  • Marco 12 posts 92 karma points c-trib
    Dec 22, 2017 @ 07:33
    Marco
    0

    Hello Pedro,

    I usually provide the search string as a string array (string[]).

    Maybe you could try to split querySearch.Catagory. Example:

    queryNodes = queryNodes.And().GroupedOr(new string[] { "categories" },  querySearch.Category.Split(new char[0]));
    

    this will split the Category by whitespace but of course you can split any way you like.

  • Pedro Marinho 10 posts 80 karma points
    Dec 22, 2017 @ 10:02
    Pedro Marinho
    0

    Hello Marco, thank you for your help, but that not solves my problem. With your code I only get an exact match of the results like I had explained before. I've looked the "umbraco.config" file and saw that the field is stored like this

     <news id="2201" key="73af51b4-991b-46d2-be82-40268397a13f" parentID="1068" level="2" creatorID="0" sortOrder="8" createDate="2017-08-22T16:25:53" updateDate="2017-10-11T17:03:20" nodeName="Noticias e Eventos" urlName="noticias-e-eventos" path="-1,1068,2201" isDoc="" nodeType="1096" creatorName="Admin" writerName="Admin" writerID="0" template="2466" nodeTypeAlias="newsList">
    <categories><![CDATA[4299,5299]]></categories>
    

    Looks like the Examine is treating the field "categories" like a string. So when I configured the filter like this

    queryNodes = queryNodes.And().GroupedOr(new string[] { "categories" }, new[] { querySearch.Category });
    

    it gives me exact match results.

    What I'm looking for is similar to these in SQL

    SELECT * FROM News WHERE categories LIKE '%4299%'
    
  • Pedro Marinho 10 posts 80 karma points
    Jan 03, 2018 @ 10:02
    Pedro Marinho
    0

    Any clues?

  • Marco 12 posts 92 karma points c-trib
    Jan 04, 2018 @ 07:02
    Marco
    0

    Sorry Pedro I've been on holiday for a couple of days.

    I think you are swapping things up. The umbraco.config file is not the Examine index. You can query the index pretty easy via the Developer section in your Umbrack backend.

    Maybe if you try that you get a better understanding of how the field is indexed by Examine. If you post that here hopefully I (or someone else) would be able to help you better.

    Regards.

Please Sign in or register to post replies

Write your reply to:

Draft