exp:low_search:keywords with a mixed keyword / range form
I have a form like this:
{exp:low_search:form
result_page="store/search"
}
<label>Enter your keywords</label>
<input type="search" name="keywords">
<select name="category[]" id="appearance">
<option value="">Styles</option>
</select>
<select name="range:product_price" id="prices">
<option value="">Price</option>
<option value=";49">Less than $50</option>
<option value="50;99">$50-$99</option>
<option value="100;149">$100-$149</option>
<option value="150;199">$150-$199</option>
<option value="200;249">$200-$249</option>
<option value="250;300">$250-$300</option>
<option value="301;">More than $300</option>
</select>
<button type="submit">Search</button>
{/exp:low_search:form}
and on the results page I have
{exp:low_search:keywords query="{segment_3}"}
When I enter a term in the keyword field, the result is what I want. But when I choose an option from the prices select, I get the title of every match output. So ideally, I'd rather have nothing at all or possibly the option range that was chosen. Is that possible using a single form / results template?
Also, in my testing of the price ranges search so far, I'm getting results that fall outside the range I'm searching. I've converted the field value to be a number instead of text already. Is there anything else I should be looking for?
Replies
Low 13 Mar 2017 11:48
What type of field is product_price?
Can you turn on template debugging and look up all the lines that mention Low Search -- what does that say?
John Faulds 14 Mar 2017 02:20
product_price is a text field with it's type set to number.
Debugging has:
(0.189966 / 14.49MB) Low Search: Prepping if low_search_no_results conditional
(0.193346 / 14.86MB) Low Search: Applying Low_search_filter_ranges
(0.201549 / 15.01MB) Low Search: Applying Low_search_filter_keywords
(0.201612 / 15.01MB) Low Search: No keyword search
(0.202234 / 14.97MB) Low Search: Setting entry_id param
(0.202290 / 14.98MB) Low Search: Parameters set: query="eyJyZXN1bHRfcGFnZSI6InN0b3JlXC9zZWFyY2giLCJyYW5nZTpwcm9kdWN0X3ByaWNlIjoiNTA7OTkifQ" channel="X|Y|Z" require_all="category" limit="24" paginate="bottom" orderby="title" sort="asc" result_page="store/search" range:product_price="50;99" entry_id="lots of IDs!"
(0.202293 / 14.97MB) Low Search: Pre-applying search vars to tagdata
(0.204112 / 14.99MB) Low Search: Calling the channel module
Low 14 Mar 2017 12:44
So it's looking like the ranges filter does indeed fire and offer results. And you're saying these results are off?
Can you look up the queries that are generated by LS and copy/paste them here?
John Faulds 15 Mar 2017 00:47
Actually, results are coming out fine now but where I have
exp:low_search:keywords
I get:You searched for: Title of every entry returned by the search... There are XXX products.
Low 15 Mar 2017 08:22
If you put this in your Results tag, wouldn't that work?
John Faulds 15 Mar 2017 11:01
Actually, I haven't been looking at my own code closely enough.
I'm already wrapping it in a count conditional but I've also got another conditional within that that says if {low_search_keywords} is empty, then output a category name, because all the other fields in my form are category inputs.
Up to now I'd only had one other field which wasn't for categories, so it must've contained keywords. Now I have the price field as well.
So is there any way in the results template to tell whether the input came from a particular field in the search form?
Low 15 Mar 2017 20:56
As per this principle, you can use any parameter in the form as a variable in your Results tag.
This means you can use {if low_search_range:product_price} as well. That should give you enough info to find out which fields were filled out and which weren't.
John Faulds 16 Mar 2017 00:14
Ah awesome, that's what I was after!