Skip to content

Commit

Permalink
Merge pull request #301 from ral-facilities/feature/search-api-includ…
Browse files Browse the repository at this point in the history
…e-filter-#261

Implement Include Filter for Search API
  • Loading branch information
MRichards99 authored Jan 31, 2022
2 parents 58e5f20 + e0b2d95 commit 10d1ca8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 17 deletions.
2 changes: 1 addition & 1 deletion datagateway_api/src/search_api/panosc_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_icat_mapping(self, panosc_entity_name, field_name):
)

try:
icat_mapping = mappings.mappings[panosc_entity_name][field_name]
icat_mapping = self.mappings[panosc_entity_name][field_name]
log.debug("ICAT mapping/translation found: %s", icat_mapping)
except KeyError as e:
raise FilterError(f"Bad PaNOSC to ICAT mapping: {e.args}")
Expand Down
10 changes: 4 additions & 6 deletions datagateway_api/src/search_api/query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,13 @@ def get_include_filter(include_filter_input, entity_name):
scope_query_filter, included_entity,
)
if isinstance(scope_query_filter, SearchAPIIncludeFilter):
for included_entity_pointer in range(
len(scope_query_filter.included_filters),
for i, included_filter in enumerate(
scope_query_filter.included_filters,
):
nested_include = True
included_filter = scope_query_filter.included_filters[
included_entity_pointer
]
scope_query_filter.panosc_entity_name = entity_name
scope_query_filter.included_filters[
included_entity_pointer
i
] = f"{included_entity}.{included_filter}"

query_filters.extend(scope_query_filters)
Expand Down
10 changes: 0 additions & 10 deletions test/search_api/filters/test_search_api_include_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,6 @@ def test_valid_apply_filter_single(self):
" iu.user",
id="Document.members.person",
),
# TODO - Below test fails because dataset/investigation parameters issue on
# mapping
pytest.param(
SearchAPIIncludeFilter(["dataset.parameters.document"], "File"),
"File",
"SELECT o FROM Datafile o INCLUDE o.dataset AS d, d.parameters AS p,"
" p.investigation",
id="File.dataset.parameters.document",
marks=pytest.mark.skip,
),
pytest.param(
SearchAPIIncludeFilter(["dataset.samples.datasets"], "File"),
"File",
Expand Down
1 change: 1 addition & 0 deletions test/search_api/test_search_api_query_filter_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,7 @@ def test_valid_include_filter_with_where_filter_in_scope(
assert len(filters) == expected_length
for test_filter in filters:
if isinstance(test_filter, SearchAPIIncludeFilter):
assert test_filter.panosc_entity_name == test_entity_name
for expected_include in expected_included_entities:
assert test_filter.included_filters == expected_include
expected_included_entities.remove(expected_include)
Expand Down

0 comments on commit 10d1ca8

Please sign in to comment.