I want to search for an exact phrase from the "customers" table
Hi all,
I want to search for an exact phrase, for example "John Doe" from the "customers" table
However, the default query is
I want the query to have: where name like '%John Doe%'
The problem is in this method
extractTableSearchWords()
5 Replies
you can customize the query like this https://filamentphp.com/docs/3.x/tables/columns/getting-started#searching
It doesn't work as I expected, it's the same as before
I was looking at this earlier, and I noticed the same thing in that
extractTableSearchWords()
doesn't allow for quotes. So putting in "firstname lastname" for example will have it return an array of two values "firstname
and lastname"
. I think this could be quickly resolved by changing the line of code in the extractTableSearchWords()
method from
to:
I was planning on starting a discussion and making a merge request but I'm still checking out the library and haven't committed to it yet.
*Note: I didn't test any of this, so if you are going to do a merge request, I expect it will require testing.
Forgot to include your name in the reply so perhaps you didn't see my response above. Just wanted to make sure you got it.The only thing I can think of that you might need to be careful of is that str_getcsv() will return an array with a null entry, where explode() with return an array with an empty string, if passed an empty string. But I think everywhere extractTableSearchWords() is called, the code tests that $search is filled before calling it, so should be OK.
So as far as I can tell, that should be a safe change, and a worthwhile thing to PR.
Got some time to put this together and created the PR. I wrapped it so the
[null]
will not happen so it should have no compatibility issues from what I've seen and tested. https://github.com/filamentphp/filament/pull/9291GitHub
feature: Allow table searches to include phrases when wrapped in do...
When searching in tables the search previously broke each word separately on spaces between them. However sometimes that generates an unexpected large number of results, especially when search is e...