yabhq / laravel-scout-mysql-driver

Laravel Scout MySQL Driver
MIT License
522 stars 113 forks source link

Fallback not worked #122

Open coolycow opened 3 years ago

coolycow commented 3 years ago

Hi!

If I understand correctly, then Fallback will not work.

My config:

'mysql' => [
        'mode' => 'NATURAL_LANGUAGE',
        'model_directories' => [app_path() . '/Models'],
        'min_search_length' => 3,
        'min_fulltext_search_length' => 4,
        'min_fulltext_search_fallback' => 'LIKE_EXPANDED',
        'query_expansion' => false
    ]

I am trying to find a match on two characters and I am getting an empty result.

If I understood everything correctly, then the problem occurs because of this code: (src/Engines/MySQLEngine.php):

public function search(Builder $builder)
{
    $result = [];

    if ($this->shouldNotRun($builder)) {
        $result['results'] = Collection::make();
        $result['count'] = 0;

        return $result;
    }

...
}

protected function shouldNotRun($builder)
{
    return strlen($builder->query) < config('scout.mysql.min_search_length');
}

There is no check that the mode is used, in which the search should be switched to another mode if the number of characters is less than necessary.