Search for segment of product id within matrix column
I'm hoping to modify a basic keyword search we have now to also include searching through a specific matrix field (product id) using the loose_ends=both method. Currently we're using this:
{exp:low_search:form
result_page="search"
form_id="search-form"
}
Which is being output through this results tag:
{exp:low_search:results
query="{get_post:keywords}"
collection="products"
}
This works great, but the client recently asked if we could pull results on specific product id's. For example: if an id is PROD316111A they would like a search of 316 to pull up all products with that "root" 316 attribute. Therefore the results may include products with the id's of PROD316111A, PROD316111B, PROD316111C.
This seems like a good fit for a combination of loose_ends=both and the search:field_name:column_name options, but I'm not quite sure how to put this together.
Is this in fact possible?
Replies
Low 6 Mar 2014 09:26
First of all, using query="{get_post:keywords}" does nothing. If you're encoding queries, the query="" parameter should point to the encoded query in the URI. If you're not encoding queries (using GET variables), then the query="" param can be omitted, as it won't do anything.
Secondly, you're mixing up two different filters. The Keywords filter can use the loose_ends parameter, as it targets the keywords parameter. The search:field_name:column_name parameter is part of the Field Search filter, which comes with its own set of parameters. loose_ends does not target Field Search parameters. Instead, the Field Search filter works just like the native search:field_name params.
That means a parameter like search:field_name:column_name="316" will already be a substring search, just like it would be using the native search:field_name="316". In the same way, search:field_name:column_name="=316" would look for a column where the value is exactly 316, not a substring.
Make sense?
bryant 6 Mar 2014 19:25
Hey Low, I'm Chris' dev partner, just following up on his question.
What you said make sense, but I'm still not clear how exactly that would be applied. In the docs I can't tell if a search filter needs to be applied to the actual search form itself, or if it can be applied in the results tag.
If it can be applied in the results tag, would this be the syntax?
{exp:low_search:results
collection="products"
search:product_dynamic_fields:part_number="{get_post:keywords}"}
Low 7 Mar 2014 07:53
Filters can always be applied either in the form or in the results tag.
In a form, you can use something like this:
If you want to use the same search terms for both Keywords and the Field Search filter, you can use JavaScript to copy over the value from one field to the other, before submitting the form.
By the way, I see you're using {get_post:keywords}, which means (I assume) you're not encoding queries on the front-end, but using GET variables instead. Low Search will automatically read that and filter entries accordingly, so you don't need to explicitly define them in the Results tag.
Chris 7 Mar 2014 16:27
Thanks for your help, Low!