Return the queryset used for generating facets, before any facets
        are applied
423945
def pre_facet_sqs(self):
        
        sqs = SearchQuerySet()

        if self.query:
            sqs = sqs.filter(
                SQ(content=AutoQuery(self.query)) |  # Search `text` document
                SQ(get_title=AutoQuery(self.query)) | # boosted field
                SQ(boosted_search_terms=AutoQuery(self.query)) # boosted field
            )

        return sqs
1088743
def apply_filters(self, queryset, applicable_filters=None, applicable_exclusions=None):
        
        for field, options in applicable_filters["field_facets"].items():
            queryset = queryset.facet(field, **options)

        for field, options in applicable_filters["date_facets"].items():
            queryset = queryset.date_facet(field, **options)

        for field, options in applicable_filters["query_facets"].items():
            queryset = queryset.query_facet(field, **options)

        return queryset
603955
def get_queryset(self):
        
        self.queryset = super(CustomFieldsMixin, self).get_queryset()
        serializer_class = self.get_serializer_class()
        if hasattr(serializer_class.Meta, 'nested_fields'):
            nested_fields = serializer_class.Meta.nested_fields
            fields = serializer_class.Meta.fields
            self._expand_queryset(fields, nested_fields, self.queryset.model)
        return self.queryset
1339822
def index_queryset(self, using=None):
        
        translation.activate(settings.LANGUAGE_CODE)
        return self.get_model().objects.filter(status=UrlNode.PUBLISHED).select_related()
384896
def current_set(self):
        
        assert self.model.KEY_FIELDS != (), "Just use model.current() if there are no KEY_FIELDS"
        return self.get_queryset().filter(
            pk__in=self._current_ids_subquery()
        ).annotate(
            is_active=models.Value(1, output_field=models.IntegerField())
        )
526115
def _parent_queryset_es(self):
        
        parent = self._resource.parent
        if hasattr(parent, 'view'):
            req = self.request.blank(self.request.path)
            req.registry = self.request.registry
            req.matchdict = {
                parent.id_name: self.request.matchdict.get(parent.id_name)}
            parent_view = parent.view(parent.view._factory, req)
            obj = parent_view.get_item_es(**req.matchdict)
            prop = self._resource.collection_name
            objects_ids = getattr(obj, prop, None)
            return objects_ids
1211137
def get_queryset(self):
        
        queryset = super(CachedViewMixin, self).get_queryset()
        if self.action in ('list', 'retrieve'):
            return CachedQueryset(self.get_queryset_cache(), queryset=queryset)
        else:
            return queryset
798211
def get_queryset(self):
        
        self.z, self.x, self.y = self._parse_args()
        nw = self.tile_coord(self.x, self.y, self.z)
        se = self.tile_coord(self.x + 1, self.y + 1, self.z)
        bbox = Polygon((nw, (se[0], nw[1]),
                       se, (nw[0], se[1]), nw))
        qs = super(TiledGeoJSONLayerView, self).get_queryset()
        qs = qs.filter(**{
            '%s__intersects' % self.geometry_field: bbox
        })
        self.bbox = bbox.extent

        # Simplification dict by zoom level
        simplifications = self.simplifications or {}
        z = self.z
        self.simplify = simplifications.get(z)
        while self.simplify is None and z < 32:
            z += 1
            self.simplify = simplifications.get(z)

        # Won't trim point geometries to a boundary
        model_field = qs.model._meta.get_field(self.geometry_field)
        self.trim_to_boundary = (self.trim_to_boundary and
                                 not isinstance(model_field, PointField) and
                                 Intersection is not None)
        if self.trim_to_boundary:
            if django.VERSION < (1, 9):
                qs = qs.intersection(bbox)
            else:
                qs = qs.annotate(intersection=Intersection(self.geometry_field, bbox))
            self.geometry_field = 'intersection'

        return qs
