gault-millau/apps/search_indexes/documents/establishment.py
2019-09-18 15:05:28 +03:00

75 lines
2.8 KiB
Python

"""Establishment app documents."""
from django.conf import settings
from django_elasticsearch_dsl import Document, Index, fields
from search_indexes.utils import OBJECT_FIELD_PROPERTIES
from establishment import models
EstablishmentIndex = Index(settings.ELASTICSEARCH_INDEX_NAMES.get(__name__,
'establishment'))
EstablishmentIndex.settings(number_of_shards=1, number_of_replicas=1)
@EstablishmentIndex.doc_type
class EstablishmentDocument(Document):
"""Establishment document."""
description = fields.ObjectField(attr='description_indexing',
properties=OBJECT_FIELD_PROPERTIES)
tags = fields.ObjectField(
properties={
'id': fields.IntegerField(attr='metadata.id'),
'label': fields.ObjectField(attr='metadata.label_indexing',
properties=OBJECT_FIELD_PROPERTIES),
'category': fields.ObjectField(attr='metadata.category',
properties={
'id': fields.IntegerField(),
})
},
multi=True)
address = fields.ObjectField(
properties={
'id': fields.IntegerField(),
'street_name_1': fields.TextField(
fields={'raw': fields.KeywordField()}
),
'street_name_2': fields.TextField(
fields={'raw': fields.KeywordField()}
),
'number': fields.IntegerField(),
'location': fields.GeoPointField(attr='location_field_indexing'),
'city': fields.ObjectField(
properties={
'id': fields.IntegerField(),
'name': fields.KeywordField(),
'is_island': fields.BooleanField(),
'country': fields.ObjectField(
properties={
'id': fields.IntegerField(),
'name': fields.ObjectField(attr='name_indexing',
properties=OBJECT_FIELD_PROPERTIES),
'code': fields.KeywordField(),
}
),
}
),
}
)
collections = fields.ObjectField(properties={
'id': fields.IntegerField(attr='collection.id'),
'collection_type': fields.IntegerField(attr='collection.collection_type'),
})
class Django:
model = models.Establishment
fields = (
'id',
'name',
'toque_number',
'price_level',
)
def get_queryset(self):
return super().get_queryset().published()