Skip to content

Commit

Permalink
Elasticsearch search
Browse files Browse the repository at this point in the history
  • Loading branch information
DevFabi committed Sep 17, 2020
1 parent 114bd68 commit f34abf3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 7 additions & 0 deletions config/elastic/index_book.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

11 changes: 6 additions & 5 deletions src/Controller/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/UseCases/GetAllApiBooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ class GetAllApiBooks
{

const KEYWORD = [
'roman',
'océan',
'animaux'
'Katherine Pancol',
'Michel Bussi',
'Valérie Perrin',
'Joël Dicker'
];

private $uploader;
Expand Down

0 comments on commit f34abf3

Please sign in to comment.