Browse Source

Beefing up elastic

imwald
Nuša Pukšič 3 months ago
parent
commit
83853cbbc4
  1. 17
      config/packages/fos_elastica.yaml
  2. 11
      src/Twig/Components/SearchComponent.php

17
config/packages/fos_elastica.yaml

@ -9,6 +9,7 @@ fos_elastica:
# create the index by running php bin/console fos:elastica:populate # create the index by running php bin/console fos:elastica:populate
articles: articles:
index_name: '%env(ELASTICSEARCH_INDEX_NAME)%' index_name: '%env(ELASTICSEARCH_INDEX_NAME)%'
use_alias: true
settings: settings:
index: index:
# Increase refresh interval for better write performance # Increase refresh interval for better write performance
@ -23,6 +24,10 @@ fos_elastica:
# Optimize for search performance # Optimize for search performance
max_result_window: 10000 max_result_window: 10000
analysis: analysis:
normalizer:
topic_norm:
type: custom
filter: [ lowercase, asciifolding ] # case & accent insensitive
analyzer: analyzer:
custom_analyzer: custom_analyzer:
type: custom type: custom
@ -37,24 +42,30 @@ fos_elastica:
analyzer: custom_analyzer analyzer: custom_analyzer
# Add term_vector for faster phrase queries # Add term_vector for faster phrase queries
term_vector: with_positions_offsets term_vector: with_positions_offsets
copy_to: search_combined
content: content:
type: text type: text
analyzer: custom_analyzer analyzer: custom_analyzer
# Don't store norms for content to save space and improve speed # Don't store norms for content to save space and improve speed
norms: false norms: false
copy_to: search_combined
summary: summary:
type: text type: text
analyzer: custom_analyzer analyzer: custom_analyzer
term_vector: with_positions_offsets term_vector: with_positions_offsets
tags: copy_to: search_combined
type: keyword
slug: slug:
type: keyword type: keyword
# Enable doc_values for faster sorting/aggregations # Enable doc_values for faster sorting/aggregations
doc_values: true doc_values: true
pubkey: pubkey:
type: keyword type: keyword
topics: ~ topics:
type: keyword
normalizer: topic_norm
search_combined:
type: text
analyzer: standard
persistence: persistence:
driver: orm driver: orm
model: App\Entity\Article model: App\Entity\Article

11
src/Twig/Components/SearchComponent.php

@ -187,7 +187,7 @@ final class SearchComponent
// Add phrase match for exact matches (high boost) // Add phrase match for exact matches (high boost)
$phraseMatch = new Query\MatchPhrase(); $phraseMatch = new Query\MatchPhrase();
$phraseMatch->setField('title', [ $phraseMatch->setField('search_combined', [
'query' => $query, 'query' => $query,
'boost' => 10 'boost' => 10
]); ]);
@ -196,15 +196,8 @@ final class SearchComponent
// Main multi-match query with optimized settings // Main multi-match query with optimized settings
$multiMatch = new MultiMatch(); $multiMatch = new MultiMatch();
$multiMatch->setQuery($query); $multiMatch->setQuery($query);
$multiMatch->setFields([ $multiMatch->setFields(['search_combined']);
'title^5',
'summary^3',
'content^1.5',
'topics^2'
]);
$multiMatch->setType(MultiMatch::TYPE_BEST_FIELDS); // Faster than MOST_FIELDS
$multiMatch->setFuzziness('AUTO'); $multiMatch->setFuzziness('AUTO');
$multiMatch->setOperator(MultiMatch::OPERATOR_OR); // OR is faster and more forgiving
$boolQuery->addMust($multiMatch); $boolQuery->addMust($multiMatch);
// Exclude specific patterns // Exclude specific patterns

Loading…
Cancel
Save