Closed dircm closed 4 years ago
Unfortunately, I'm not sure that such functionality is possible, or if it is, my guess is that it would not be a trivial undertaking to implement and would likely lead to unforeseen edge cases.
The reason for this, is that whereFuzzy
doesn't just add a WHERE
statement to the SQL query, it also uses addSelect
, orderBy
and having
statements to enable relevance calculations:
return $builder
-> addSelect(static::pipeline($field, $native, $value))
-> orderBy('relevance_' . str_replace('.', '_', $field), 'desc')
-> having('relevance_' . str_replace('.', '_', $field), '>', 0);
That said, my inclination may be wrong, so I'm not against a PR adding it. If you feel it would be of use and would like to see it implemented, feel free to submit something :)
Thanks for replying ! I’ll have a dig-in 👍🏼
When searching across multiple columns, if the query would normally return a match with ONE whereFuzzy, that result is not returned if second column query returns null.
Would it be possible to built an OR function to return a better result set in that instance ?
I.e.
User::whereFuzzy('name', 'jd') ->orWhereFuzzy('email', 'gm') ->first();