Skip to content

Commit

Permalink
Do not display search results due to exceptional circumstances (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
de-code authored Nov 7, 2024
1 parent 09de9a1 commit 0f6ae19
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
7 changes: 6 additions & 1 deletion sciety_labs/app/routers/api/papers/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
OpenSearchSearchResultDict
)
from sciety_labs.providers.opensearch.utils import (
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
OPENSEARCH_FIELDS_BY_REQUESTED_FIELD,
OpenSearchFilterParameters,
OpenSearchPaginationParameters,
Expand Down Expand Up @@ -68,6 +69,7 @@ def get_classification_list_opensearch_query_dict(
filter_parameters: OpenSearchFilterParameters
) -> dict:
filter_dicts: List[dict] = [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT
]
filter_dicts.extend(get_opensearch_filter_dicts_for_filter_parameters(
Expand Down Expand Up @@ -118,10 +120,13 @@ def get_paper_search_by_category_opensearch_query_dict(
pagination_parameters: OpenSearchPaginationParameters,
query: Optional[str] = None
) -> dict:
filter_dicts: List[dict] = []
filter_dicts: List[dict] = [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT
]
filter_dicts.extend(get_opensearch_filter_dicts_for_filter_parameters(
filter_parameters=filter_parameters
))
LOGGER.info('filter_dicts: %r', filter_dicts)
query_dict: dict = {
'query': {
'bool': {
Expand Down
13 changes: 13 additions & 0 deletions sciety_labs/providers/opensearch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,16 @@ def get_default_filter_parameters(article_doi: str) -> ArticleRecommendationFilt
'doi': KnownDoiPrefix.BIORXIV_MEDRXIV
}
}


IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT = {
'bool': {
'must_not': {
"ids": {
"values": [
"10.31235/osf.io/rzjc9"
]
}
}
}
}
7 changes: 6 additions & 1 deletion tests/unit_tests/app/routers/api/papers/providers_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from sciety_labs.providers.opensearch.typing import OpenSearchSearchResultDict
from sciety_labs.providers.opensearch.utils import (
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT,
IS_EVALUATED_OPENSEARCH_FILTER_DICT,
OpenSearchFilterParameters,
Expand Down Expand Up @@ -76,6 +77,7 @@ def test_should_include_biorxiv_medrxiv_filter(self):
filter_parameters=OpenSearchFilterParameters(evaluated_only=False)
)
assert query_dict['query']['bool']['filter'] == [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT
]

Expand All @@ -84,6 +86,7 @@ def test_should_include_evaluated_only_filter(self):
filter_parameters=OpenSearchFilterParameters(evaluated_only=True)
)
assert query_dict['query']['bool']['filter'] == [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT,
IS_EVALUATED_OPENSEARCH_FILTER_DICT
]
Expand Down Expand Up @@ -116,6 +119,7 @@ def test_should_include_category_filter(self):
assert query_dict['query'] == {
'bool': {
'filter': [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT,
get_category_as_crossref_group_title_opensearch_filter_dict('Category 1')
]
Expand All @@ -132,6 +136,7 @@ def test_should_include_category_and_has_evaluations_filter(self):
pagination_parameters=OpenSearchPaginationParameters()
)
assert query_dict['query']['bool']['filter'] == [
IS_ARTICLE_DOI_TO_BE_DISPLAYED_OPENSEARCH_FILTER_DICT,
IS_BIORXIV_MEDRXIV_DOI_PREFIX_OPENSEARCH_FILTER_DICT,
get_category_as_crossref_group_title_opensearch_filter_dict('Category 1'),
IS_EVALUATED_OPENSEARCH_FILTER_DICT
Expand All @@ -146,7 +151,7 @@ def test_should_include_from_publication_date_filter(self):
sort_parameters=OpenSearchSortParameters(),
pagination_parameters=OpenSearchPaginationParameters()
)
assert query_dict['query']['bool']['filter'] == [
assert query_dict['query']['bool']['filter'][-1:] == [
get_from_publication_date_query_filter(from_publication_date)
]

Expand Down

0 comments on commit 0f6ae19

Please sign in to comment.