search in multiple text fields plus category How?
I am using Low ver 4 on an EE 2 site.
I have a business directory search form and I want to be able to search for multiple fields.
The fields would be Business Name (text field) , City (text field) and a list of categories.
I would like the user to be able to fill in any combination of fields and get results. ie:
search for entries in New York and include category 1,2,3
or Business name XYZ in Miami. Basically any combination of all 3 fields.
Can you help ,e get started? Do I use collections? Sorry for such a basic question I am new to Low search
Replies
Low 10 Apr 2017 14:23
I'd set up a collection where you add weight to the Business Name field, and use the Keywords filter for that.
Then, since you're looking for a specific match, use the Field Search filter for the City matching.
Finally, generate your list of categories using the native categories tag and use the Categories filter for that one.
Read up on the docs, the filter details (as linked above), tags and the examples to get going.
peter e 11 Apr 2017 12:30
Thank you so much for your assistance.
Can you help let me know if I am on the right track with this code?
{exp:low_search:form collection="find-a-clinic" result_page="search/low_results" query="{segment_3}"}
<fieldset>
<input type="search" name="keywords" placeholder="Search Keyword..">
<input type="search" name="search:title" placeholder="Clinic Name..">
<input type="search" name="search:find-a-clinic_city" placeholder="City..">
<select class="cus-select">
<option selected disabled>Area of Practice</option>
{exp:channel:categories category_group="10" style="linear"}
<option value="{category_id}"{if low_search_category ~ '/\b'.category_id.'\b/'} selected{/if}>
{category_name}
</option> {/exp:channel:categories}
</select>
<button type="submit">Go</button>
{if low_search_keywords_missing}<em>Keywords are required</em>{/if}
</fieldset>
{/exp:low_search:form}
How do I create 2 separate fields one for keywords and one for city?
If I only select a category it doesn't work as keywords are required.
Thanks in advance
Low 11 Apr 2017 14:34
Couple of pointers.
1. Move the collection="" parameter to the Results tag.
See also the first alinea here.
collection
is a filter parameter so won't do anything as a parameter on the Form tag.2. Add a
name="category"
to the select elementThe select element has no name attribute, so nothing will be sent to the server like that. Add name="category" to trigger the Categories filter. Add name="category[]" if you're using a multiple-select element.
3. Add a
value=""
to the first option elementIf an
option
element has novalue
attribute, the value will be the enclosed text, which you do not want.You've already created 2 fields for keywords and one for city. Remove required="keywords" from the Form tag to make the keywords optional.
peter e 11 Apr 2017 16:16
THANKS NOW WE ARE GETTING SOMEWHERE!!
when I search for City or catgory etc my s=results show search for... "blank"
instead of the text I entered in the field.
{low_search_keywords}
Since I am not using a keyword what do I add here on the results page?
Searched for {low_search_keywords}.
And why are the scores always 0 now?
Why does the search log ONLY show keyword search history?
Low 11 Apr 2017 16:23
As explained here, you can access any parameter value using a variable with the same name and
{low_search_
prefix. When using in the Form, make sure you've set the query="" param, too.Scores can only be calculated when using keywords searches.
The search log will show all other parameters under the 'Parameters' heading. You can click that part for each row (when there's a horizontal ellipsis) to reveal all params.