All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Combining AND and OR with Field Search filter

Bhashkar Yadav 15 Jan 2014 01:10 question, complete

Hi Low,

I would like to have same feature with AND/OR condition but sorry I couldn't understand exactly what to do with this discussion.

Let me explain. My low:search form code is like:

My seach form is like:

{exp:low_search:form}
Field 1:

#####

Field 2:

#####

Field 3:

#####

AND
OR

{/exp:low_search:form}

On changing and_or select box to OR, I am updating require_all value as "search:field1|search:field2|search:field3" i.e

But it doesn't seem working for OR. Could you please guide me where I am going wrong.

Thanks,

Note: This topic was created from a reply on the Possible to specify AND/OR custom field searches? topic.

Replies

  1. Low 15 Jan 2014 08:12

    Moving your reply to a new thread removed some of the formatting. Here is the code you originally had:

    {exp:low_search:form} 
    Field 1:
    <select name="search:field1[]">
    #####
    </select>
    Field 2:
    <select name="search:field2[]">
    #####
    </select>
    Field 3:
    <select name="search:field3[]">
    #####
    </select>
    <select name="and_or">
    <option value="and">AND</option>
    <option value="or">OR</option>
    </select>
    <input type="hidden" name="require_all" id="require_all" value="{low_search_require_all}" />
    {/exp:low_search:form}

  2. Low 15 Jan 2014 08:21

    So, my question to you is, what are you expecting? A setup like yours will always result in something like:

    (field1-a OR field1-b) AND (field2-c OR field2-d) AND (field3-e OR field3-f)

    where -a and -b are values for each field.

    Adding the parameter names to the require_all value, will change that to

    (field1-a AND field1-b) AND (field2-c AND field2-d) AND (field3-e AND field3-f)

    The different parameters (fields) are always separated with AND, just like you would expect in actual parameter syntax:

    search:field1="a|b" search:field2="c|d" search:field3="e|f"


    You could simplify your template by removing the hidden field and use this instead:

    <select name="require_all"> 
    <option value="search:field1|search:field2|search:field3">AND</option>
    <option value="">OR</option>
    </select>

  3. Bhashkar Yadav 15 Jan 2014 18:17

    Hi Low,

    Thanks for your kind response. Simply, I would like to have "Field1 OR Field2 OR Field3" for OR filter. Same like AND filter: "Field1 AND Field2 AND Field3".

    Could you please guide me.

    Thanks

  4. Low 15 Jan 2014 20:42

    Using OR between different parameters is not possible. That's what the Feature Request thread is about.

  5. Bhashkar Yadav 15 Jan 2014 20:48

    Thanks Low.

    I was looking for extension hooks of Low Search but couldn't find any suitable hook for it.
    Could you please guide if its possible via any extension hook from http://gotolow.com/addons/low-search/...

    Thanks

  6. Low 15 Jan 2014 20:51

    For a custom solution, your best bet is to use the low_search_pre_search hook, read out your parameters, perform your queries and set the entry_id parameter with the search results accordingly.