Код: Выделить всё
private function phraseQuery(array $matchFields): array {
return [
'bool' => [
"minimum_should_match" => 1,
"should" => [
$this->multiMatch($matchFields),
[
'match' => [
'Title' => [
'query' => $this->searchTerm,
'fuzziness' => 'AUTO:4,8'
]
]
], [
'match' => [
'TransliteratedTitle' => [
'query' => $this->searchTerm,
'fuzziness' => 'AUTO:4,8'
]
]
]
]
]
];
}
Код: Выделить всё
private function fuss(array $matchFields): array {
$fuzziness = [];
foreach($matchFields as $field) {
$query = ['query' => $this->searchTerm , 'fuzziness' => 'AUTO:4,8'];
$match = [ $field => $query ];
$fuzziness[] = [ 'match' => $match ];
}
return $fuzziness;
}
private function phraseQuery(array $matchFields): array {
return [
'bool' => [
"minimum_should_match" => 1,
"should" => [
$this->multiMatch($matchFields),
...$this->fuss($matchFields),
]
]
];
}
К вашему сведению: я использую Elastic Cloud и PHP v8
Я протестировал свой код на площадке PHP, чтобы убедиться, что запросы к Elasticsearch структурированы одинаково. Я запустил обе формы запроса, и одна вернула 4 результата, а другая — почти 1500.
Подробнее здесь: https://stackoverflow.com/questions/787 ... erent-resu
Мобильная версия