Пример #1
0
    def get_facets(self):
        facets = dict()

        if self.should_include_facets() and self.facet_class:
            if self.is_user_document():
                return facets
            is_source_child_document_model = self.is_source_child_document_model(
            )
            default_filters = self.default_filters.copy()

            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')

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

        return facets
Пример #2
0
    def get_facets(self):
        facets = dict()
        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
            }

            if self.should_include_retired() or self.facet_class not in [
                    ConceptSearch, MappingSearch
            ]:
                filters.pop('retired')

            searcher = 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()

        return facets
Пример #3
0
    def get_facets(self):
        facets = dict()
        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
            }
            searcher = 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()

        return facets
Пример #4
0
    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
            }

            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
                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)

        return facets
Пример #5
0
 def test_to_camel_case(self):
     self.assertEqual(to_camel_case(""), "")
     self.assertEqual(to_camel_case("foobar"), "foobar")
     self.assertEqual(to_camel_case("foo_bar"), "fooBar")
     self.assertEqual(to_camel_case("fooBar"), "fooBar")