laravel-scout-tntsearch-driver
laravel-scout-tntsearch-driver copied to clipboard
Fuzzy Search - Last part of string
Hi there
First of all - great package! Really appreciate all the work that has gone into this.
I have a problem, where I cannot search for the last part of a string. Consider these (real examples):
User table:
name | e-mail
Oliver Jensen | [email protected]
Andranik Jaheo | [email protected]
When I search for strings like Oli, Oliv, Jensen it works. I get the first result.
However, when I search for example busk or badalyan - which are both part of the e-mail - I do not get any results.
- [X] Laravel 5.6
This is my config:
'tntsearch' => [
'storage' => storage_path(), //place where the index files will be stored
'fuzziness' => env('TNTSEARCH_FUZZINESS', true),
'fuzzy' => [
'prefix_length' => 2,
'max_expansions' => 50,
'distance' => 20
],
'asYouType' => false,
'searchBoolean' => env('TNTSEARCH_BOOLEAN', false),
],
I think you need to add ngrams to search in parts of words.
You need something like this in the toSearchableArray() method:
$array['ngrams'] = utf8_encode((new TNTIndexer)->buildTrigrams($this->email));
I read myself about this in a tutorial - I think this one: https://github.com/teamtnt/tutorials/blob/master/Did%20you%20mean%20functionality%20with%20Laravel%20Scout.md