Skip to content

Commit

Permalink
Changed "exact match boost" implementation to use a match_phrase quer…
Browse files Browse the repository at this point in the history
…y in should (#4978)

* Add utori to the "Made with Openverse" page

dd Sutori to the "Made with Openverse" page.

* Add Sutori to the "Made with Openverse" page.

* Add Sutori to Made with Openverse page (#4972)

Fixed commit message to be more precise and include the issue number

* Add Sutori to Made with Openverse page (#4972)

Fixed commit message to be more precise and include the issue number

* Add Sutori to Made with Openverse page (#4972)

* Add Sutori to Made with Openverse page (#4972)

* @dryruffiaAdd Sutori to Made with Openverse page (#4972)

I added the suggestion from @sarayourfriend.

Co-authored-by: sarayourfriend <[email protected]>

* Add Sutori to Made with Openverse page (#4971)

* Change "exact match boost" implementation to use a match_phrase query in should #4960

I have added support for "match_pharse"
and also removed variable quotes_stripped it's not needed now.

* Changed exact match boost implementation to use a match_phrase query in should #4960

I have added support for "match_pharse"
and also removed variable quotes_stripped it's not needed now.

* I have added support for match_pharse
and also removed variable quotes_stripped it's not needed now.

* Added Test to acoomodate match_pharses

* Added Test to acoomodate match_pharses

* Added Test to accommodate march_phrases

---------

Co-authored-by: sarayourfriend <[email protected]>
  • Loading branch information
dryruffian and sarayourfriend committed Sep 23, 2024
1 parent 8c412c6 commit 7a0e4eb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
9 changes: 1 addition & 8 deletions api/api/controllers/search_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,7 @@ def build_search_query(

search_queries["must"].append(Q("simple_query_string", **base_query_kwargs))
# Boost exact matches on the title
quotes_stripped = query.replace('"', "")
exact_match_boost = Q(
"simple_query_string",
flags=DEFAULT_SQS_FLAGS,
fields=["title"],
query=f"{quotes_stripped}",
boost=10000,
)
exact_match_boost = Q("match_phrase", title={"query": query, "boost": 10000})
search_queries["should"].append(exact_match_boost)
else:
for field, field_name in [
Expand Down
30 changes: 15 additions & 15 deletions api/test/unit/controllers/test_search_controller_search_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def test_create_search_query_q_search_no_filters(media_type_config, anon_request
],
"should": [
{
"simple_query_string": {
"boost": 10000,
"fields": ["title"],
"query": "cat",
"flags": DEFAULT_SQS_FLAGS,
"match_phrase": {
"title": {
"query": "cat",
"boost": 10000,
}
}
},
{"rank_feature": {"boost": 10000, "field": "standardized_popularity"}},
Expand Down Expand Up @@ -129,11 +129,11 @@ def test_create_search_query_q_search_with_quotes_adds_raw_suffix(
],
"should": [
{
"simple_query_string": {
"boost": 10000,
"fields": ["title"],
"query": "The cutest cat",
"flags": DEFAULT_SQS_FLAGS,
"match_phrase": {
"title": {
"query": '"The cutest cat"',
"boost": 10000,
}
}
},
{"rank_feature": {"boost": 10000, "field": "standardized_popularity"}},
Expand Down Expand Up @@ -185,11 +185,11 @@ def test_create_search_query_q_search_with_filters(
],
"should": [
{
"simple_query_string": {
"boost": 10000,
"fields": ["title"],
"query": "cat",
"flags": DEFAULT_SQS_FLAGS,
"match_phrase": {
"title": {
"query": "cat",
"boost": 10000,
}
}
},
{"rank_feature": {"boost": 10000, "field": "standardized_popularity"}},
Expand Down

0 comments on commit 7a0e4eb

Please sign in to comment.