Limiting Search Results by EE Grid Column Data
I can search and display Grid rows, but the search results page is show ALL rows for that entry.
How can I limit the results and show only the Grid row(s) where the item exists per entry?
Search form:
{exp:low_search:form collection="members" search_mode="exact" search:item_name="yes" result_page="fashion_shop_search/results/" form_class="padding-left-3" secure="no"}
SEEK
{/exp:low_search:form}
Results:
{exp:low_search:results limit="10" query="{segment_3}" status="not closed" disable="member_data" search:item_name="yes"}
{if count == 1}
{if low_search_keywords}Searched for {low_search_keywords}.{/if}
Total results: {absolute_results}.
{/if}
{member_shop_name}
{member_featured_stock}
{member_featured_stock:item_name}
{member_featured_stock:price}
{/member_featured_stock}
{member_county}
View
{paginate}
Page {current_page} of {total_pages} pages {pagination_links}
{/paginate}
{if no_results}
Sorry, your query did not return any results.
Check your spelling or try a different search term.
{/if}
{/exp:low_search:results}
TIA.
Replies
Low 4 Dec 2013 16:24
Can you re-paste your code so it GetSat "gets it", too? You can use http://pastie.org/ or http://pastebin.com/ for large chunks of code.
Jeremy Timms 4 Dec 2013 16:30
Sorry - done:
http://pastie.org/8528549
Low 4 Dec 2013 16:31
Err, that code hasn't got any HTML input fields in the form either... Can you check?
Jeremy Timms 4 Dec 2013 16:34
Edited, sorry: http://pastie.org/8528556
Low 4 Dec 2013 16:37
For the record, what are your LS, EE and PHP versions?
Jeremy Timms 4 Dec 2013 16:40
Low Search 2.4.2
EE: v2.7.0
PHP Version 5.4.21
Low 4 Dec 2013 16:51
So, in your form, the element for keywords doesn't have a name="" parameter. I presume it should be the keywords, so add name="keywords" to it.
Secondly, I recommend that you upgrade to Low Search 3, which will help with what you're trying to accomplish. Be sure to read the upgrade notes.
Jeremy Timms 4 Dec 2013 17:06
Thank you Low.
I have now added the keywords value and upgraded to LS 3.
All rows are in the results are being returned still not the specific rows that only contain the exact phrase for an entry.
Low 4 Dec 2013 17:27
Low Search will only return the entries, so to filter the Grid, you need to use its search:column="" parameter. And if you're searching by keyword, that would be something like search:column_name="{low_search_keywords}".
Jeremy Timms 4 Dec 2013 17:31
EUREKA - thanks so much Low. It is now working. I could kiss you :)
Jeremy Timms 15 Jan 2014 22:30
Low - following on from this now that data is being shoved in...
In a Grid column I have a field called item_name which I targeting as per the threads and resolution we went for above. For some reason, some of the fields I want to display in the results are not being rendered, even though it seems the search is working, for example:
Item entry in the Grid row: shoes size 6 black
A search for: shoes size 6 - this renders the desired fields of:
member_featured_stock:item_name
member_featured_stock:item_image
member_featured_stock:price
member_shop_name
member_county
But a search for: shoes size 6 black - this only renders the fields:
member_shop_name
member_county
This is baffling me, I have tried changing the search mode/s and putting loose ends 'on'.
Any ideas?
Low 16 Jan 2014 08:34
Are you using search:column_name="{low_search_keywords}" on the Grid field? If so, then it can mean that filtering the Grid field by those keywords (which is handled natively, not by Low Search) are not found in the Grid column your targeting. The native search:column_name will filter use its value for a substring lookup, so the string "shoes size 6 black" should be present in the column. If it is not, no rows are returned, hiding the Grid field.
Jeremy Timms 16 Jan 2014 08:37
Yes I am using that method and the string IS present in the column as:
shoes size 6 black
This does not return all fields but:
shoes size 6 does.
Bizarre, as one would think it would be the other way round...
Low 16 Jan 2014 08:49
I probably wouldn't filter out the Grid field at all and just show all rows.
Another solution could be, but it's a bit of a nasty workaround, to use an embed for the search results, so you can change the keywords from "shoes size 6 black" to "shoes&&size&&6&&black" (see these docs).
For that, you'd need Low Replace (free):
And in the search/_results template, put your Results tag, using this in the Grid field:
Untested, but something like that might work better for you. If you want to filter the Grid field by any of the given terms (not all), then use a | rather than &&.
Jeremy Timms 16 Jan 2014 09:44
Unless I am doing something wrong (which is possible being at work for 20 hours), it's bringing everything back now in all rows/entries.
Process:
1. New template group: embeds > new template called 'the_keywords' > paste in sample code and change paths > embed="fashion_search/results"
2. Place embed into results template search:item_name="embed:embeds/the_keywords"
Test.
Low 16 Jan 2014 09:49
No. Wrong process. Try this:
1. New template embeds/_results: should contain only the low_search:results tag, including search:column_name="{embed:grid_keywords}" in the Grid field.
2. In the original search results template, replace the low_search:results tag with an embed tag, as laid out in my previous comment.
Jeremy Timms 16 Jan 2014 10:14
No results..
Quite happy for you to have CP login and have a look/pay for your time to tie this last piece of the puzzle up before I go nuts ;)
Low 16 Jan 2014 10:17
I'll take a look. Please send SuperAdmin login credentials to hi at gotolow dot com if you can.
Jeremy Timms 16 Jan 2014 10:21
Have done, thank you.
Low 16 Jan 2014 10:37
You had query="segment_3" instead of query="{segment_3}" in your Results tag. It works now.
Also left a comment in your search results template. Basically a gotcha:
Jeremy Timms 27 Jan 2014 08:55
As this is relevant and using the same code/method, I thought I would follow this up with an issue I have found.
One of these Grid rows is Price, numbers in a text input field, with the field content set as all.
The results are not bringing back ANYTHING, not even a results not found if searching using an example number that I know is present in a entries row. It's not a minimum word length issue either.
I actually do not want the user to search on price, so was hoping the no results would kick in. But this is not returned at all when numbers only are used as a search.
Any ideas?
Low 27 Jan 2014 09:00
So you're not getting an error message? Or a white screen? Just blank where the Results tag should be?
I'll need to see your current Form code. Also, enable template debugging and copy/paste its contents here.
Edit: Also, how are you searching? Using keywords only or targeting the Grid field specifically using the Field Search filter?
Jeremy Timms 27 Jan 2014 09:16
Just blank where the Results tag/no results should be.
Searching by the method above, using an embed on the keywords to then target the grid field using the field search filter.
Form code, search method and debugging: http://pastie.org/8671307
Low 27 Jan 2014 10:54
LS does return 1 result for that search (you can see the <ul> being generated in the results). However, the Grid filtering won't display the result. The opening Grid var pair is:
This searches the item_name column. If the keywords contain the price, it won't find a match, as the price is stored in a different column. So the entry is returned, but the Grid filter you have in place returns no matches.
Also, I'm afraid there isn't an option where you can do something like search:any_grid_column="foo", where it will search any of the grid columns.
Jeremy Timms 27 Jan 2014 12:32
Hi Low,
Shame we cannot tell the collection to not index certain columns in a Grid/Matrix field. I am just being anal I guess.
Thanks for your help.
Low 27 Jan 2014 12:34
Well, actually, you can. If you set the column as not searchable, it shouldn't be included in the index either, and therefore should not appear as a keyword search result.
Jeremy Timms 27 Jan 2014 12:37
I tried that via the Grid settings but it still comes back blank :(
Low 27 Jan 2014 12:46
Remember the difference between the actual Low Search keyword search, which brings back the entry; and the search:column_name="keywords" on the Grid field.
If you make the Grid column "not searchable", it means it will be excluded from the search index (both native and for LS), so keyword searches (again, both for native as for LS) will ignore content in that column. Also beware that if you change a column property like that, you'll most likely need to re-save entries. The index is not automatically updated (that's a Grid thing, not a LS thing).
Having the column set to "not searchable" has no effect on the search:column_name="" param on the Grid variable pair.
If you get the empty results like that, there *is* a result, but the filter on the Grid var pair hides the content.
Jeremy Timms 27 Jan 2014 12:55
100% got you now :)
Thank you again. Conditional time to filter out a blank result to present something to the user.