Copied to clipboard

Flag this post as spam?

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


  • trfletch 598 posts 604 karma points
    May 16, 2016 @ 17:45
    trfletch
    0

    Examine AND OR query

    I am working on an Examine search that has a free text field and then some additional filters (which are in the form of checkbox lists). The problem I have is trying to get the additional filters to work.

    I am passing through separate string lists of filters, if more than one filter option is selected then it should show results that match either of those filters.

    For example, if filter 1 has five options as follows:

    • A
    • B
    • C
    • D
    • E

    And both "B" and "D" are selected it should return results where "property1" is either "B" or "D" as well as matching on the free text search.

    This is what I have so far but it does not work (it just returns all results), can anyone point me in the right direction:

    if (searchTerm != string.Empty) {
    
    var fields = new[] {"nodeName", "heading1", "summary", "mainText"};
    var term = new IExamineValue[] {searchTerm.ToLower().Escape()};
    
    // Setup query
    query = searchCriteria.GroupedOr(fields, term);
    
    if (filters1.Any())
    {
        query.And();
        foreach (var x in filters1)
            query.Or().Field("property1", x);
    }
    
    if (filters2.Any())
    {
        query.And();
        foreach (var x in filters2)
            query.Or().Field("property2", x);
    }
    
    // Run search query
    var searchResults = searcher.Search(query.Compile());
    

    }

Please Sign in or register to post replies

Write your reply to:

Draft