From 958a75028ad0229b6a100ccc705d9ddcf31dd0a8 Mon Sep 17 00:00:00 2001 From: Mat Chapman Date: Tue, 15 Sep 2020 10:20:59 +0100 Subject: [PATCH 1/4] Add fuzziness search defaulted to AUTO --- config/laravel-search.php | 4 +++- src/Engines/ElasticSearchEngine.php | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/laravel-search.php b/config/laravel-search.php index 7c0928d..26818ea 100644 --- a/config/laravel-search.php +++ b/config/laravel-search.php @@ -13,10 +13,12 @@ ], + 'fuzziness' => env('SEARCH_FUZZINESS', 'AUTO'), + 'es' => [ 'user' => env('SEARCH_USER', ''), 'password' => env('SEARCH_PASSWORD'), 'schema' => env('SEARCH_HOST_SCHEMA'), 'port' => env('SEARCH_HOST_PORT'), ] -]; \ No newline at end of file +]; diff --git a/src/Engines/ElasticSearchEngine.php b/src/Engines/ElasticSearchEngine.php index d557451..6e8fae7 100644 --- a/src/Engines/ElasticSearchEngine.php +++ b/src/Engines/ElasticSearchEngine.php @@ -221,6 +221,7 @@ protected function performSearch(Builder $builder, array $filters = []) 'fields' => $builder->fields, 'type' => 'phrase', 'operator' => 'and', + 'fuzziness' => config('laravel-search.fuzziness'), ], ] ] @@ -284,6 +285,7 @@ public function searchAll(AllBuilder $builder) 'query' => $builder->query, 'type' => 'phrase', 'default_operator' => 'and', + 'fuzziness' => config('laravel-search.fuzziness'), ], ] ] @@ -376,4 +378,4 @@ public function deleteIndex($config) $this->client->indices()->delete($params); } } -} \ No newline at end of file +} From 881efd9450fbe07071af1d60be4bd7550b5f8d20 Mon Sep 17 00:00:00 2001 From: Mat Chapman Date: Tue, 15 Sep 2020 11:00:09 +0100 Subject: [PATCH 2/4] Add publishable config php artisan vendor:publish --tag=laravel-search-config --- src/SearchServiceProvider.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/SearchServiceProvider.php b/src/SearchServiceProvider.php index f3e08f5..be490aa 100644 --- a/src/SearchServiceProvider.php +++ b/src/SearchServiceProvider.php @@ -42,6 +42,16 @@ public function register() }); } + /** + * Bootstrap any application services. + * + * @return void + */ + public function boot() + { + $this->configurePublishing(); + } + /** * Get the services provided by the provider. * @@ -51,4 +61,20 @@ public function provides() { return ['search']; } + + /** + * Configure publishing for the package. + * + * @return void + */ + protected function configurePublishing() + { + if (!$this->app->runningInConsole()) { + return; + } + + $this->publishes([ + __DIR__ . '/../config/laravel-search.php' => config_path('laravel-search.php'), + ], 'laravel-search-config'); + } } From 2be76b21d433d80362230be7f3f9df351bd35e26 Mon Sep 17 00:00:00 2001 From: Mat Chapman Date: Wed, 16 Sep 2020 19:32:18 +0100 Subject: [PATCH 3/4] Disable phrase search type --- src/Engines/ElasticSearchEngine.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Engines/ElasticSearchEngine.php b/src/Engines/ElasticSearchEngine.php index 6e8fae7..74ec5b2 100644 --- a/src/Engines/ElasticSearchEngine.php +++ b/src/Engines/ElasticSearchEngine.php @@ -219,7 +219,6 @@ protected function performSearch(Builder $builder, array $filters = []) 'multi_match' => [ 'query' => $builder->query, 'fields' => $builder->fields, - 'type' => 'phrase', 'operator' => 'and', 'fuzziness' => config('laravel-search.fuzziness'), ], @@ -283,7 +282,6 @@ public function searchAll(AllBuilder $builder) 'query' => [ 'query_string' => [ 'query' => $builder->query, - 'type' => 'phrase', 'default_operator' => 'and', 'fuzziness' => config('laravel-search.fuzziness'), ], From cdadbed38688fef04fa46afe3181468939096d0d Mon Sep 17 00:00:00 2001 From: Mat Chapman Date: Wed, 16 Sep 2020 19:57:27 +0100 Subject: [PATCH 4/4] Can't seem to search using multi_match need query string --- src/Engines/ElasticSearchEngine.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Engines/ElasticSearchEngine.php b/src/Engines/ElasticSearchEngine.php index 74ec5b2..094490d 100644 --- a/src/Engines/ElasticSearchEngine.php +++ b/src/Engines/ElasticSearchEngine.php @@ -216,10 +216,10 @@ protected function performSearch(Builder $builder, array $filters = []) 'bool' => [ 'must' => [ [ - 'multi_match' => [ + 'query_string' => [ 'query' => $builder->query, 'fields' => $builder->fields, - 'operator' => 'and', + 'default_operator' => 'and', 'fuzziness' => config('laravel-search.fuzziness'), ], ]