how to set hook $param (low_search_pre_search)
Hello Programmers,
I want to limit my search result by the user data. That the outcome of the search is determined if the user is logged in or not or what for group the user belonged.
I created a module and an extension for it. I want hook the: low_search_pre_search. That If the user is logged in or not, that I change the status of the search. That if a user is logged in that the search result show all entries with status open and ingelogd.
I tried in a method to do this: $params['keywords-query:status'] = 'ingelogd OR status = open';
$params['keywords-query:status'] = 'ingelogd|open';
I even searched for an entry with no results: $params['keywords-query:status'] = '8332';
How can I change the result of the search with using a hook?
Thank you for your time.
Replies
Low 17 Jul 2018 13:54
The
keywords-query:column_name
keys only applies the actual SQL query generated for the keywords filter. Most likely, you can leave that alone.Instead, you want to set regular old parameters, so use
Thomas 17 Jul 2018 14:08
Thank you for you response.
But that dit not work either. The only change in status what I have is when i add status to the: exp:low_search:results. Do you have a idea why it wont work.
This is my param that I send:
[_params:Low_search_params:private] => Array
(
[result_page] => zoeken
[keywords] => Functioneren
[collection] => activities|ads|articles|columns|dentz|faq|news|newsletters|pages|themes|tools|uitspraken|documenten|links
[channel] => not zoo_visitor|students|dentists|werkgroepen|reacties|links|authors|verslagen|gebruikersgroepen
[limit] => 4
[paginate] => bottom
[search_mode] => all
[loose_ends] => both
[show_future_entries] => yes
[status] => open
)
Low 17 Jul 2018 14:11
If you have status defined in the Results tag, that will always overwrite any dynamic parameter you set. Remove it, or use
default:status="foo"
instead.Thomas 17 Jul 2018 14:27
That didn't work either. However, I now only get the result with only the status: open when I added default:status="foo". Are there result-tag-parameters overwriting the params which is sent from the hook?
Thomas 17 Jul 2018 15:02
This is the result-tag that I use for displaying the data:
{exp:low_search:results query='{segment_2}' collection="activities|ads|articles|columns|dentz|faq|news|newsletters|pages|themes|tools|uitspraken|documenten|links" channel="not|students|dentists|werkgroepen|reacties|links|authors|verslagen|gebruikersgroepen" limit='4' paginate='bottom' search_mode='all' loose_ends='both' show_future_entries='yes'}
I S here something that overwrite my sended $param or is it diferent problem
Low 17 Jul 2018 15:02
Okay, refreshing my own memory for a bit.
First, params are set from the query.
Then, params are combined with tag parameters (so hard-coded params take precedence).
Then, defaults are set when necessary.
Then the low_search_pre_search hook is called, and the parameters returned will overwrite the params collected thus far.
Then filters are fired.
Then the entry_id/fixed_order param is set based on filtered results.
Then the Channel Entries tag is called to parse the results (and handle native filters like status).
Any parameter you set in the hook, should be either picked up by LS filters, or the native channel:entries tag.
Check the template debugger for more details if (even with your custom extension) you get unexpected results, to see which params are indeed set.
Low 17 Jul 2018 15:04
Note that, for the status, EE's native behaviour is to default to 'open' only. So if it's not set, you'll get entries with status="open" only.
Low 17 Jul 2018 15:12
Also, the code of your method should be something like
So, you're getting an array, and you should return one.
Thomas 17 Jul 2018 20:06
Thanks for the response.
I think its a cache problem. I have to empty cache to see the difference between a user that is logged in and a user that is not. I think that the cache saves the search result. But i have to dubbel check that to be sure.
Thomas 18 Jul 2018 06:49
I checked its a cache problem. Is there a way to disable or clear the cache in the result of the search? I get the result of the first search in my second search.
Low 18 Jul 2018 11:34
LS doesn't do any caching, so if that's the issue, it falls outside the scope of LS.