Skip to content

Commit

Permalink
Facets to use default filters same as search creteria
Browse files Browse the repository at this point in the history
  • Loading branch information
snyaggarwal committed Mar 1, 2021
1 parent 8489682 commit de9894a
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions core/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,38 +244,22 @@ def get_kwargs_filters(self):

def get_facets(self):
facets = dict()
is_source_child_document_model = self.is_source_child_document_model()

if self.should_include_facets() and self.facet_class:
faceted_filters = {to_camel_case(k): v for k, v in self.get_faceted_filters(True).items()}
filters = {
**self.default_filters, **self.get_facet_filters_from_kwargs(), **faceted_filters, 'retired': False
}
default_filters = self.default_filters.copy()
is_source_child_document_model = self.is_source_child_document_model()

if is_source_child_document_model and 'collection' not in self.kwargs and 'version' not in self.kwargs:
default_filters['is_latest_version'] = True

faceted_filters = {to_camel_case(k): v for k, v in self.get_faceted_filters(True).items()}
filters = {**default_filters, **self.get_facet_filters_from_kwargs(), **faceted_filters, 'retired': False}
if not self._should_exclude_retired_from_search_results() or not is_source_child_document_model:
filters.pop('retired')

searcher = self.facet_class( # pylint: disable=not-callable
facets = self.facet_class( # pylint: disable=not-callable
self.get_search_string(), filters=filters, exact_match=self.is_exact_match_on()
)
facets = searcher.execute().facets.to_dict()

if 'user' in self.kwargs or 'org' in self.kwargs:
facets.pop('owner', None)
facets.pop('ownerType', None)

if 'source' in self.kwargs:
facets.pop('source', None)

if 'collection' in self.kwargs:
facets.pop('collection', None)
elif is_source_child_document_model:
facets['collection_membership'] = facets.pop('collection', None)

if is_source_child_document_model:
facets.pop('concept', None)
facets.pop('conceptOwner', None)
facets.pop('conceptOwnerType', None)
facets.pop('conceptSource', None)
).execute().facets.to_dict()

return facets

Expand Down

0 comments on commit de9894a

Please sign in to comment.