Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make type of query_string query configurable #2370

Merged
merged 1 commit into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/search/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _get_query(self, req):

def _enhance_query_string(self, query_string):
query_string.setdefault("analyze_wildcard", app.config["ELASTIC_QUERY_STRING_ANALYZE_WILDCARD"])
query_string.setdefault("type", app.config["ELASTIC_QUERY_STRING_TYPE"])

def _get_projected_fields(self, req):
"""Get elastic projected fields."""
Expand Down
42 changes: 42 additions & 0 deletions features/search.feature
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,45 @@ Feature: Search Feature
]
}
"""

@auth
Scenario: Search by multiple words each matching in different field
Given "desks"
"""
[{"name": "Sports Desk", "content_expiry": 60}]
"""
Given "archive"
"""
[
{
"guid": "1",
"state": "in_progress",
"task": {"desk": "#desks._id#"},
"headline": "headline",
"body_html": "body"
},
{
"guid": "2",
"state": "in_progress",
"task": {"desk": "#desks._id#"},
"headline": "something completely different",
"body_html": "body"
},
{
"guid": "3",
"state": "in_progress",
"task": {"desk": "#desks._id#"},
"headline": "headline",
"body_html": "something completely different"
}
]
"""
When we get "/search?source={"query": {"filtered": {"query": {"query_string": {"query": "headline body", "lenient": true, "default_operator": "AND"}}}}}"
Then we get list with 1 items
"""
{
"_items": [
{"guid": "1"}
]
}
"""
6 changes: 6 additions & 0 deletions superdesk/default_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def local_to_utc_hour(hour):
#: https://discuss.elastic.co/t/configuring-the-standard-tokenizer/8691/5
ELASTIC_QUERY_STRING_ANALYZE_WILDCARD = False

#: allow to change type of query string query
#:
#: .. versionadded:: 2.5
#:
ELASTIC_QUERY_STRING_TYPE = "cross_fields"

#: max api items to get with single query
#:
#: .. versionchanged:: 2.4.1
Expand Down
1 change: 1 addition & 0 deletions superdesk/metadata/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def _set_highlight_query(source):
query_string = source.get("query", {}).get("filtered", {}).get("query", {}).get("query_string")
if query_string:
query_string.setdefault("analyze_wildcard", app.config["ELASTIC_QUERY_STRING_ANALYZE_WILDCARD"])
query_string.setdefault("type", app.config["ELASTIC_QUERY_STRING_TYPE"])
highlight_query = get_elastic_highlight_query(query_string)
if highlight_query:
source["highlight"] = highlight_query
Expand Down