Merge branch 'feature/search-by-type' into develop

This commit is contained in:
evgeniy-st 2019-10-25 16:07:38 +03:00
commit 174e580c20
4 changed files with 26 additions and 7 deletions

View File

@ -97,6 +97,7 @@ class CropImageSerializer(serializers.Serializer):
class NewsImageSerializer(serializers.ModelSerializer): class NewsImageSerializer(serializers.ModelSerializer):
"""Serializer for returning crop images of news image.""" """Serializer for returning crop images of news image."""
orientation_display = serializers.CharField(source='get_orientation_display', orientation_display = serializers.CharField(source='get_orientation_display',
read_only=True) read_only=True)
original_url = serializers.URLField(source='image.url') 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) 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 @EstablishmentIndex.doc_type
class EstablishmentDocument(Document): class EstablishmentDocument(Document):
"""Establishment document.""" """Establishment document."""
@ -22,14 +32,13 @@ class EstablishmentDocument(Document):
'id': fields.IntegerField(), 'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing', 'name': fields.ObjectField(attr='name_indexing',
properties=OBJECT_FIELD_PROPERTIES), properties=OBJECT_FIELD_PROPERTIES),
'index_name': fields.KeywordField(attr='index_name'),
}) })
establishment_subtypes = fields.ObjectField( establishment_subtypes = fields.ObjectField(
properties={ properties={
'id': fields.IntegerField(), 'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing', 'name': fields.ObjectField(attr='name_indexing'),
properties={ 'index_name': fields.KeywordField(attr='index_name'),
'id': fields.IntegerField(),
}),
}, },
multi=True) multi=True)
works_evening = fields.ListField(fields.IntegerField( works_evening = fields.ListField(fields.IntegerField(
@ -54,7 +63,7 @@ class EstablishmentDocument(Document):
'closed_at': fields.KeywordField(attr='closed_at_str'), 'closed_at': fields.KeywordField(attr='closed_at_str'),
} }
)) ))
address = fields.ObjectField( address = ObjectField(
properties={ properties={
'id': fields.IntegerField(), 'id': fields.IntegerField(),
'street_name_1': fields.TextField( 'street_name_1': fields.TextField(
@ -82,7 +91,7 @@ class EstablishmentDocument(Document):
), ),
} }
), ),
} },
) )
# todo: need to fix # todo: need to fix
# collections = fields.ObjectField( # collections = fields.ObjectField(

View File

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

View File

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