Modify global search query
I would like to tweak the generated SQL query for global search. In the below example, I'm querying the user_id, firstname, lastname and email fields.
I would like to do things like:
1. Not bother searching firstname, lastname or email fields if the search term is numeric.
2. Not bother searching user_id if the search term is not numeric.
3. Do an exact match search of user_id at all times (the system defaults to LIKE '%[term]%' for each field.
4. Search for CONCAT(firstname, ' ', lastname)
I imagine I could somehow obtain the search term and modify the query, maybe in getGlobalSearchEloquentQuery(), but how?
Thank you!
Solution:Jump to solution
You can overwrite the
public static function getGlobalSearchResults(string $search): Collection to have complete control over the results.2 Replies
Solution
You can overwrite the
public static function getGlobalSearchResults(string $search): Collection to have complete control over the results.Amazing, thank you @Dennis Koch !