Another agg ES response strategy #2
This commit is contained in:
parent
68626e9fd5
commit
9cf82f03fe
|
|
@ -4,7 +4,6 @@ from django_elasticsearch_dsl_drf import constants
|
||||||
from django_elasticsearch_dsl_drf.filter_backends import (
|
from django_elasticsearch_dsl_drf.filter_backends import (
|
||||||
FilteringFilterBackend,
|
FilteringFilterBackend,
|
||||||
GeoSpatialFilteringFilterBackend,
|
GeoSpatialFilteringFilterBackend,
|
||||||
FacetedSearchFilterBackend,
|
|
||||||
)
|
)
|
||||||
from elasticsearch_dsl import TermsFacet
|
from elasticsearch_dsl import TermsFacet
|
||||||
from django_elasticsearch_dsl_drf.viewsets import BaseDocumentViewSet
|
from django_elasticsearch_dsl_drf.viewsets import BaseDocumentViewSet
|
||||||
|
|
@ -14,25 +13,7 @@ from search_indexes.documents.product import ProductDocument
|
||||||
from utils.pagination import ESDocumentPagination
|
from utils.pagination import ESDocumentPagination
|
||||||
|
|
||||||
|
|
||||||
class FacetedResponseMixin:
|
class NewsDocumentViewSet(BaseDocumentViewSet):
|
||||||
def filter_queryset(self, queryset):
|
|
||||||
"""
|
|
||||||
Given a queryset, filter it with whichever filter backend is in use.
|
|
||||||
|
|
||||||
You are unlikely to want to override this method, although you may need
|
|
||||||
to call it either from a list view, or from a custom `get_object`
|
|
||||||
method if you want to apply the configured filtering backend to the
|
|
||||||
default queryset.
|
|
||||||
"""
|
|
||||||
for backend in list(self.filter_backends):
|
|
||||||
bc = backend()
|
|
||||||
queryset = bc.filter_queryset(self.request, queryset, self)
|
|
||||||
if hasattr(bc, 'facets_computed'):
|
|
||||||
setattr(self, 'facets_computed', bc.facets_computed)
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
|
|
||||||
class NewsDocumentViewSet(BaseDocumentViewSet, FacetedResponseMixin):
|
|
||||||
"""News document ViewSet."""
|
"""News document ViewSet."""
|
||||||
|
|
||||||
document = NewsDocument
|
document = NewsDocument
|
||||||
|
|
@ -95,6 +76,14 @@ class NewsDocumentViewSet(BaseDocumentViewSet, FacetedResponseMixin):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
for backend in list(self.filter_backends):
|
||||||
|
bc = backend()
|
||||||
|
queryset = bc.filter_queryset(self.request, queryset, self)
|
||||||
|
if hasattr(bc, 'facets_computed'):
|
||||||
|
setattr(self.paginator, 'facets_computed', bc.facets_computed)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class MobileNewsDocumentViewSet(NewsDocumentViewSet):
|
class MobileNewsDocumentViewSet(NewsDocumentViewSet):
|
||||||
|
|
||||||
|
|
@ -104,7 +93,7 @@ class MobileNewsDocumentViewSet(NewsDocumentViewSet):
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class EstablishmentDocumentViewSet(BaseDocumentViewSet, FacetedResponseMixin):
|
class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
||||||
"""Establishment document ViewSet."""
|
"""Establishment document ViewSet."""
|
||||||
|
|
||||||
document = EstablishmentDocument
|
document = EstablishmentDocument
|
||||||
|
|
@ -303,6 +292,14 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet, FacetedResponseMixin):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
for backend in list(self.filter_backends):
|
||||||
|
bc = backend()
|
||||||
|
queryset = bc.filter_queryset(self.request, queryset, self)
|
||||||
|
if hasattr(bc, 'facets_computed'):
|
||||||
|
setattr(self.paginator, 'facets_computed', bc.facets_computed)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class MobileEstablishmentDocumentViewSet(EstablishmentDocumentViewSet):
|
class MobileEstablishmentDocumentViewSet(EstablishmentDocumentViewSet):
|
||||||
|
|
||||||
|
|
@ -417,6 +414,14 @@ class ProductDocumentViewSet(BaseDocumentViewSet):
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
for backend in list(self.filter_backends):
|
||||||
|
bc = backend()
|
||||||
|
queryset = bc.filter_queryset(self.request, queryset, self)
|
||||||
|
if hasattr(bc, 'facets_computed'):
|
||||||
|
setattr(self.paginator, 'facets_computed', bc.facets_computed)
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class MobileProductDocumentViewSet(ProductDocumentViewSet):
|
class MobileProductDocumentViewSet(ProductDocumentViewSet):
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user