Skip to content

Commit

Permalink
documents: fix boosting
Browse files Browse the repository at this point in the history
* Adds boostring support for field with fields sub properties.

Co-Authored-by: Johnny Mariéthoz <Johnny.Mariethoz@rero.ch>
  • Loading branch information
jma committed Mar 5, 2024
1 parent 55199d0 commit f817da0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion pyproject.toml
Expand Up @@ -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"

Expand Down
7 changes: 7 additions & 0 deletions sonar/modules/documents/receivers.py
Expand Up @@ -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}.*'
Expand Down
2 changes: 2 additions & 0 deletions tests/api/test_api_query.py
Expand Up @@ -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):
Expand Down

0 comments on commit f817da0

Please sign in to comment.