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

Support archive

Filtering search results from a grid channel field

Merv 23 Feb 2014 11:19 question, complete

Hi,
Sorry to have to ask this, but I could not figure it out from similar answers. My filtered search results are pulling all rows in a grid (called: wc_type_timetable), albeit correctly in terms of retrieving the matching rows, but it is also including other rows that don't meet the search criteria (meaning all rows of the grid dataset). Example, if I select the "practice" criteria "Aromatherapy", I get the records of all Wellness Centers that have "Aromatherapy" correctly but the problem is that the returned grid rows for a particular "Wellness Center" includes all the practices offered by them and not just "Aromatherapy".

Here is the search template code:


{exp:low_search:form
collection="wellness_centers"
query="{segment_2}"
result_page="directory/filtered-results-wellness-centers"
form_id="search"
search_mode="all"
}
<table width="100%">
<tr>
<fieldset class="fieldset">
<td width="20%">
<label for="city">City</label>
<div class="group">
<select name="search:wc_city">
<option value="">Dubai</option>
{exp:query sql="SELECT DISTINCT field_id_9 FROM exp_channel_data WHERE field_id_9 != '' AND field_id_9 !='Dubai' ORDER BY field_id_9 ASC"}
<option value="{field_id_9}">{field_id_9}</option>
{/exp:query}
</select>
<input type="hidden" name="exact[]" value="search:wc_city">

{!--
<select name="require_all[]">
<option value=""{if 'search:wc_city' NOT IN ({low_search_require_all})} selected{/if}>Any</option>
<option value="wc_city"{if 'wc_city' IN ({low_search_require_all})} selected{/if}>All</option>
</select> of the above
--}
</div>
</td>
<td width="25%">

<label for="wc_type_timetable:practice">Practice</label>
<div class="group">
<select name="search:wc_type_timetable:practice">
<option value="">Any practice</option>
<option value="Aromatherapy">Aromatherapy</option>
<option value="Massage-Ayurvedic">Massage:Ayurvedic</option>
<option value="Massage-Balinese">Massage:Balinese</option>
<option value="Massage-Deep-Tissue">Massage:Deep Tissue</option>
<option value="Massage-Hot-Stone">Massage:Hot Stone</option>
<option value="Massage-Javanese">Massage:Javanese</option>
<option value="Massage-Swedish">Massage:Swedish</option>
<option value="Massage-Thai">Massage:Thai</option>
<option value="Pilates">Pilates</option>
<option value="Reflexology">Reflexology</option>
<option value="Salt-Therapy">Salt Therapy</option>
<option value="Stretching">Stretching</option>
<option value="Yoga-Artistic">Yoga:Artistic</option>
</select>
<input type="hidden" name="exact[]" value="search:wc_type_timetable:practice">

{!--
<select name="require_all[]">
<option value=""{if 'search:wc_type_timetable:practice' NOT IN ({low_search_require_all})} selected{/if}>Any</option>
<option value="practice"{if 'practice' IN ({low_search_require_all})} selected{/if}>All</option>
</select> of the above
--}
</div>

</td>
<td width="20%">

<label for="day">Day</label>
<div class="group">
<select name="search:wc_type_timetable:day">
<option value="">Any day</option>
<option value="All">All weekdays</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
<option value="Sunday">Sunday</option>
</select>
<input type="hidden" name="exact[]" value="search:wc_type_timetable:day">

{!--
<select name="require_all[]">
<option value=""{if 'search:wc_type_timetable:day' NOT IN ({low_search_require_all})} selected{/if}>Any</option>
<option value="day"{if 'day' IN ({low_search_require_all})} selected{/if}>All</option>
</select> of the above
--}
</div>

</td>
<td width="15%">

