Skip to content

Commit

Permalink
improve DOI support in Publication search (#1437)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarosenb committed Sep 12, 2024
1 parent b54d068 commit be4a489
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export const PublishedListing: React.FC = () => {
type="error"
description={
<span>
An unexpected error occurred while retrieving publications."
An unexpected error occurred while retrieving publications.
</span>
}
/>
Expand Down
12 changes: 10 additions & 2 deletions designsafe/apps/api/publications_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,12 @@ def handle_search(query_opts: dict, offset=0, limit=100):
if search_string := query_opts["q"]:
qs_query = Q(
"query_string",
query=search_string,
# Elasticsearch can't parse query strings with unescaped slashes
query=search_string.replace("/", "\\/"),
default_operator="AND",
type="cross_fields",
fields=[
"nodes.value.dois",
"nodes.value.description",
"nodes.value.keywords",
"nodes.value.title",
Expand All @@ -128,7 +130,13 @@ def handle_search(query_opts: dict, offset=0, limit=100):
"nodes.value.authors.inst",
],
)
term_query = Q({"term": {"nodes.value.projectId.keyword": search_string}})
term_query = Q(
{
"term": {
"nodes.value.projectId.keyword": search_string.replace("/", "\\/")
}
}
)
query = query.filter(qs_query | term_query)

hits = (
Expand Down

0 comments on commit be4a489

Please sign in to comment.