From 83853cbbc4ac2ba346d4344d7be881fefd8c767e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Fri, 10 Oct 2025 21:15:01 +0200 Subject: [PATCH] Beefing up elastic --- config/packages/fos_elastica.yaml | 19 +++++++++++++++---- src/Twig/Components/SearchComponent.php | 11 ++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/config/packages/fos_elastica.yaml b/config/packages/fos_elastica.yaml index 9a65728..7a395b6 100644 --- a/config/packages/fos_elastica.yaml +++ b/config/packages/fos_elastica.yaml @@ -9,7 +9,8 @@ fos_elastica: # create the index by running php bin/console fos:elastica:populate articles: index_name: '%env(ELASTICSEARCH_INDEX_NAME)%' - settings: + use_alias: true + settings: index: # Increase refresh interval for better write performance refresh_interval: "5s" @@ -23,6 +24,10 @@ fos_elastica: # Optimize for search performance max_result_window: 10000 analysis: + normalizer: + topic_norm: + type: custom + filter: [ lowercase, asciifolding ] # case & accent insensitive analyzer: custom_analyzer: type: custom @@ -37,24 +42,30 @@ fos_elastica: analyzer: custom_analyzer # Add term_vector for faster phrase queries term_vector: with_positions_offsets + copy_to: search_combined content: type: text analyzer: custom_analyzer # Don't store norms for content to save space and improve speed norms: false + copy_to: search_combined summary: type: text analyzer: custom_analyzer term_vector: with_positions_offsets - tags: - type: keyword + copy_to: search_combined slug: type: keyword # Enable doc_values for faster sorting/aggregations doc_values: true pubkey: type: keyword - topics: ~ + topics: + type: keyword + normalizer: topic_norm + search_combined: + type: text + analyzer: standard persistence: driver: orm model: App\Entity\Article diff --git a/src/Twig/Components/SearchComponent.php b/src/Twig/Components/SearchComponent.php index d8c5bba..29a9051 100644 --- a/src/Twig/Components/SearchComponent.php +++ b/src/Twig/Components/SearchComponent.php @@ -187,7 +187,7 @@ final class SearchComponent // Add phrase match for exact matches (high boost) $phraseMatch = new Query\MatchPhrase(); - $phraseMatch->setField('title', [ + $phraseMatch->setField('search_combined', [ 'query' => $query, 'boost' => 10 ]); @@ -196,15 +196,8 @@ final class SearchComponent // Main multi-match query with optimized settings $multiMatch = new MultiMatch(); $multiMatch->setQuery($query); - $multiMatch->setFields([ - 'title^5', - 'summary^3', - 'content^1.5', - 'topics^2' - ]); - $multiMatch->setType(MultiMatch::TYPE_BEST_FIELDS); // Faster than MOST_FIELDS + $multiMatch->setFields(['search_combined']); $multiMatch->setFuzziness('AUTO'); - $multiMatch->setOperator(MultiMatch::OPERATOR_OR); // OR is faster and more forgiving $boolQuery->addMust($multiMatch); // Exclude specific patterns