Exact phrase for multiple words?
Hi Low,
Is it possible to use Low Search to search for exact phrases with multiple words, and without the user having to add quotes around the phrase? For example, I want to be able to search for Mickey Mouse, and only return results with the exact phrase "Mickey Mouse". If the user searches only for Mickey, or only for Mouse, they would get a no results found.
Here's my code:
{exp:low_search:form result_page="search" required="keywords" exact="title" }
<div class="input-group">
<input name="keywords:mode" value="exact" type="hidden">
<input type="search" name="keywords" class="form-control input-lg" placeholder="">
<span class="input-group-btn">
<button class="btn btn-default btn-lg" type="submit">Search</button>
</span>
</div><!-- /input-group -->
{/exp:low_search:form}
Thanks!
P.S. I find it very odd that GetSatisfaction doesn't provide better support code for blocks. :-/
Replies
Low 17 May 2015 09:10
You're already using keywords:mode="exact", so that would be the way to get exact phrase matching for the Keywords filter. But that means you will get search results back when searching just for "mickey" or "mouse", as that term exactly matches a sequence of words in the search index.
If you want to exactly match a certain field, you might want to consider using the Field Search filter, which can target a specific field, eg:
Or in Form syntax:
And yes, GetSat's support for code blocks is severely lacking. I've asked for better support. In the meantime, you can use http://pastie.org/ or http://pastebin.com/ for large chunks of code.
gtowle 17 May 2015 23:04
Low,
Thanks for the prompt reply. At first I couldn't get it working - I was trying to use the Title field as the search field, which didn't work. So I created a name field, and that worked. Thanks!
Geoff
Low 18 May 2015 07:00
search:title="foo" should work as well, but if a custom field works, that's fine.
gtowle 19 May 2015 00:01
Out of curiosity, this is the code I attempted to use with title but can't get it to work.
<input name="search:title" type="search" class="form-control input-lg" value="">
<input type="hidden" name="exact" value="search:title">
Low 19 May 2015 06:31
As long as you're on version 2.2.0 or up, that syntax should work.
If it doesn't, I'll need to take a look myself. Please send SuperAdmin login credentials to hi at gotolow dot com if you can.