From f34abf39ee4514ec25e1e9e4e91c035c4046a862 Mon Sep 17 00:00:00 2001 From: Fabiola BELET Date: Thu, 17 Sep 2020 09:11:23 +0200 Subject: [PATCH] Elasticsearch search --- config/elastic/index_book.yaml | 7 +++++++ src/Controller/BookController.php | 11 ++++++----- src/UseCases/GetAllApiBooks.php | 7 ++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/config/elastic/index_book.yaml b/config/elastic/index_book.yaml index d9629a5..cea9aa3 100644 --- a/config/elastic/index_book.yaml +++ b/config/elastic/index_book.yaml @@ -3,11 +3,18 @@ settings: # single node, no sharding number_of_shards: 1 number_of_replicas: 0 + analysis: + analyzer: + my_analyzer: + tokenizer: "keyword" + filter: ["word_delimiter_graph"] mappings: dynamic: false # disable dynamic mapping properties: title: type: text + analyzer: my_analyzer author: type: text + analyzer: my_analyzer \ No newline at end of file diff --git a/src/Controller/BookController.php b/src/Controller/BookController.php index caf7858..6e7dd84 100644 --- a/src/Controller/BookController.php +++ b/src/Controller/BookController.php @@ -90,15 +90,15 @@ public function searchBooks(Request $request, Client $client): Response $match = new Match(); $match->setFieldQuery('author', $author->getName()); - $match->setFieldFuzziness('author', 'AUTO') - ->setFieldMinimumShouldMatch('author', '80%'); + $match->setFieldFuzziness('author', '2') + ->setFieldMinimumShouldMatch('author', '100%'); $bool = new BoolQuery(); - $bool->addShould($match); + $bool->addMust($match); $elasticaQuery = new Query($bool); - $foundBooks = $client->getIndex('book')->search($elasticaQuery); + $books = []; foreach ($foundBooks as $book) { @@ -128,7 +128,8 @@ public function searchBooksBis(Request $request,Client $client): Response $match = new Query\MultiMatch(); $match->setFields(['title','author'])->setQuery($result['text']); - $match->setFuzziness('AUTO'); + $match->setFuzziness('2'); + $match->setMinimumShouldMatch('100%'); $bool = new BoolQuery(); $bool->addShould($match); diff --git a/src/UseCases/GetAllApiBooks.php b/src/UseCases/GetAllApiBooks.php index f4a5dbb..189e29b 100644 --- a/src/UseCases/GetAllApiBooks.php +++ b/src/UseCases/GetAllApiBooks.php @@ -13,9 +13,10 @@ class GetAllApiBooks { const KEYWORD = [ - 'roman', - 'océan', - 'animaux' + 'Katherine Pancol', + 'Michel Bussi', + 'Valérie Perrin', + 'Joël Dicker' ]; private $uploader;