class AuthorDocument(Document): """Author Elasticsearch document.""" id = fields.IntegerField(attr='id') name = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion), }) salutation = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion), }) email = StringField(fields={ 'raw': KeywordField(), }) birth_date = fields.DateField() biography = StringField() phone_number = StringField() website = StringField() headshot = StringField(attr='headshot_indexing') class Django(object): model = Author # The model associate with this Document class Meta(object): parallel_indexing = True
class PublisherDocument(DocType): """Publisher Elasticsearch document.""" id = fields.IntegerField(attr='id') name = StringField(fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) info = StringField() address = StringField(fields={'raw': KeywordField()}) city = StringField(fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) state_province = StringField(fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) country = StringField(fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) website = StringField() # Location location = fields.GeoPointField(attr='location_field_indexing') class Meta(object): """Meta options.""" model = Publisher # The model associate with this DocType
class CollectionDocument(Document): """Collection Elasticsearch document.""" id = fields.IntegerField(attr='id') title = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) collection_url = fields.TextField(attr='get_absolute_url') image = fields.FileField(attr="image") class Django(object): """Inner nested class Django.""" model = Collection # The model associate with this Document
class MovieDocument(Document): """Movie Elasticsearch document.""" id = fields.IntegerField(attr='id') title = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) world_premiere = fields.DateField() country = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) rf_premiere = fields.DateField() categories = fields.NestedField( properties={ 'title': fields.TextField(analyzer=html_strip, fields={ 'raw': KeywordField(), }), }) rating_kp = fields.FloatField() rating_imdb = fields.FloatField() directors = fields.NestedField( properties={ 'full_name': fields.TextField(analyzer=html_strip), 'id': fields.IntegerField(), }) image = fields.FileField(attr="poster") movie_url = fields.TextField(attr='get_absolute_url') class Django(object): """Inner nested class Django.""" model = Movies # The model associate with this Document
class SkillDocument(Document): """Skill Elasticsearch document.""" id = StringField( attr="id", analyzer=html_strip, ) name = StringField( fields={ "raw": KeywordField(), "suggest": fields.CompletionField(), }, ) # Date created created = fields.DateField() class Django(object): model = Skill # The model associate with this Document class Meta(object): parallel_indexing = True
class SectorDocument(Document): """Secto Elasticsearch document.""" id = StringField( attr="id", analyzer=html_strip, ) __name_fields = { "raw": KeywordField(), "suggest": fields.CompletionField(), "edge_ngram_completion": StringField(analyzer=edge_ngram_completion), "mlt": StringField(analyzer="english"), } name = StringField(analyzer=html_strip, fields=__name_fields) # Date created created = fields.DateField() class Django(object): model = Sector # The model associate with this Document class Meta(object): parallel_indexing = True
class CityDocument(Document): """City Elasticsearch document. This document has been created purely for testing out complex fields. """ # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ID id = fields.IntegerField(attr='id') # ******************************************************************** # ********************** Main data fields for search ***************** # ******************************************************************** name = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) info = StringField(analyzer=html_strip) # ******************************************************************** # ************** Nested fields for search and filtering ************** # ******************************************************************** # City object country = fields.NestedField( properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing'), }) location = fields.GeoPointField(attr='location_field_indexing') # ******************************************************************** # ********** Other complex fields for search and filtering *********** # ******************************************************************** boolean_list = fields.ListField(StringField(attr='boolean_list_indexing')) # boolean_dict_indexing = fields.ObjectField( # properties={ # 'true': fields.BooleanField(), # 'false': fields.BooleanField(), # } # ) datetime_list = fields.ListField( StringField(attr='datetime_list_indexing')) # datetime_dict_indexing float_list = fields.ListField(StringField(attr='float_list_indexing')) # float_dict_indexing integer_list = fields.ListField(StringField(attr='integer_list_indexing')) # integer_dict_indexing class Django(object): model = City # The model associate with this Document class Meta(object): parallel_indexing = True
class BookDocument(DocType): """Book Elasticsearch document.""" # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ID id = fields.IntegerField(attr='id') # ******************************************************************** # *********************** Main data fields for search **************** # ******************************************************************** __title_fields = { 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField(analyzer=edge_ngram_completion), 'mlt': StringField(analyzer='english'), } if ELASTICSEARCH_GTE_5_0: __title_fields.update({ 'suggest_context': fields.CompletionField(contexts=[ { "name": "tag", "type": "category", "path": "tags.raw", }, { "name": "state", "type": "category", "path": "state.raw", }, { "name": "publisher", "type": "category", "path": "publisher.raw", }, ]), }) title = StringField(analyzer=html_strip, fields=__title_fields) description = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'mlt': StringField(analyzer='english'), }) summary = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'mlt': StringField(analyzer='english'), }) # ******************************************************************** # ********** Additional fields for search and filtering ************** # ******************************************************************** authors = fields.ListField( StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), })) # Publisher publisher = StringField(attr='publisher_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) # Publication date publication_date = fields.DateField() # State state = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) # ISBN isbn = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) # Price price = fields.FloatField() # Pages pages = fields.IntegerField() # Stock count stock_count = fields.IntegerField() # Tags tags = StringField(attr='tags_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(multi=True), 'suggest': fields.CompletionField(multi=True), }, multi=True) # Date created created = fields.DateField() null_field = StringField(attr='null_field_indexing') class Meta(object): """Meta options.""" model = Book # The model associate with this DocType parallel_indexing = True def prepare_summary(self, instance): """Prepare summary.""" return instance.summary[:32766] def prepare_authors(self, instance): """Prepare authors.""" return [author.name for author in instance.authors.all()]
class JournalDocument(Document): """Journal Elasticsearch document.""" # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ISBN/ID isbn = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) # ******************************************************************** # *********************** Main data fields for search **************** # ******************************************************************** title = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField(analyzer=edge_ngram_completion), 'mlt': StringField(analyzer='english'), }) description = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'mlt': StringField(analyzer='english'), }) summary = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'mlt': StringField(analyzer='english'), }) # ******************************************************************** # ********** Additional fields for search and filtering ************** # ******************************************************************** # Publication date publication_date = fields.DateField() # Price price = fields.FloatField() # Pages pages = fields.IntegerField() # Stock count stock_count = fields.IntegerField() # Date created created = fields.DateField(attr='created_indexing') class Django(object): model = Journal # The model associate with this Document class Meta(object): parallel_indexing = True # queryset_pagination = 50 # This will split the queryset # # into parts while indexing def prepare_summary(self, instance): """Prepare summary.""" return instance.summary[:32766] if instance.summary else None
class LocationDocument(DocType): """ Location document. """ full = fields.StringField( analyzer=html_strip, fields={ "raw": KeywordField(), "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), # edge_ngram_completion "q": StringField( analyzer=edge_ngram_completion ), } ) partial = fields.StringField( analyzer=html_strip, fields={ "raw": KeywordField(), "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), # edge_ngram_completion "q": StringField( analyzer=edge_ngram_completion ), } ) postcode = fields.StringField( analyzer=html_strip, fields={ "raw": KeywordField(), "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), } ) number = fields.StringField( attr="address_no", analyzer=html_strip, fields={ "raw": KeywordField(), } ) address = fields.StringField( attr="address_street", analyzer=html_strip, fields={ "raw": KeywordField(), } ) town = fields.StringField( attr="address_town", analyzer=html_strip, fields={ "raw": KeywordField(), } ) authority = fields.StringField( attr="authority_name", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # URL fields /geocode/slug geocode = fields.StringField( analyzer=html_strip, fields={ "raw": KeywordField(), } ) slug = fields.StringField( analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Filter fields category = fields.StringField( attr="group", analyzer=html_strip, fields={ "raw": KeywordField(), } ) occupied = fields.StringField( attr="occupation_status_text", analyzer=html_strip, fields={ "raw": KeywordField(), } ) size = fields.FloatField(attr="floor_area") staff = fields.FloatField(attr="employee_count") rent = fields.FloatField(attr="rental_valuation") revenue = fields.FloatField(attr="revenue") coordinates = fields.GeoPointField(attr="location_field_indexing") class Meta(object): """Meta options.""" model = Location # The model associate with this DocType parallel_indexing = True queryset_pagination = 50 # This will split the queryset
class PublisherDocument(Document): """Publisher Elasticsearch document.""" id = fields.IntegerField(attr='id') name = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion ), } ) info = StringField() address = StringField( fields={ 'raw': KeywordField() } ) city = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion ), } ) state_province = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion ), } ) country = StringField( fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), 'edge_ngram_completion': StringField( analyzer=edge_ngram_completion ), } ) website = StringField() # Location location = fields.GeoPointField(attr='location_field_indexing') # Geo-shape fields location_point = fields.GeoShapeField(strategy='recursive', attr='location_point_indexing') location_circle = fields.GeoShapeField(strategy='recursive', attr='location_circle_indexing') class Django(object): model = Publisher # The model associate with this Document class Meta: parallel_indexing = True
class AddressDocument(Document): id = fields.IntegerField(attr='id') street = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) house_number = StringField(analyzer=html_strip) appendix = StringField(analyzer=html_strip) zip_code = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) city = fields.ObjectField( properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField() }), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing'), 'country': fields.ObjectField( properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing') }) }) # Defining the ``@property`` functions in the address model country = fields.NestedField( attr='country_indexing', properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'city': fields.ObjectField( properties={ 'name': StringField(analyzer=html_strip, fields={'raw': KeywordField()}) }) }) continent = fields.NestedField( attr='continent_indexing', properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField() }), 'country': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip, fields={'raw': KeywordField()}), 'city': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip, fields={'raw': KeywordField()}) }) }) }) location = fields.GeoPointField(attr='location_field_indexing') class Django(object): model = Address
class AddressDocument(Document): """Address Elasticsearch document.""" # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ID id = fields.IntegerField(attr='id') # ******************************************************************** # *********************** Main data fields for search **************** # ******************************************************************** __street_fields = { 'raw': KeywordField(), 'suggest': fields.CompletionField(), } if ELASTICSEARCH_GTE_5_0: __street_fields.update( { 'suggest_context': fields.CompletionField( contexts=[ { "name": "loc", "type": "geo", "path": "location", "precision": "1000km", }, ] ), } ) street = StringField( analyzer=html_strip, fields=__street_fields ) house_number = StringField(analyzer=html_strip) appendix = StringField(analyzer=html_strip) zip_code = StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), } ) # ******************************************************************** # ********** Additional fields for search and filtering ************** # ******************************************************************** # City object city = fields.ObjectField( properties={ 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), } ), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing'), 'country': fields.ObjectField( properties={ 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), } ), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField( attr='location_field_indexing' ) } ) } ) # Country object country = fields.NestedField( attr='country_indexing', properties={ 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), } ), 'city': fields.ObjectField( properties={ 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), }, ), }, ), }, ) # Continent object continent = fields.NestedField( attr='continent_indexing', properties={ 'id': fields.IntegerField(), 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), } ), 'country': fields.NestedField( properties={ 'id': fields.IntegerField(), 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), } ), 'city': fields.NestedField( properties={ 'id': fields.IntegerField(), 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), } ) } ) } ) } ) location = fields.GeoPointField( attr='location_field_indexing', ) class Django(object): model = Address # The model associate with this Document class Meta(object): parallel_indexing = True
class CollectionItemDocument(DocType): """Collection item document.""" # ID id = fields.IntegerField(attr='id') record_number = KeywordField() inventory_number = KeywordField() api_url = KeywordField(index="not_analyzed") web_url = KeywordField(index="not_analyzed") # ******************************************************************** # *************** Main data fields for search and filtering ********** # ******************************************************************** importer_uid = KeywordField(attr='importer_uid_indexing') language_code_orig = KeywordField(attr='language_code_orig') department = StringField( attr='department_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) # ******************************************************************** # ***************************** English ****************************** # ******************************************************************** title_en = StringField( attr='title_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) description_en = StringField( attr='description_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) period_en = StringField( attr='period_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) period_1_en = fields.NestedField( attr='period_1_en_indexing', properties={ 'name': StringField(analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), }), 'period_2_en': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), }), 'period_3_en': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), }), 'period_4_en': fields.NestedField( properties={ 'name': StringField( analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), }) }) }) }) }) primary_object_type_en = StringField( attr='primary_object_type_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), 'suggest': fields.CompletionField(), }) object_type_en = StringField(attr='object_type_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), 'suggest': fields.CompletionField(), }) # To be shown on the detail page object_type_detail_en = fields.TextField( attr='object_type_detail_en_indexing', index='no') material_en = StringField( attr='material_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) # To be shown on the detail page material_detail_en = fields.TextField(attr='material_detail_en_indexing', index='no') city_en = StringField( attr='city_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) country_en = StringField( attr='country_en_indexing', analyzer=html_strip_synonyms_en, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='english'), # 'suggest': fields.CompletionField(), }) # To be shown on the detail page references_en = fields.TextField(attr='references_en_indexing', index='no') # To be shown on the detail page acquired_en = fields.TextField(attr='acquired_en_indexing', index='no') # To be shown on the detail page site_found_en = fields.TextField(attr='site_found_en_indexing', index='no') # To be shown on the detail page reign_en = fields.TextField(attr='reign_en_indexing', index='no') # To be shown on the detail page keywords_en = fields.TextField(attr='keywords_en_indexing', index='no') # To be shown on the detail page dynasty_en = fields.TextField(attr='dynasty_en_indexing', index='no') # New fields # To be shown on the detail page credit_line_en = fields.TextField(attr='credit_line_en_indexing', index='no') # To be shown on the detail page region_en = fields.TextField(attr='region_en_indexing', index='no') # To be shown on the detail page sub_region_en = fields.TextField(attr='sub_region_en_indexing', index='no') # To be shown on the detail page locale_en = fields.TextField(attr='locale_en_indexing', index='no') # To be shown on the detail page excavation_en = fields.TextField(attr='excavation_en_indexing', index='no') # To be shown on the detail page museum_collection_en = fields.TextField( attr='museum_collection_en_indexing', index='no') # To be shown on the detail page style_en = fields.TextField(attr='style_en_indexing', index='no') # To be shown on the detail page culture_en = fields.TextField(attr='culture_en_indexing', index='no') # To be shown on the detail page inscriptions_en = fields.TextField(attr='inscriptions_en_indexing', index='no') # To be shown on the detail page provenance_en = fields.TextField(attr='provenance_en_indexing', index='no') # To be shown on the detail page exhibitions_en = fields.TextField(attr='exhibitions_en_indexing', index='no') # ******************************************************************** # ****************************** Dutch ******************************* # ******************************************************************** title_nl = StringField( attr='title_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) description_nl = StringField( attr='description_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) period_nl = StringField( attr='period_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) period_1_nl = fields.NestedField( attr='period_1_nl_indexing', properties={ 'name': StringField(analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), }), 'period_2_nl': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), }), 'period_3_nl': fields.NestedField( properties={ 'name': StringField(analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), }), 'period_4_nl': fields.NestedField( properties={ 'name': StringField( analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), }) }) }) }) }) primary_object_type_nl = StringField( attr='primary_object_type_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), 'suggest': fields.CompletionField(), }) object_type_nl = StringField(attr='object_type_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), 'suggest': fields.CompletionField(), }) # To be shown on the detail page object_type_detail_nl = fields.TextField( attr='object_type_detail_nl_indexing', index='no') material_nl = StringField( attr='material_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) # To be shown on the detail page material_detail_nl = fields.TextField(attr='material_detail_nl_indexing', index='no') city_nl = StringField( attr='city_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) country_nl = StringField( attr='country_nl_indexing', analyzer=html_strip_synonyms_nl, fields={ 'raw': KeywordField(), 'natural': StringField(analyzer='dutch'), # 'suggest': fields.CompletionField(), }) # To be shown on the detail page keywords_nl = fields.TextField(attr='keywords_nl_indexing', index='no') # To be shown on the detail page acquired_nl = fields.TextField(attr='acquired_nl_indexing', index='no') # To be shown on the detail page site_found_nl = fields.TextField(attr='site_found_nl_indexing', index='no') # To be shown on the detail page reign_nl = fields.TextField(attr='reign_nl_indexing', index='no') # To be shown on the detail page references_nl = fields.TextField(attr='references_nl_indexing', index='no') # To be shown on the detail page dynasty_nl = fields.TextField(attr='dynasty_nl_indexing', index='no') # New fields # To be shown on the detail page credit_line_nl = fields.TextField(attr='credit_line_nl_indexing', index='no') # To be shown on the detail page region_nl = fields.TextField(attr='region_nl_indexing', index='no') # To be shown on the detail page sub_region_nl = fields.TextField(attr='sub_region_nl_indexing', index='no') # To be shown on the detail page locale_nl = fields.TextField(attr='locale_nl_indexing', index='no') # To be shown on the detail page excavation_nl = fields.TextField(attr='excavation_nl_indexing', index='no') # To be shown on the detail page museum_collection_nl = fields.TextField( attr='museum_collection_nl_indexing', index='no') # To be shown on the detail page style_nl = fields.TextField(attr='style_nl_indexing', index='no') # To be shown on the detail page culture_nl = fields.TextField(attr='culture_nl_indexing', index='no') # To be shown on the detail page inscriptions_nl = fields.TextField(attr='inscriptions_nl_indexing', index='no') # To be shown on the detail page provenance_nl = fields.TextField(attr='provenance_nl_indexing', index='no') # To be shown on the detail page exhibitions_nl = fields.TextField(attr='exhibitions_nl_indexing', index='no') # ******************************************************************** # ************************** Language independent ******************** # ******************************************************************** dimensions = StringField( attr='dimensions_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'natural': StringField(), # 'suggest': fields.CompletionField(), }) object_date_begin = StringField( attr='object_date_begin_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'natural': StringField(), # 'suggest': fields.CompletionField(), }) object_date_end = StringField( attr='object_date_end_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'natural': StringField(), # 'suggest': fields.CompletionField(), }) location = fields.GeoPointField(attr='geo_location_indexing') # List of 32x32 PNG versions of the images. Full path to. images = fields.ListField(StringField(attr='images_indexing')) # List of image URLs. images_urls = fields.ListField( fields.ObjectField(attr='images_urls_indexing', properties={ 'th': KeywordField(index="not_analyzed"), 'lr': KeywordField(index="not_analyzed"), })) # Classified as by our AI classified_as = fields.ListField( StringField(attr='classified_as_indexing', fields={ 'raw': KeywordField(), })) # Classified as 1st element classified_as_1 = StringField(attr='classified_as_1_indexing', fields={ 'raw': KeywordField(), }) # Classified as 2nd element classified_as_2 = StringField(attr='classified_as_2_indexing', fields={ 'raw': KeywordField(), }) # Classified as 3rd element classified_as_3 = StringField(attr='classified_as_3_indexing', fields={ 'raw': KeywordField(), }) # ******************************************************************** # ************** Nested fields for search and filtering ************** # ******************************************************************** # # City object # country = fields.NestedField( # properties={ # 'name': StringField( # analyzer=html_strip, # fields={ # 'raw': KeywordField(), # 'suggest': fields.CompletionField(), # } # ), # 'info': StringField(analyzer=html_strip), # 'location': fields.GeoPointField(attr='location_field_indexing'), # } # ) # # location = fields.GeoPointField(attr='location_field_indexing') class Meta(object): """Meta options.""" model = Item # The model associate with this DocType def get_queryset(self): """Filter out items that are not eligible for indexing.""" qs = super(CollectionItemDocument, self).get_queryset() # qs = qs.select_related('period_node').prefetch_related('images') filters = [] for field in ['title']: for language in ['en', 'nl']: filters.extend([ Q(**{"{}_{}__isnull".format(field, language): True}), Q(**{"{}_{}__exact".format(field, language): ''}), ]) if filters: qs = qs.exclude(six.moves.reduce(operator.or_, filters)) # We concatenate ``object_type`` and ``classification`` fields, after # cleaning them. Therefore, db-only checks don't work here. ids = [] for item in qs: if not (item.object_type_en_indexing and item.object_type_nl_indexing): ids.append(item.pk) return qs.exclude(id__in=ids) def prepare_department(self, instance): """Prepare department.""" return instance.department_indexing \ if instance.department_indexing\ else VALUE_NOT_SPECIFIED def prepare_object_date_begin(self, instance): """Prepare material.""" return instance.object_date_begin_indexing def prepare_object_date_end(self, instance): """Prepare material.""" return instance.object_date_end_indexing # ******************************************************************** # ***************************** English ****************************** # ******************************************************************** def prepare_material_en(self, instance): """Prepare material.""" return instance.material_en_indexing \ if instance.material_en_indexing\ else VALUE_NOT_SPECIFIED def prepare_period_en(self, instance): """Prepare state.""" return instance.period_en_indexing \ if instance.period_en_indexing \ else VALUE_NOT_SPECIFIED def prepare_dynasty_en(self, instance): """Prepare dynasty.""" return instance.dynasty_en_indexing \ if instance.dynasty_en_indexing \ else VALUE_NOT_SPECIFIED def prepare_description_en(self, instance): """Prepare description.""" return instance.description_en_indexing \ if instance.description_en_indexing\ else VALUE_NOT_SPECIFIED def prepare_city_en(self, instance): """Prepare city.""" return instance.city_en_indexing \ if instance.city_en_indexing\ else VALUE_NOT_SPECIFIED def prepare_country_en(self, instance): """Prepare country.""" return instance.country_en_indexing \ if instance.country_en_indexing \ else VALUE_NOT_SPECIFIED # ******************************************************************** # ****************************** Dutch ******************************* # ******************************************************************** def prepare_material_nl(self, instance): """Prepare material.""" return instance.material_nl_indexing \ if instance.material_nl_indexing\ else VALUE_NOT_SPECIFIED def prepare_period_nl(self, instance): """Prepare state.""" return instance.period_nl_indexing \ if instance.period_nl_indexing \ else VALUE_NOT_SPECIFIED def prepare_dynasty_nl(self, instance): """Prepare dynasty.""" return instance.dynasty_nl_indexing \ if instance.dynasty_nl_indexing \ else VALUE_NOT_SPECIFIED def prepare_description_nl(self, instance): """Prepare description.""" return instance.description_nl_indexing \ if instance.description_nl_indexing\ else VALUE_NOT_SPECIFIED def prepare_city_nl(self, instance): """Prepare city.""" return instance.city_nl_indexing \ if instance.city_nl_indexing\ else VALUE_NOT_SPECIFIED def prepare_country_nl(self, instance): """Prepare country.""" return instance.country_nl_indexing \ if instance.country_nl_indexing \ else VALUE_NOT_SPECIFIED
class LocationDocument(DocType): """ Location document. """ # Full fields __full_fields = { "raw": KeywordField(), # edge_ngram_completion "q": StringField( analyzer=edge_ngram_completion ), } if ELASTICSEARCH_GTE_5_0: __full_fields.update( { "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), } ) full = StringField( analyzer=html_strip, fields=__full_fields ) # Partial fields __partial_fields = { "raw": KeywordField(), # edge_ngram_completion "q": StringField( analyzer=edge_ngram_completion ), } if ELASTICSEARCH_GTE_5_0: __partial_fields.update( { "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), } ) partial = StringField( analyzer=html_strip, fields=__partial_fields ) # Postcode __postcode_fields = { "raw": KeywordField(), } if ELASTICSEARCH_GTE_5_0: __postcode_fields.update( { "suggest": fields.CompletionField(), "context": fields.CompletionField( contexts=[ { "name": "category", "type": "category", "path": "category.raw", }, { "name": "occupied", "type": "category", "path": "occupied.raw", }, ] ), } ) postcode = StringField( analyzer=html_strip, fields=__postcode_fields ) # Number number = StringField( attr="address_no", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Address address = StringField( attr="address_street", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Town town = StringField( attr="address_town", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Authority authority = StringField( attr="authority_name", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # URL fields /geocode/slug geocode = StringField( analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Slug slug = StringField( analyzer=html_strip, fields={ "raw": KeywordField(), } ) # ********************* Filter fields ********************** # Category category = StringField( attr="group", analyzer=html_strip, fields={ "raw": KeywordField(), } ) # Occupied occupied = StringField( attr="occupation_status_text", analyzer=html_strip, fields={ "raw": KeywordField(), } ) size = fields.FloatField(attr="floor_area") staff = fields.FloatField(attr="employee_count") rent = fields.FloatField(attr="rental_valuation") revenue = fields.FloatField(attr="revenue") coordinates = fields.GeoPointField(attr="location_field_indexing") class Meta(object): """Meta options.""" model = Location # The model associate with this DocType parallel_indexing = True queryset_pagination = 50 # This will split the queryset
class AddressDocument(DocType): """Address Elasticsearch document.""" # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ID id = fields.IntegerField(attr='id') # ******************************************************************** # *********************** Main data fields for search **************** # ******************************************************************** street = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) house_number = StringField(analyzer=html_strip) appendix = StringField(analyzer=html_strip) zip_code = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) # ******************************************************************** # ********** Additional fields for search and filtering ************** # ******************************************************************** # City object city = fields.ObjectField( properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing'), 'country': fields.ObjectField( properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'info': StringField(analyzer=html_strip), 'location': fields.GeoPointField(attr='location_field_indexing') }) }) # Country object country = fields.NestedField( attr='country_indexing', properties={ 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'city': fields.ObjectField(properties={ 'name': StringField( analyzer=html_strip, fields={ 'raw': KeywordField(), }, ), }, ), }, ) # Continent object continent = fields.NestedField( attr='continent_indexing', properties={ 'id': fields.IntegerField(), 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }), 'country': fields.NestedField( properties={ 'id': fields.IntegerField(), 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }), 'city': fields.NestedField( properties={ 'id': fields.IntegerField(), 'name': StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) }) }) }) location = fields.GeoPointField(attr='location_field_indexing') class Meta(object): """Meta options.""" model = Address # The model associate with this DocType
class BookDocument(DocType): """Book Elasticsearch document.""" # In different parts of the code different fields are used. There are # a couple of use cases: (1) more-like-this functionality, where `title`, # `description` and `summary` fields are used, (2) search and filtering # functionality where all of the fields are used. # ID id = fields.IntegerField(attr='id') # ******************************************************************** # *********************** Main data fields for search **************** # ******************************************************************** title = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) description = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) summary = StringField(analyzer=html_strip, fields={'raw': KeywordField()}) # ******************************************************************** # ********** Additional fields for search and filtering ************** # ******************************************************************** authors = fields.ListField( StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), })) # Publisher publisher = StringField(attr='publisher_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(), 'suggest': fields.CompletionField(), }) # Publication date publication_date = fields.DateField() # State state = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) # ISBN isbn = StringField(analyzer=html_strip, fields={ 'raw': KeywordField(), }) # Price price = fields.FloatField() # Pages pages = fields.IntegerField() # Stock count stock_count = fields.IntegerField() # Tags tags = StringField(attr='tags_indexing', analyzer=html_strip, fields={ 'raw': KeywordField(multi=True), 'suggest': fields.CompletionField(multi=True), }, multi=True) null_field = fields.StringField(attr='null_field_indexing') class Meta(object): """Meta options.""" model = Book # The model associate with this DocType def prepare_summary(self, instance): """Prepare summary.""" return instance.summary[:32766] def prepare_authors(self, instance): """Prepare authors.""" return [author.name for author in instance.authors.all()]