From 56585fb1e01dc66c04a8277b9f55ae2bcbf56092 Mon Sep 17 00:00:00 2001 From: Cameron Lamb Date: Tue, 7 Nov 2023 11:04:17 +0000 Subject: [PATCH] DWPF-905 Fix explicit fields (#494) --- src/extended_search/managers/query_builder.py | 4 +++- src/extended_search/tests/test_querybuilder.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/extended_search/managers/query_builder.py b/src/extended_search/managers/query_builder.py index 1960a3510..73880b4ce 100644 --- a/src/extended_search/managers/query_builder.py +++ b/src/extended_search/managers/query_builder.py @@ -6,6 +6,7 @@ from wagtail.search.query import Boost, Fuzzy, Phrase, PlainText, SearchQuery from extended_search.backends.query import Nested, OnlyFields +from extended_search.managers import get_indexed_field_name from extended_search.settings import extended_search_settings as search_settings from extended_search.types import AnalysisType, SearchQueryType @@ -128,7 +129,8 @@ def _get_searchquery_for_query_field_querytype_analysistype( analysis_type, ) - return OnlyFields(Boost(query, boost), fields=[base_field_name]) + field_name = get_indexed_field_name(base_field_name, analysis_type) + return OnlyFields(Boost(query, boost), fields=[field_name]) @classmethod def _combine_queries(cls, q1: Optional[SearchQuery], q2: Optional[SearchQuery]): diff --git a/src/extended_search/tests/test_querybuilder.py b/src/extended_search/tests/test_querybuilder.py index aef009428..2ff9f6200 100644 --- a/src/extended_search/tests/test_querybuilder.py +++ b/src/extended_search/tests/test_querybuilder.py @@ -166,7 +166,7 @@ def test_get_searchquery_for_etc_uses_submethods(self, mocker): {}, ) assert isinstance(result, OnlyFields) - assert result.fields == ["title"] + assert result.fields == ["title_explicit"] subquery = result.subquery assert isinstance(subquery, Boost) assert subquery.boost == 333.33 @@ -376,7 +376,7 @@ def test_get_searchquery_for_etc_uses_submethods(self, mocker): {"parent_model_field": "foo"}, ) assert isinstance(result, OnlyFields) - assert result.fields == ["foo.title"] + assert result.fields == ["foo.title_explicit"] subquery = result.subquery assert isinstance(subquery, Boost) assert subquery.boost == 333.33