From f817da0d9f7cdb4fd84fb3d9bbe4ebde100aa0b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Marie=CC=81thoz?= Date: Mon, 19 Feb 2024 14:45:19 +0100 Subject: [PATCH] documents: fix boosting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Adds boostring support for field with fields sub properties. Co-Authored-by: Johnny MarieĢthoz --- pyproject.toml | 1 - sonar/modules/documents/receivers.py | 7 +++++++ tests/api/test_api_query.py | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 410f23ed..f9f80b33 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -243,7 +243,6 @@ stats = "sonar.modules.stats.admin:stats_adminview" [tool.poetry.plugins."babel.extractors"] json = "sonar.modules.babel_extractors:extract_json" - [tool.poetry.group.dev.dependencies] requests-mock = "^1.11.0" diff --git a/sonar/modules/documents/receivers.py b/sonar/modules/documents/receivers.py index f25111da..58c71828 100644 --- a/sonar/modules/documents/receivers.py +++ b/sonar/modules/documents/receivers.py @@ -176,6 +176,13 @@ def process_boosting(config): fields = [] for prop, conf in mapping['mappings']['properties'].items(): field = prop + # fields for multiple mapping configurations + if conf.get('fields'): + tmp_fields = [field, f'{field}.*'] + for tmp_f in tmp_fields: + if tmp_f not in existing_fields: + fields.append(tmp_f) + continue # add .* for field with children if conf.get('properties'): field = f'{field}.*' diff --git a/tests/api/test_api_query.py b/tests/api/test_api_query.py index e4f1a2a0..c7db7a85 100644 --- a/tests/api/test_api_query.py +++ b/tests/api/test_api_query.py @@ -35,6 +35,8 @@ def test_boosting_fields(app): assert process_boosting(['title.*']) == ['title.*'] assert 'title.*' in process_boosting(['*']) assert 'title.*^2' in process_boosting(['title.*^2', '*']) + assert 'customField1' in process_boosting(['*']) + assert 'customField1.*' in process_boosting(['*']) def test_api_query(client, document_with_file, document_json, make_document, superuser):