Copied to clipboard

Flag this post as spam?

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


  • Mitch 1 post 71 karma points
    Sep 13, 2016 @ 18:33
    Mitch
    0

    Umbraco Examine returning results with True/False property

    I am using Umbraco Examine for a basic site search. I have a DocType that has a property with a true/false data type. I want the search to return any content of that doctype where the property is true if the name of the property is the search query. Any suggestions?

  • Ivan Ponomarenko 20 posts 105 karma points
    Sep 14, 2016 @ 08:52
    Ivan Ponomarenko
    1

    Hi Mitch!

    I think you have minimum two solutions.

    Best way is use this example code:

    BaseSearchProvider searcher = ExamineManager.Instance.SearchProviderCollection[searcherName];
    ISearchCriteria criteria = searcher.CreateSearchCriteria(BooleanOperation.Or);
    ISearchCriteria filter = criteria.GroupedOr(new []{"Title", "Name", "Description"}, searchTerm).Not().Field("TrueFalsePropertyAlias", "0").Compile();
    ISearchResults results = searcher.Search(filter); 
    

    Note .Field("TrueFalsePropertyAlias", "0")

    Or you can filter all search results by fields:

    ISearchResults results = searcher.Search(filter);
    IEnumerable<SearchResult> filteredResults = results.Where(x => x.Fields.Contains(new KeyValuePair<String, String>("TrueFalsePropertyAlias", "1")));
    

    Hope it help you!

    Regards, Ivan

Please Sign in or register to post replies

Write your reply to:

Draft