758946
def _build_requested_prefetches(
        self,
        prefetches,
        requirements,
        model,
        fields,
        filters
    ):
        """"""

        for name, field in six.iteritems(fields):
            original_field = field
            if isinstance(field, DynamicRelationField):
                field = field.serializer
            if isinstance(field, serializers.ListSerializer):
                field = field.child
            if not isinstance(field, serializers.ModelSerializer):
                continue

            source = field.source or name
            if '.' in source:
                raise ValidationError(
                    'nested relationship values '
                    'are not supported'
                )

            if source in prefetches:
                # ignore duplicated sources
                continue

            is_remote = is_field_remote(model, source)
            is_id_only = getattr(field, 'id_only', lambda: False)()
            if is_id_only and not is_remote:
                continue

            related_queryset = getattr(original_field, 'queryset', None)

            if callable(related_queryset):
                related_queryset = related_queryset(field)

            source = field.source or name
            # Popping the source here (during explicit prefetch construction)
            # guarantees that implicitly required prefetches that follow will
            # not conflict.
            required = requirements.pop(source, None)

            prefetch_queryset = self._build_queryset(
                serializer=field,
                filters=filters.get(name, {}),
                queryset=related_queryset,
                requirements=required
            )

            # Note: There can only be one prefetch per source, even
            #       though there can be multiple fields pointing to
            #       the same source. This could break in some cases,
            #       but is mostly an issue on writes when we use all
            #       fields by default.
            prefetches[source] = self._create_prefetch(
                source,
                prefetch_queryset
            )

        return prefetches
858579
def facets(self, request):
        
        queryset = self.filter_facet_queryset(self.get_queryset())

        for facet in request.query_params.getlist(self.facet_query_params_text):

            if ":" not in facet:
                continue

            field, value = facet.split(":", 1)
            if value:
                queryset = queryset.narrow('%s:"%s"' % (field, queryset.query.clean(value)))

        serializer = self.get_facet_serializer(queryset.facet_counts(), objects=queryset, many=False)
        return Response(serializer.data)
367477
def get_queryset(self):
        """"""
        if self.model.node_order_by:
            order_by = ['parent'] + list(self.model.node_order_by)
        else:
            order_by = ['parent', 'sib_order']
        return super(AL_NodeManager, self).get_queryset().order_by(*order_by)
257547
def get_queryset(self):  # DROP_WITH_DJANGO15
        """"""

        args = (self.model._mptt_meta.tree_id_attr,
                self.model._mptt_meta.left_attr)
        method = 'get_query_set' if django.VERSION < (1, 6) else 'get_queryset'
        return getattr(super(SectionManager, self), method)().order_by(*args)
148484
def get_queryset(self):  # pylint: disable=method-hidden
        """"""
        if self.request and self.request.query_params.get('hydrate_data', False):
            return self.queryset.prefetch_related('data__entity_set')

        return self.queryset
302776
def _get_translated_queryset(self, meta=None):
        
        # Get via self.TRANSLATIONS_FIELD.get(..) so it also uses the prefetch/select_related cache.
        if meta is None:
            meta = self._parler_meta.root

        accessor = getattr(self, meta.rel_name)  # RelatedManager
        return accessor.get_queryset()
28980
def prepopulate(self, queryset):
        
        objs = list(queryset)
        hashobjs = dict([(x.pk, x) for x in objs] + [(self.pk, self)])
        for descendant in hashobjs.values():
            descendant._cached_children = []
        for descendant in objs:
            assert descendant._closure_parent_pk in hashobjs
            parent = hashobjs[descendant._closure_parent_pk]
            parent._cached_children.append(descendant)
713544
def _build_implicit_queryset(self, model, requirements):
        """"""

        queryset = self._make_model_queryset(model)
        prefetches = {}
        self._build_implicit_prefetches(
            model,
            prefetches,
            requirements
        )
        prefetch = prefetches.values()
        queryset = queryset.prefetch_related(*prefetch).distinct()
        if self.DEBUG:
            queryset._using_prefetches = prefetches
        return queryset
257491
def get_queryset_filters(self, query):
        
        conditions = Q()
        for field_name in self.fields:
            conditions |= Q(**{
                self._construct_qs_filter(field_name): query
            })
        return conditions