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: @@ -9,6 +9,7 @@ fos_elastica:
# create the index by running php bin/console fos:elastica:populate
articles:
index_name: '%env(ELASTICSEARCH_INDEX_NAME)%'
use_alias: true
settings:
index:
# Increase refresh interval for better write performance
@ -23,6 +24,10 @@ fos_elastica: @@ -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: @@ -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

11
src/Twig/Components/SearchComponent.php

@ -187,7 +187,7 @@ final class SearchComponent @@ -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 @@ -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

Loading…
Cancel
Save