Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 211 posts 620 karma points c-trib
    Mar 19, 2018 @ 09:49
    Lewis Smith
    0

    Examine Search results to show results that have empty strings

    Hi All,

    I'm exploring the word of examine to do some searching for all 'products' and I'm trying to get examine to pick up the pages that do not have anything entered:

    E.g

    If the user lands on the page when it's not filtering by the category of design I want to show all the products (those with designs and those without anything entered as design is not a mandatory field) but if the user does search by design then I want to show the designs for what they're searching for.

    The way I currently have examine set up doesn't cater for this as I create an array of all options and search for this when nothing is being searched for meaning the empty string found on the products that dont have anything entered are not being found. Then when something is being searched for I only search for this one.

    Could anyone shed some light on this?

    I basically want my searcher to add fields that are null or empty to the results list unless its being searched for.

    Current query

    var query = searchCriteria
            .GroupedOr(new string[] { "gender" }, genderArray.ToArray()).And()
            .GroupedOr(new string[] { "design" }, designArray.ToArray());
    

    gender array is set to all genders unless it's being searched for then its set to the searched for gender. The same goes for design which is why pages without anything entered for design or gender are not being found as their results of null or empty are not within the array

    Thanks,

    Lewis

  • Paul Tilsed 26 posts 179 karma points c-trib
    Mar 20, 2018 @ 15:13
    Paul Tilsed
    0

    Hi Lewis,

    You should be able to build up the query based on if each search parameter has any values or not. Something like this might be along the right lines:

    var query = searchCriteria;
    
    if(genderArray.Any())
            query = query.And().GroupedOr(new string[] { "gender" }, genderArray.ToArray())
    
    if(designArray.Any())
            query = query.And().GroupedOr(new string[] { "design" }, designArray.ToArray())
    

    You should be able to expand this out to fit the exact requirements for your search.

    Thanks,

    Paul

Please Sign in or register to post replies

Write your reply to:

Draft