How can I search/filter by a multi select custom field using Low Search?
I'm building an "Advanced Search Form" using Low Search, and I'm having difficulty getting a Multi Select custom field to produce search results. Using Low Search and Low Options, here's the code I'm trying:
<select name="search:fieldname[]" multiple="multiple" />
{exp:low_options:fieldname}
{options}<option value="{option:value}">{option:label}</option>{/options}
{/exp:low_options:fieldname}
</select>
It renders the multi select field just fine in my search form, but when I select one or more options, it does not pull up the appropriate entries.
For what it's worth, I've gotten Low Search and Low Options to work fine with single-select dropdown fields. But not here.
What might I be doing wrong?
Replies
Low 24 Jan 2013 08:46
In what sense does it not produce the right results? Remember that the search:fieldname[] field will perform substring matching.
MattV 24 Jan 2013 16:31
Sorry, I should have been more specific. I get no matches at all.
Low 24 Jan 2013 16:34
What's your full Low Search Form and Results tag? Use http://pastie.org for the code (or GetSat might break).
Also, what does the Template Debugger say? Can you copy/paste all lines that mention Low Search here?
MattV 24 Jan 2013 17:48
I've created a pastie with the Search Form and Results tags, as well as the queries and template debugger lines that mention Low Search.
http://pastie.org/5849187
MattV 24 Jan 2013 22:13
Still troubleshooting, but I feel like I'm getting somewhere.
When I just put the options in manually into the select list, the search function works fine. When I use Low Options, it fails.
I think the answer might be in this part of the query that I posted in the pastie above:
LIKE "%Agriculture\n%"
When I do the search with the manual list of options and without Low Options, the query looks like this:
LIKE "%Agriculture%"
Also, when I look at the source for the select using Low Options, each option appears to exist on a single line. But when I cut and paste the source into a text editor, each option breaks down like this:
<option value="Agriculture
">Agriculture
</option>
Could Low Options be introducing some sort of newline character that is interfering with Low Search?
MattV 24 Jan 2013 22:34
I should mention that this seems to only be the case for fields with the EE Multi Select fieldtype. I can convert a P&T Dropdown field into a multiple-select field in the Search form HTML, and it works just fine.
Low 24 Jan 2013 22:44
Yeah, looks like that newline might be the cause. Can you make sure the field's options field doesn't have trailing spaces and such? Or perhaps try and enter the options again?
MattV 24 Jan 2013 22:53
Huh. There didn't seem to be any additional characters in the field options. And I cut-and-pasted it into a text editor and looked for invisible characters.
But when I cut-and-pasted it back into the field options and resaved the field, the search form finally worked properly! Hooray!
Thanks for helping me figure this out. And my apologies for taking up your time on something that didn't end up being related to Low Options at all.
And thanks so much for Low Search. It's working out really well so far.
Low 24 Jan 2013 22:54
No probs. Glad it's working now!