Searching Distance, Date and Keyword (all together) Problems
Hi, I'm creating a fairly complex search using the distance filter, keywords and the channel tag's start_on parameter all at once. If I search by distance and keywords everything is great, keywords alone work great, as does distance alone but searching by distance AND keywords AND date results in a no results message. Thanks for taking a look...
Here's my simplified code:
{exp:low_search:results
channel="sightings"
distance:from="{cookie:_lat}|{cookie:_lon}"
distance:to="latitude|longitude"
distance:radius=""
distance:unit="{cookie:_format}"
limit="10"
query="{segment_2}"
orderby_sort="distance"
start_on="{cookie:date_filter}"
}
<!-- SEARCH -->
{exp:low_search:form required="keywords" result_page="website/index"}
<select id="category" name="category[]" class="form-control">
<option>Sighting Type</option>
<option>Man saw Woman</option>
<option>Woman saw Man</option>
<option>Man saw Man</option>
<option>Woman saw Woman</option>
<option>Other</option>
</select>
<select id="date_filter" name="date_filter" class="form-control" onchange="timeshift();">
<option value="365 days ago"{if cookie:date_filter == '365 days ago'} selected{/if}>last Year</option>
<option value="31 days ago"{if cookie:date_filter == '31 days ago'} selected{/if}>last Month</option>
<option value="7 days ago"{if cookie:date_filter == '7 days ago'} selected{/if}>last Week</option>
<option value="yesterday"{if cookie:date_filter == 'yesterday'} selected{/if}>Yesterday</option>
<option value="today"{if cookie:date_filter == 'today'} selected{/if}>Today</option>
<option value="3 hours ago"{if cookie:date_filter == '3 hours ago'} selected{/if}>last 3 Hours</option>
</select>
<input type="text" class="form-control custom-form-control" value="{if low_search_keywords}{absolute_results} Matches: {low_search_keywords}{/if}" aria-label="search" name="keywords" placeholder="Search Sightings">
<span class="input-group-btn"><button class="btn btn-success" type="submit"><span class=" glyphicon glyphicon-search"></span></button></span>
{/exp:low_search:form}
<script>
// write cookie for selected timeframe to put into search tag as parameter
function timeshift() {
var x = document.getElementById("date_filter").value;
document.cookie = 'date_filter ='+x+'; expires=Wed, 31 Dec 2025 00:00:00 UTC';
}
</script>
<!-- channel content results -->
<p>{title}</p>
{if low_search_no_results}
...no results...
{/if}
{/exp:low_search:results}
Replies
Low 31 Dec 2016 09:06
Does searching with just the date filter work? Can you enable template debugging and share all lines that mention Low Search or low_search?
Varen Swaab 31 Dec 2016 18:51
Low
Thanks for getting back to me I was hoping to work on this all weekend ;-)
Yes, searching works fine with just the date filter and no keywords entered. If I remove the date filter then keywords work just fine but all together I get no results. Here's the debugging:
0.075002 / 6.1MB Calling Tag: {exp:low_search:results channel="sightings" distance:from="48.11206548650057|-122.76600045561938" distance:to="latitude|longitude" distance:radius="" distance:unit="yd" limit="10" query="eyJyZXN1bHRfcGFnZSI6IndlYnNpdGVcL2luZGV4IiwiY2F0ZWdvcnkiOiJTaWdodGluZyBUeXBlIiwiZGF0ZV9maWx0ZXIiOiIzMSBkYXlzIGFnbyIsImtleXdvcmRzIjoiZG93bnRvd24ifQ" orderby_sort="distance" start_on="3 hours ago" }
0.085111 / 6.5MB Low Search: Prepping if low_search_no_results conditional
0.097841 / 6.9MB Low Search: Applying Low_search_filter_distance
0.097961 / 6.9MB Low Search: Getting channel field info from API
0.114139 / 7.4MB Low Search: Applying Low_search_filter_keywords
0.115581 / 7.4MB Low Search: Keywords: downtown
0.115832 / 7.4MB Low Search: Starting search (fulltext)
0.117472 / 7.5MB Low Search: Ordering results by score
0.117508 / 7.5MB Low Search: Returning entry IDs
0.117595 / 7.4MB Low Search: Setting fixed_order param
0.117988 / 7.4MB Low Search: Parameters set: channel="sightings" distance:from="48.11206548650057|-122.76600045561938" distance:to="latitude|longitude" distance:radius="" distance:unit="yd" limit="10" query="eyJyZXN1bHRfcGFnZSI6IndlYnNpdGVcL2luZGV4IiwiY2F0ZWdvcnkiOiJTaWdodGluZyBUeXBlIiwiZGF0ZV9maWx0ZXIiOiIzMSBkYXlzIGFnbyIsImtleXdvcmRzIjoiZG93bnRvd24ifQ" orderby_sort="distance" start_on="3 hours ago" result_page="website/index" category="Sighting Type" date_filter="31 days ago" keywords="downtown" fixed_order="18"
0.118004 / 7.4MB Low Search: Pre-applying search vars to tagdata
0.124862 / 7.4MB Low Search: Calling the channel module
0.149752 / 8.1MB Returning No Results Content
0.149831 / 8.1MB Low Search: Found low_search variables in no_results block, calling filters to parse
0.154623 / 8.1MB -> Data Returned
0.154724 / 8.1MB Detecting Tags in Template
0.154886 / 8.1MB Running Tags
0.155283 / 8.0MB Calling Tag: {exp:low_search:suggestions keywords="downtown" keywords:lang="en" limit="2"}
0.155659 / 8.0MB Low Search: Prepping if no_suggestions conditional
0.156645 / 8.1MB Low Search: No valid words to base suggesions on
0.156672 / 8.1MB Returning No Results Content
0.156725 / 8.1MB -> Data Returned
0.156763 / 8.1MB - End Tag Processing -
Low 2 Jan 2017 08:32
Looking at the debug data, the entry returned based on the Distance and Keywords filters, is entry ID 18. Low Search then passes on that data to the native Channel Entries tag, which applies the start_on parameter. So, logically, entry 18 does not fall into the "3 hours ago" limit.
Note that start_on="3 hours ago" and your custom date_filter="31 days ago". These are two different values. Perhaps you're getting the two mixed up.
Varen Swaab 3 Jan 2017 17:58
Hi Low, I'm still trying to figure this out based on the hints you gave me. I'm not getting the results I'm looking for yet but will continue trying. Thanks.