class PersonDocument(Document): autocomplete = TextField(attr="name_autocomplete", analyzer=autocomplete_analyzer) sort_date = DateField() organization_ids = IntegerField(attr="organization_ids") def get_queryset(self): sort_date_queryset = Membership.objects.filter( start__isnull=False).order_by("-start") return (Person.objects.order_by("id").prefetch_related( "membership_set").prefetch_related( Prefetch( "membership_set", queryset=sort_date_queryset, to_attr="sort_date_prefetch", ))) class Index: name = settings.ELASTICSEARCH_PREFIX + "-person" class Django: model = Person queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION fields = ["id", "name", "given_name", "family_name"]
class PersonDocument(DocType): autocomplete = TextField(attr="name_autocomplete", analyzer=autocomplete_analyzer) sort_date = DateField() organization_ids = IntegerField(attr="organization_ids") def get_queryset(self): sort_date_queryset = Membership.objects.filter(start__isnull=False).order_by( "-start" ) return ( Person.objects.order_by("id") .prefetch_related("membership_set") .prefetch_related( Prefetch( "membership_set", queryset=sort_date_queryset, to_attr="sort_date_prefetch", ) ) ) class Meta: model = Person queryset_pagination = 500 fields = ["id", "name", "given_name", "family_name"]
class MeetingDocument(DocType): location = GeoPointField() sort_date = DateField() agenda_items = NestedField(attr="agendaitem_set", properties={ "key": StringField(), "title": StringField(), "position": IntegerField(), "public": BooleanField(), }) @staticmethod def prepare_location(instance: Meeting): if instance.location: return instance.location.coordinates() class Meta: model = Meeting fields = [ 'id', 'name', 'short_name', 'start', 'end', 'created', 'modified', ]
class MeetingDocument(DocType): location = GeoPointField() sort_date = DateField() agenda_items = NestedField( attr="agendaitem_set", properties={ "key": TextField(), "name": TextField(analyzer=text_analyzer), "position": IntegerField(), "public": BooleanField(), }, ) @staticmethod def prepare_location(instance: Meeting) -> Optional[Dict[str, Any]]: if instance.location: return instance.location.coordinates() def get_queryset(self): return (Meeting.objects.prefetch_related( "agendaitem_set").prefetch_related("location").order_by("id")) class Meta: model = Meeting queryset_pagination = 500 fields = [ "id", "name", "short_name", "start", "end", "created", "modified" ]
class GenericMembershipDocument: autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField() body = ObjectField(properties={"id": IntegerField(), "name": TextField()}) class Meta: fields = ["id", "name", "short_name"]
class GenericMembershipDocument: autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField() body = ObjectField(properties={"id": IntegerField(), "name": TextField()}) class Django: fields = ["id", "name", "short_name"] queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION
class GenericMembershipDocument: autocomplete = StringField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField() body = ObjectField(properties={ 'id': IntegerField(), 'name': StringField(), }) class Meta: fields = ['id', 'name', 'short_name']
class PersonDocument(DocType): autocomplete = StringField(attr="name_autocomplete", analyzer=autocomplete_analyzer) sort_date = DateField() organization_ids = IntegerField(attr="organization_ids") class Meta: model = Person fields = [ 'id', 'name', 'given_name', 'family_name', ]
class OrganizationDocument(DocType, GenericMembershipDocument): autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField() body = ObjectField(properties={"id": IntegerField(), "name": TextField()}) def get_queryset(self): return Organization.objects.prefetch_related("body").order_by("id") class Meta(GenericMembershipDocument.Meta): model = Organization queryset_pagination = 500 fields = [ "id", "name", "short_name", "start", "end", "created", "modified" ]
class OrganizationDocument(Document, GenericMembershipDocument): autocomplete = TextField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField() body = ObjectField(properties={"id": IntegerField(), "name": TextField()}) def get_queryset(self): return Organization.objects.prefetch_related("body").order_by("id") class Index: name = settings.ELASTICSEARCH_PREFIX + "-organization" class Django(GenericMembershipDocument.Django): model = Organization queryset_pagination = settings.ELASTICSEARCH_QUERYSET_PAGINATION fields = [ "id", "name", "short_name", "start", "end", "created", "modified" ]
class OrganizationDocument(DocType, GenericMembershipDocument): autocomplete = StringField(attr="name", analyzer=autocomplete_analyzer) sort_date = DateField(attr="sort_date") body = ObjectField(properties={ 'id': IntegerField(), 'name': StringField(), }) class Meta(GenericMembershipDocument.Meta): model = Organization fields = [ 'id', 'name', 'short_name', 'start', 'end', 'created', 'modified', ]
class PropertyDocument(Document): """Property Elasticsearch document.""" id = IntegerField(attr="id") propertyName = TextField() landlord = TextField(attr="user_indexing", ) numberOfBedrooms = IntegerField() numberOfBathrooms = IntegerField() propertyType = TextField() availableFrom = DateField() listingDescription = TextField() unit = IntegerField() size = FloatField() propertyStatus = TextField() monthlyRent = FloatField() securityDeposit = FloatField() created_at = DateField() propertyRules = ObjectField( properties={ PROPERTY: TextField(attr="property_indexing", ), PropertyRules.SMOKING: BooleanField(), PropertyRules.PET: BooleanField(), PropertyRules.MUSICAL_INSTRUMENTS: BooleanField(), }) propertyAddress = ObjectField( properties={ PROPERTY: TextField(attr="property_indexing", ), PropertyAddress.ADDRESS: TextField(), PropertyAddress.STATE_NAME: TextField(), PropertyAddress.LATITUDE: FloatField(), PropertyAddress.LONGITUDE: FloatField(), }) propertyAmenities = ObjectField( properties={ PROPERTY: TextField(attr="property_indexing", ), PropertyAmenities.POOL: BooleanField(), PropertyAmenities.GARDEN: BooleanField(), PropertyAmenities.ELEVATOR: BooleanField(), PropertyAmenities.DOORMAN: BooleanField(), PropertyAmenities.DECK: BooleanField(), PropertyAmenities.WASHER: BooleanField(), PropertyAmenities.GYM: BooleanField(), PropertyAmenities.PARKING: BooleanField(), PropertyAmenities.FIRE_PLACE: BooleanField(), PropertyAmenities.AIR_CONDITION: BooleanField(), PropertyAmenities.DISH_WASHER: BooleanField(), PropertyAmenities.ITEM_STORAGE: BooleanField(), PropertyAmenities.WHEELCHAIR: BooleanField(), PropertyAmenities.BALCONY: BooleanField(), PropertyAmenities.HARD_FLOOR: BooleanField(), PropertyAmenities.FURNISHED: BooleanField(), PropertyAmenities.VIEW: BooleanField(), PropertyAmenities.HIGH_RISE: BooleanField(), PropertyAmenities.STUDENT_FRIENDLY: BooleanField(), PropertyAmenities.UTILITIES: BooleanField(), }) propertyImage = ObjectField( properties={ ID: IntegerField(attr="id"), PROPERTY: TextField(attr="property_indexing", ), PropertyImage.IMAGE: FileField(), }) class Django(object): """The Django model associate with this Document""" model = Property