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

Support archive

Search Multiple Fields in a form with other field searches using one keyword input using collection

smartpill 23 Oct 2018 15:56 question, complete

This is for one field in an advanced search form that has multiple dropdown category selectors and a few keyword inputs. This is the field which I would like to also search the entry title.

''

If I try something like:

''
The results page returns an error. Is there a way to do this? I did create a collection that only has values for those fields but I'm not clear on how to reference that collection in the input. The overall search tag has multiple collections in the exp:low_search:form collections parameter.

The site is running Low Search v4.4.5 with ExpressionEngine 2.7.3

Replies

  1. Low 23 Oct 2018 18:26

    Not sure I follow; GetSat stripped away any code. Can you try again, maybe use http://pastebin.com/ for large chunks of code.

  2. smartpill 23 Oct 2018 19:29

    Oh, yeah that's no good. ;-)

    https://pastebin.com/X7LSmyks

  3. Low 24 Oct 2018 06:01

    If you want to search multiple fields with keywords, you'd have to use the Keywords filter. So, use

    <input name="keywords">


    along with a collection parameter (or leave empty for all collections). You said you've already created a collection for the combined fields, so you could use

    <input name="collection" value="ctm_comp_names">


    or just hard-code it on the Results tag:

    collection="ctm_comp_names"

  4. smartpill 24 Oct 2018 17:15

    In the input I used:

    type="text" collection="ctm_comp_names" name="keywords" value="{low_search_keywords}"

    I tried the collection parameter with just a single number and with the Collection Name. Seems to search the entry titles fine but the custom field which is a matrix field is not searched. If I only specify the matrix field it works. If I don't specify any collection name it doesn't work.

  5. Low 24 Oct 2018 18:05

    The Matrix field needs to be searchable itself, and has at least one searchable column defined in the field's settings. Then you can assign weight to it in the LS Collection details.

    Note that if the Matrix field wasn't searchable to begin with, you will need to re-save each entry to populate the actual searchable data. A bit of a pain, but there's no real way around it.

    Once that's done and you've created the collection, you can build the collection's index.

    To search that specific collection, you need 2 parameters: keywords and collection.

    Using an input field like this, using regular old HTML:

    <input type="text" collection="ctm_comp_names" name="keywords" value="{low_search_keywords}">


    ...won't do anything with the collection="" attribute. It's an custom attribute to an input element, is all. Check the docs on parameters again, you'll see that syntax doesn't make sense.

    Instead, as stated in the docs, either use an input field in a LS Form per parameter like this:

    <input name="keywords" value="{low_search_keywords}"> 
    <input name="collection" value="ctm_comp_names">


    ...or move the collection parameter to the Results tag, using EE's parameter syntax we all know:

    {exp:low_search:results query="{segment_x}" collection="ctm_comp_names" ...}

    smartpill 24 Oct 2018 19:10

    I did see that although the Matrix field was searchable the column in the matrix with the data I need to search didn't have "Is col searchable?" checked. So I checked that and re-saved the one entry I was testing for and then the search worked with name="keywords". Previously it worked without that box checked when I had the column specified in the single field search like this:

    search:resource_additional_names:rhn_historical_name

    so that was confusing.

    But at least I have a solution now. Thanks!

    Low 25 Oct 2018 05:51

    Difference between the Keywords filter (using keywords param) and Field Search filter (using search:field_name param) is that the former uses a custom search index you need to build, the latter targets the field directly.

    smartpill 25 Oct 2018 13:59

    Good to know. Thanks for clearing that up.