Products search draft
This commit is contained in:
parent
2ec40ff8fe
commit
93d32c7ae0
117
apps/search_indexes/documents/product.py
Normal file
117
apps/search_indexes/documents/product.py
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
"""Product app documents."""
|
||||
from django.conf import settings
|
||||
from django_elasticsearch_dsl import Document, Index, fields
|
||||
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
|
||||
from product import models
|
||||
|
||||
ProductIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__, 'product'))
|
||||
ProductIndex.settings(number_of_shards=1, number_of_replicas=1)
|
||||
|
||||
|
||||
@ProductIndex.doc_type
|
||||
class ProductDocument(Document):
|
||||
"""Product document."""
|
||||
|
||||
@staticmethod
|
||||
def _get_standard_properties():
|
||||
return {
|
||||
'name': fields.KeywordField(),
|
||||
'standard_type': fields.IntegerField(),
|
||||
'coordinates': fields.GeoPointField(),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_country_properties():
|
||||
return {
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(attr='name_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES),
|
||||
'code': fields.KeywordField(),
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _get_tags_properties():
|
||||
return {
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'value': fields.KeywordField(),
|
||||
'category': fields.ObjectField(properties={
|
||||
'label': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'public': fields.BooleanField(),
|
||||
'index_name': fields.KeywordField(),
|
||||
'value_type': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties=ProductDocument._get_country_properties()),
|
||||
}),
|
||||
}
|
||||
|
||||
description = fields.ObjectField(attr='description_indexing',
|
||||
properties=OBJECT_FIELD_PROPERTIES)
|
||||
product_type = fields.ObjectField(properies={
|
||||
'id': fields.IntegerField(),
|
||||
'name': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'index_name': fields.KeywordField(),
|
||||
'use_subtypes': fields.BooleanField(),
|
||||
})
|
||||
|
||||
subtypes = fields.ObjectField(
|
||||
properties={
|
||||
'name': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
'index_name': fields.KeywordField(),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
# TODO establishment
|
||||
|
||||
wine_region = fields.ObjectField(properties={
|
||||
'name': fields.KeywordField(),
|
||||
'country': fields.ObjectField(properties=_get_country_properties()),
|
||||
'coordinates': fields.GeoPointField(),
|
||||
'description': fields.ObjectField(properties=OBJECT_FIELD_PROPERTIES),
|
||||
})
|
||||
|
||||
wine_sub_region = fields.ObjectField(properties={'name': fields.KeywordField()})
|
||||
|
||||
classifications = fields.ObjectField( # TODO
|
||||
properties={
|
||||
'classification_type': fields.ObjectField(properties={}),
|
||||
'standard': fields.ObjectField(properties=_get_standard_properties()),
|
||||
'tags': fields.ObjectField(
|
||||
properties=_get_tags_properties(),
|
||||
multi=True
|
||||
),
|
||||
},
|
||||
multi=True
|
||||
)
|
||||
|
||||
standards = fields.ObjectField(
|
||||
properties=_get_standard_properties(),
|
||||
multi=True
|
||||
)
|
||||
|
||||
wine_village = fields.ObjectField(properties={
|
||||
'name': fields.KeywordField(),
|
||||
})
|
||||
|
||||
tags = fields.ObjectField(
|
||||
properties=_get_tags_properties(),
|
||||
multi=True
|
||||
)
|
||||
|
||||
class Django:
|
||||
model = models.Product
|
||||
fields = (
|
||||
'id',
|
||||
'category',
|
||||
'name',
|
||||
'available',
|
||||
'public_mark',
|
||||
'slug',
|
||||
'old_id',
|
||||
'state',
|
||||
'old_unique_key',
|
||||
'vintage',
|
||||
)
|
||||
related_models = [models.ProductType]
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().published().with_base_related()
|
||||
|
|
@ -4,6 +4,7 @@ from elasticsearch_dsl import AttrDict
|
|||
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
|
||||
from news.serializers import NewsTypeSerializer
|
||||
from search_indexes.documents import EstablishmentDocument, NewsDocument
|
||||
from search_indexes.documents.product import ProductDocument
|
||||
from search_indexes.utils import get_translated_value
|
||||
|
||||
|
||||
|
|
@ -123,3 +124,24 @@ class EstablishmentDocumentSerializer(DocumentSerializer):
|
|||
# 'establishment_type',
|
||||
# 'establishment_subtypes',
|
||||
)
|
||||
|
||||
|
||||
class ProductDocumentSerializer(DocumentSerializer):
|
||||
"""Product document serializer"""
|
||||
|
||||
class Meta:
|
||||
"""Meta class."""
|
||||
|
||||
document = ProductDocument
|
||||
fields = (
|
||||
'id',
|
||||
'category',
|
||||
'name',
|
||||
'available',
|
||||
'public_mark',
|
||||
'slug',
|
||||
'old_id',
|
||||
'state',
|
||||
'old_unique_key',
|
||||
'vintage'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ router = routers.SimpleRouter()
|
|||
router.register(r'establishments', views.EstablishmentDocumentViewSet, basename='establishment')
|
||||
router.register(r'mobile/establishments', views.EstablishmentDocumentViewSet, basename='establishment-mobile')
|
||||
router.register(r'news', views.NewsDocumentViewSet, basename='news')
|
||||
router.register(r'product', views.ProductDocumentViewSet, basename='news')
|
||||
|
||||
urlpatterns = router.urls
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ from django_elasticsearch_dsl_drf.filter_backends import (
|
|||
from django_elasticsearch_dsl_drf.viewsets import BaseDocumentViewSet
|
||||
from search_indexes import serializers, filters
|
||||
from search_indexes.documents import EstablishmentDocument, NewsDocument
|
||||
from search_indexes.documents.product import ProductDocument
|
||||
from utils.pagination import ProjectMobilePagination
|
||||
|
||||
|
||||
|
|
@ -192,3 +193,27 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
|
|||
]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ProductDocumentViewSet(BaseDocumentViewSet):
|
||||
"""Product document ViewSet."""
|
||||
|
||||
document = ProductDocument
|
||||
lookup_field = 'slug'
|
||||
pagination_class = ProjectMobilePagination
|
||||
permission_classes = (permissions.AllowAny,)
|
||||
serializer_class = serializers.ProductDocumentSerializer
|
||||
ordering = ('id',)
|
||||
|
||||
filter_backends = [
|
||||
filters.CustomSearchFilterBackend,
|
||||
FilteringFilterBackend,
|
||||
]
|
||||
|
||||
search_fields = {
|
||||
}
|
||||
translated_search_fields = (
|
||||
)
|
||||
|
||||
filter_fields = {
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user