From d41a15ab2aa9dad313cd4ca83b7f66612e966077 Mon Sep 17 00:00:00 2001 From: Bohdan Odintsov Date: Tue, 29 Apr 2025 15:24:32 +0300 Subject: [PATCH 1/3] add query syntax with `simple_query_string --- share/search/index_strategy/trovesearch_denorm.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/share/search/index_strategy/trovesearch_denorm.py b/share/search/index_strategy/trovesearch_denorm.py index 1d13bc33e..59ea81656 100644 --- a/share/search/index_strategy/trovesearch_denorm.py +++ b/share/search/index_strategy/trovesearch_denorm.py @@ -712,11 +712,13 @@ def _text_field_name(self, propertypath: Propertypath): ) def _exact_text_query(self, textsegment: SearchText) -> dict: - # TODO: textsegment.is_openended (prefix query) - return _any_query([ - {'match_phrase': {self._text_field_name(_path): {'query': textsegment.text}}} - for _path in textsegment.propertypath_set - ]) + return { + "simple_query_string": { + "query": textsegment.text, + "fields": [self._text_field_name(_path) for _path in textsegment.propertypath_set], + "default_operator": "AND" + } + } @dataclasses.dataclass From 2d3d565a316459ea1c9763a3f7273e3a76327a08 Mon Sep 17 00:00:00 2001 From: Bohdan Odintsov Date: Tue, 29 Apr 2025 16:41:04 +0300 Subject: [PATCH 2/3] simplified --- .../index_strategy/trovesearch_denorm.py | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/share/search/index_strategy/trovesearch_denorm.py b/share/search/index_strategy/trovesearch_denorm.py index 59ea81656..1e38e85c7 100644 --- a/share/search/index_strategy/trovesearch_denorm.py +++ b/share/search/index_strategy/trovesearch_denorm.py @@ -654,7 +654,16 @@ def iri_boolparts(self) -> Iterator[tuple[str, dict]]: def text_boolparts(self) -> Iterator[tuple[str, dict]]: # text-based queries for _text in self.searchtext: - yield 'must', self._exact_text_query(_text) + yield ( + 'must', + { + "simple_query_string": { + "query": _text.text, + "fields": [self._text_field_name(_path) for _path in _text.propertypath_set], + "default_operator": "AND" + } + } + ) def _presence_query(self, search_filter) -> dict: return _any_query([ @@ -711,16 +720,6 @@ def _text_field_name(self, propertypath: Propertypath): else f'{self.base_field}.text_by_propertypath.{_path_field_name(propertypath)}' ) - def _exact_text_query(self, textsegment: SearchText) -> dict: - return { - "simple_query_string": { - "query": textsegment.text, - "fields": [self._text_field_name(_path) for _path in textsegment.propertypath_set], - "default_operator": "AND" - } - } - - @dataclasses.dataclass class _CardsearchQueryBuilder: params: CardsearchParams From 78930ded288aaeb824aa440345e35a89114bc24d Mon Sep 17 00:00:00 2001 From: Bohdan Odintsov Date: Tue, 29 Apr 2025 16:45:51 +0300 Subject: [PATCH 3/3] fix flake8 --- share/search/index_strategy/trovesearch_denorm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/share/search/index_strategy/trovesearch_denorm.py b/share/search/index_strategy/trovesearch_denorm.py index 1e38e85c7..a65eb776f 100644 --- a/share/search/index_strategy/trovesearch_denorm.py +++ b/share/search/index_strategy/trovesearch_denorm.py @@ -720,6 +720,7 @@ def _text_field_name(self, propertypath: Propertypath): else f'{self.base_field}.text_by_propertypath.{_path_field_name(propertypath)}' ) + @dataclasses.dataclass class _CardsearchQueryBuilder: params: CardsearchParams