laravel-scout-tntsearch-driver: [question] Model::search($query)->get(); only returns 1 result.

Consider the following dataset:

  • record 1; loremipsum
  • record 2; loremdolor

Is there any way that searching for ‘lorem’ would only return record 2?

Options asYouType and fuzziness are both true.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Try with this config:

'tntsearch' => [
    'fuzziness' => env('TNTSEARCH_FUZZINESS', true),
    'fuzzy' => [
        'prefix_length' => 3,
        'max_expansions' => 50,
        'distance' => 10
    ],
    'asYouType' => false,
],

I’ll have a look on how to implement that. For now I’ll fall back to Algolia again, but I’d rather not send any data to a search provider like that. Having something like TNTSearch locally is the prefered solution.

Thanks for your help and timely responses! ^^

Hmm something strange is going on, for your usecase I guess the n-gram approach would be the best. Here’s a tutorial on how to do this http://tnt.studio/blog/did-you-mean-functionality-with-laravel-scout

I think the problem here is that it’s just returning one result. No matter what I do, I never get more then one result.

$companies = Company::search(request('query'))->get();

Nothing fancy here, just following the plain simple example from the docs to get started. Any clue to why I’m only getting one result back, while there are more records matching the query? Getting raw result also shows ‘1 hit’.

If that’s your real dataset then it’s not the best way of testing full text search I’m afraid. Full text search, unlike sql %like%, relies on other things like stemming words so could you please test with real data and use appropriate Stemmer while indexing.

If you have real data and this was just an example could you post a real example and we’ll take it from there 😃