<label for="time">Time</label>
<div class="group">
<select name="search:wc_type_timetable:start_time">
<option value="">Any time</option>
<option value="8:00">8:00 am</option>
<option value="8:30">8:30 am</option>
<option value="9:00">9:00 am</option>
<option value="9:30">9:30 am</option>
<option value="10:00">10:00 am</option>
<option value="10:30">10:30 am</option>
<option value="11:00">11:00 am</option>
<option value="11:00:30">11:30 am</option>
<option value="12:00">12:00 pm</option>
<option value="12:30">12:30 pm</option>
<option value="13:00">1:00 pm</option>
<option value="13:30">1:30 pm</option>
<option value="14:00">2:00 pm</option>
<option value="14:30">2:30 pm</option>
<option value="15:00">3:00 pm</option>
<option value="15:30">3:30 pm</option>
<option value="16:00">4:00 pm</option>
<option value="16:30">4:30 pm</option>
<option value="17:00">5:00 pm</option>
<option value="17:30">5:30 pm</option>
<option value="18:00">6:00 pm</option>
<option value="18:30">6:30 pm</option>
<option value="19:00">7:00 pm</option>
<option value="19:30">7:30 pm</option>
<option value="20:00">8:00 pm</option>
<option value="20:30">8:30 pm</option>
<option value="21:00">9:00 pm</option>
<option value="21:30">9:30 pm</option>
</select>
<input type="hidden" name="exact[]" value="search:wc_type_timetable:start_time">
</div>

</td>
<td width="20%">
<div class='searchSubmit'>
<input type='submit' value='Search' class='submit'>
</div>
</td>
</tr>
</fieldset>
</table>
{/exp:low_search:form}


Here is the filtered results template code:


{exp:low_search:results
query="{segment_3}"
status="not closed"
disable="member_data|category_fields"
paginate_base="directory/filtered-results-wellness-centers/{segment_3}" limit="5"
orderby_sort="wc_name|asc"
}

<div class="feature-box directorylisting">
<div class="pic">
<a href="">
<img src="{wc_picture}">
<noscript><img src="{wc_picture}"></noscript>
</a>
</div>
<div class="description">
<div class="title"><a href="">{wc_name}</a></div>
<br>
<p>{wc_service_description}</p>
<table width="70%" class="boldtable">
<tr>
<td width="35%" valign="top" class="wc-td">Practice</td><td width="15%" valign="top" class="wc-td">Day</td><td width="15%" valign="top" class="wc-td">Starts</td><td width="15%" valign="top" class="wc-td">Ends</td>
</tr>
{wc_type_timetable}
<tr>
<td width="35%" valign="top">{wc_type_timetable:practice}</td><td width="15%" valign="top">{wc_type_timetable:day}</td><td width="15%" valign="top">{wc_type_timetable:start_time}</td><td width="15%" valign="top">{wc_type_timetable:end_time}</td>
</tr>
{/wc_type_timetable}
</table>
<div class="byline"><br>{wc_street_address}<br>
{wc_city}<br>
{wc_country}<br>
{wc_telephone}<br><br>
<a href="{wc_website}" target="_blank">{wc_name} website</a>
</div>
</div>
<div class="social">
<a href=""><i class="icon-retweet"></i> <span class="feature-shares" data-url=""></span> shares</a>
&nbsp;&nbsp;
<a href=""><i class="icon-comments"></i> <fb:comments-count href=""></fb:comments-count> comments</a>
</div>
</div>
{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/paginate}
{if low_search_no_results}
<p>
Sorry, your query did not return any results.<br>
Try <a href="{site_url}directory/search-results-wellness-centers"><u>searching</u></a> with fewer criteria by selecting (<i>Any day</i> or <i>Any time</i>) instead of a specific day or time.
</p>
{/if}
{/exp:low_search:results}

--------------------------------

Thank you

Merv

Replies

  1. Low 23 Feb 2014 11:42

    The thing to remember is that Low Search always returns entries that match the search criteria. The Grid field is part of the entry; Low Search does not filter the Grid field itself. You'd have to do that yourself in the Results tag, using the search:col_name params: http://ellislab.com/expressionengine/...

    For example:

    {wc_type_timetable search:practice="{low_search_search:wc_type_timetable:practice}"} 
    ...
    {/wc_type_timetable}


    You can apply that principle to each filter, if needed.

  2. Merv 23 Feb 2014 17:15

    Hi

    Thanks a lot. It works now.

    Many thanks for your help.

    Merv