search by type & subtype

This commit is contained in:
evgeniy-st 2019-10-25 16:06:52 +03:00
parent 9129d44708
commit d4fe5ebd2d
4 changed files with 26 additions and 7 deletions

View File

@ -97,6 +97,7 @@ class CropImageSerializer(serializers.Serializer):
class NewsImageSerializer(serializers.ModelSerializer):
"""Serializer for returning crop images of news image."""
orientation_display = serializers.CharField(source='get_orientation_display',
read_only=True)
original_url = serializers.URLField(source='image.url')

View File

@ -10,6 +10,16 @@ EstablishmentIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__,
EstablishmentIndex.settings(number_of_shards=1, number_of_replicas=1)
# todo: check & refactor
class ObjectField(fields.ObjectField):
def get_value_from_instance(self, *args, **kwargs):
value = super(ObjectField, self).get_value_from_instance(*args, **kwargs)
if value == {}:
return None
return value
@EstablishmentIndex.doc_type
class EstablishmentDocument(Document):
"""Establishment document."""
@ -22,14 +32,13 @@ class EstablishmentDocument(Document):
'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing',
properties=OBJECT_FIELD_PROPERTIES),
'index_name': fields.KeywordField(attr='index_name'),
})
establishment_subtypes = fields.ObjectField(
properties={
'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing',
properties={
'id': fields.IntegerField(),
}),
'name': fields.ObjectField(attr='name_indexing'),
'index_name': fields.KeywordField(attr='index_name'),
},
multi=True)
works_evening = fields.ListField(fields.IntegerField(
@ -54,7 +63,7 @@ class EstablishmentDocument(Document):
'closed_at': fields.KeywordField(attr='closed_at_str'),
}
))
address = fields.ObjectField(
address = ObjectField(
properties={
'id': fields.IntegerField(),
'street_name_1': fields.TextField(
@ -82,7 +91,7 @@ class EstablishmentDocument(Document):
),
}
),
}
},
)
# todo: need to fix
# collections = fields.ObjectField(

View File

@ -75,7 +75,7 @@ class NewsDocumentSerializer(DocumentSerializer):
class EstablishmentDocumentSerializer(DocumentSerializer):
"""Establishment document serializer."""
address = AddressDocumentSerializer()
address = AddressDocumentSerializer(allow_null=True)
tags = TagsDocumentSerializer(many=True)
schedule = ScheduleDocumentSerializer(many=True, allow_null=True)

View File

@ -124,6 +124,15 @@ class EstablishmentDocumentViewSet(BaseDocumentViewSet):
'establishment_subtypes': {
'field': 'establishment_subtypes.id'
},
'type': {
'field': 'establishment_type.index_name'
},
'subtype': {
'field': 'establishment_subtypes.index_name',
'lookups': [
constants.LOOKUP_QUERY_IN,
],
},
'works_noon': {
'field': 'works_noon',
'lookups': [