class ProfileIndex(DocType): django_id = Integer() email = String(analyzer='snowball', fields={'raw': String(index='no')}) name = String(analyzer='snowball', fields={'raw': String(index='no')}) is_active = Boolean() @staticmethod def get_model(): from b24online.models import Profile return Profile @classmethod def get_queryset(cls): return cls.get_model().objects.all().select_related('country', 'user') @classmethod def to_index(cls, obj): index_instance = cls( django_id=obj.pk, email=obj.user.email, name=obj.full_name, is_active=obj.user.is_active ) return index_instance
class Work(BaseDoc): title = Text(analyzer=plain_ascii, fields={'keyword': Keyword()}) sort_title = Keyword(index=False) uuid = Keyword(store=True) medium = Text(fields={'keyword': Keyword()}) series = Text(fields={'keyword': Keyword()}) series_position = Keyword() alt_titles = Text(fields={'keyword': Keyword()}) issued_date = DateRange(format='date_optional_time') created_date = DateRange(format='date_optional_time') is_government_document = Boolean(multi=False) instances = Nested(Instance) identifiers = Nested(Identifier) subjects = Nested(Subject) agents = Nested(Agent) languages = Nested(Language) @classmethod def getFields(cls): return [ 'uuid', 'title', 'sort_title', 'sub_title', 'medium', 'series', 'series_position', 'date_modified', 'date_updated' ] def __dir__(self): return ['identifiers', 'subjects', 'agents', 'languages'] def __repr__(self): return '<ESWork(title={}, uuid={})>'.format(self.title, self.uuid) class Index: name = os.environ.get('ES_INDEX', None)
class QandA(DocType): """Class used for QandA documents. Defines all the elastic search mappings""" answer = String() answering_member = String(index='not_analyzed') answer_date = Date() ministerial_correction = Boolean() first_answer_date = Date() asked_date = Date() house = String(index='not_analyzed') question = String() tabling_member = String(index='not_analyzed') # you can use multi-fields easily #This creates a extra field that won't be analysed. Useful when aggregating on #terms. i.e. Doing a histogram on the analysed categoriy will give: #"ministry", "defence", "justice" , "of"... #where raw will give #"ministry of justice", "minstry of defence" answering_body = String(fields={'raw': String(index='not_analyzed')}) answering_members_constituency = String( fields={'raw': String(index='not_analyzed')}) answering_department = String(fields={'raw': String(index='not_analyzed')}) tabling_members_constituency = String( fields={'raw': String(index='not_analyzed')}) def save(self, **kwargs): self.created_at = datetime.now() return super().save(**kwargs)
class Account(DocType): traderId = Keyword() cash = Float() positions = Nested() allValue = Float() timestamp = Date() tradingClose = Boolean() def copy_for_save(self, trading_close): account = Account() account.cash = self.cash account.traderId = self.traderId account.allValue = self.allValue account.positions = self.positions account.timestamp = account.timestamp account.tradingClose = trading_close return account def save(self, using=None, index=None, validate=True, **kwargs): self.meta.id = "{}_{}".format( self.traderId, self.timestamp.strftime('%Y-%m-%d %H:%M:%S')) return super().save(using, index, validate, **kwargs) class Meta: doc_type = 'doc' all = MetaField(enabled=False)
class MemberDoc(UserDoc): """Discord member.""" id = Integer() name = Text(fields={'raw': Keyword()}) display_name = Text(fields={'raw': Keyword()}) bot = Boolean() top_role = Nested(doc_class=RoleDoc) roles = Nested(doc_class=RoleDoc) server = Nested(doc_class=ServerDoc) class Meta: doc_type = 'member' @classmethod def member_dict(cls, member): """Member dictionary.""" d = {'id': member.id, 'username': member.name, 'bot': member.bot} if isinstance(member, Member): d.update({ 'name': member.display_name, 'display_name': member.display_name, 'roles': [{ 'id': r.id, 'name': r.name } for r in member.roles], 'top_role': { 'id': member.top_role.id, 'name': member.top_role.name }, 'joined_at': member.joined_at }) return d
class BlogCommentDoc(DocType): id = Keyword(required=True) oid = Keyword(required=True) blogitem_id = Integer(required=True) approved = Boolean() add_date = Date() comment = Text(analyzer=text_analyzer)
class VacancyIndex(DefaultIndex): """Vacancy's index class.""" id = Integer() title = Text(analyzer='standard') description = Text(analyzer='standard') salary = Float() company_id = Integer() active = Boolean() class Meta: """Metaclass of index.""" index = 'vacancies' @classmethod def store_index(cls, vacancy): """Create or update vacancy's index.""" obj = cls(meta={'id': vacancy.id}, id=vacancy.id, title=vacancy.title, description=vacancy.description, salary=vacancy.salary, company_id=vacancy.company_id, active=vacancy.active) obj.save() return obj.to_dict(include_meta=True)
class StationStatus(DocType): """ { "station_id":"72", "num_bikes_available":11, "num_bikes_disabled":1, "num_docks_available":27, "num_docks_disabled":0, "is_installed":1, "is_renting":1, "is_returning":1, "last_reported":1478989087, "eightd_has_available_keys":false } """ station_id = Text() location = GeoPoint() num_bikes_available = Integer() num_docks_available = Integer() num_docs_disabled = Integer() is_installed = Integer() is_renting = Integer() is_returning = Integer() last_reported = Date() eightd_has_key_dispenser = Boolean() station_name = Text(analyzer='snowball') class Meta: index = 'station_status'
class Post(Document): images = Text(multi=True) location = Nested(Location) created_at = Date() last_updated_at = Date() open_range = Integer(required=True) author_id = Integer(required=True) comments_on = Boolean(required=True) comments = Nested(Comment) playlist = Nested(Music) content = Text() class Index: name = 'musicmaps' def add_comment(self, author_id, content): self.comments.append( Comment(author_id=author_id, content=content, created_at=datetime.now())) def save(self, **kwargs): self.created_at = datetime.now() return super().save(**kwargs) def update(self, **kwargs): self.last_updated_at = datetime.now() return super().update(**kwargs)
class ResourceIndex(DocType): name = Text() slug = Text() brief_description = Text() show_window = Boolean() visible = Boolean() order = Integer() topic_id = Long() subejct_id = Long() nested_tags = Nested(ResourceTagIndex) create_date = Date() last_update = Date() subclass = Text() class Index: name = 'resource-index'
class _ForensicSampleDoc(InnerDoc): raw = Text() headers = Object() headers_only = Boolean() to = Nested(_EmailAddressDoc) subject = Text() filename_safe_subject = Text() _from = Object(_EmailAddressDoc) date = Date() reply_to = Nested(_EmailAddressDoc) cc = Nested(_EmailAddressDoc) bcc = Nested(_EmailAddressDoc) body = Text() attachments = Nested(_EmailAttachmentDoc) def add_to(self, display_name, address): self.to.append(_EmailAddressDoc(display_name=display_name, address=address)) def add_reply_to(self, display_name, address): self.reply_to.append(_EmailAddressDoc(display_name=display_name, address=address)) def add_cc(self, display_name, address): self.cc.append(_EmailAddressDoc(display_name=display_name, address=address)) def add_bcc(self, display_name, address): self.bcc.append(_EmailAddressDoc(display_name=display_name, address=address)) def add_attachment(self, filename, content_type, sha256): self.attachments.append(_EmailAttachmentDoc(filename=filename, content_type=content_type, sha256=sha256))
class Answer(Post): is_accepted = Boolean() @classmethod def _matches(cls, hit): " Use Answer class for child documents with child name 'answer' " return isinstance(hit['_source']['question_answer'], dict) \ and hit['_source']['question_answer'].get('name') == 'answer' @classmethod def search(cls, **kwargs): return cls._index.search(**kwargs).exclude('term', question_answer='question') @property def question(self): # cache question in self.meta # any attributes set on self would be interpretted as fields if 'question' not in self.meta: self.meta.question = Question.get( id=self.question_answer.parent, index=self.meta.index) return self.meta.question def save(self, **kwargs): # set routing to parents id automatically self.meta.routing = self.question_answer.parent return super(Answer, self).save(**kwargs)
class DatasetMeta(DiscoveryMeta): """ Modifiable Metadata Fields """ # username also required through inheritance class_id = Keyword(required=True) # like ctsa::bts:CTSADataset private = Boolean() # this controls visibility guide = Keyword()
class TaxRulesIndex(DocType): id = Integer() code = Text() priority = Integer() position = Integer() customer_tax_class_ids = Long() product_tax_class_ids = Long() tax_rate_ids = Long() calculate_subtotal = Boolean() rates = Object( properties={ 'id': Integer(), 'tax_country_id': Text(), 'tax_region_id': Integer(), 'tax_postcode': Text(), 'rate': Integer(), 'code': Text(), }) class Index: name = 'vue_storefront_catalog' doc_type = 'taxrule' class Meta: doc_type = "taxrule"
class StationInformation(DocType): """ { u'capacity': 39, u'name': u'W 52 St & 11 Ave', u'short_name': u'6926.01', u'lon': -73.99392888, u'lat': 40.76727216, u'station_id': u'72', u'rental_methods': [u'KEY', u'CREDITCARD'], u'eightd_has_key_dispenser': False, u'region_id': 71 }, """ capacity = Integer() name = Text(analyzer='snowball') short_name = Text(analyzer='snowball') location = GeoPoint() station_id = Text(analyzer='snowball') # TODO can rental_methods be an array? Maybe nested? rental_methods = Text() # [u'KEY', u'CREDITCARD'], eightd_has_key_dispenser = Boolean() region_id = Integer() status_date = Date() class Meta: index = 'stations' """
class _AggregateReportDoc(Document): class Index: name = "dmarc_aggregate" xml_schema = Text() org_name = Text() org_email = Text() org_extra_contact_info = Text() report_id = Text() date_range = Date() date_begin = Date() date_end = Date() errors = Text() published_policy = Object(_PublishedPolicy) source_ip_address = Ip() source_country = Text() source_reverse_dns = Text() source_Base_domain = Text() message_count = Integer disposition = Text() dkim_aligned = Boolean() spf_aligned = Boolean() passed_dmarc = Boolean() policy_overrides = Nested(_PolicyOverride) header_from = Text() envelope_from = Text() envelope_to = Text() dkim_results = Nested(_DKIMResult) spf_results = Nested(_SPFResult) def add_policy_override(self, type_, comment): self.policy_overrides.append( _PolicyOverride(type=type_, comment=comment)) def add_dkim_result(self, domain, selector, result): self.dkim_results.append( _DKIMResult(domain=domain, selector=selector, result=result)) def add_spf_result(self, domain, scope, result): self.spf_results.append( _SPFResult(domain=domain, scope=scope, result=result)) def save(self, **kwargs): self.passed_dmarc = False self.passed_dmarc = self.spf_aligned or self.dkim_aligned return super().save(**kwargs)
class Listing(Document): """Base class containing the common fields.""" access = Text() additional_house_rules = Text() allows_events = Boolean() amenities = Keyword(multi=True) amenity_ids = Keyword(multi=True) avg_rating = Float() bathrooms = Float() bedrooms = Integer() beds = Integer() business_travel_ready = Boolean() city = Text(fields={'keyword': Keyword()}, required=True) country = Text(fields={'keyword': Keyword()}, required=True) coordinates = GeoPoint() description = Text() host_id = Integer(fields={'keyword': Keyword()}) house_rules = Text() interaction = Text() is_hotel = Boolean() monthly_price_factor = Float() name = Text(fields={'keyword': Keyword()}, required=True) neighborhood_overview = Text() person_capacity = Integer() photo_count = Integer() photos = Keyword(multi=True) place_id = Text(fields={'keyword': Keyword()}) price_rate = Float() price_rate_type = Text(fields={'keyword': Keyword()}, required=True) province = Text(fields={'keyword': Keyword()}) rating_accuracy = Float() rating_checkin = Float() rating_cleanliness = Float() rating_communication = Float() rating_location = Float() rating_value = Float() review_count = Integer() reviews = Nested() room_and_property_type = Text(fields={'keyword': Keyword()}, required=True) room_type = Text(fields={'keyword': Keyword()}, required=True) room_type_category = Text(fields={'keyword': Keyword()}, required=True) satisfaction_guest = Float() star_rating = Float() state = Text(fields={'keyword': Keyword()}, required=True) transit = Text() url = Text(fields={'keyword': Keyword()}, required=True) weekly_price_factor = Float()
class Declaration(DocType): """Declaration document. Assumes there's a dynamic mapping with all fields not indexed by default.""" general = Object( properties={ 'full_name_suggest': Completion(preserve_separators=False), 'full_name': String(index='analyzed'), 'name': String(index='analyzed'), 'patronymic': String(index='analyzed'), 'last_name': String(index='analyzed'), 'family_raw': String(index='analyzed'), 'family': Nested( properties={ 'name': String(index='analyzed'), 'relations': String(index='no'), 'inn': String(index='no') }), 'post_raw': String(index='analyzed'), 'post': Object( properties={ 'region': String(index='not_analyzed'), 'office': String(index='not_analyzed'), 'post': String(index='analyzed') }) }) declaration = Object( properties={ 'date': NoneAwareDate(), 'notfull': Boolean(index='no'), 'notfull_lostpages': String(index='no'), 'additional_info': Boolean(index='no'), 'additional_info_text': String(index='no'), 'needs_scancopy_check': Boolean(index='no') }) class Meta: index = 'declarations'
class IndexedPhone(InnerObjectWrapper): """Contact indexed phone model.""" is_primary = Boolean() number = Text() phone_id = Keyword() type = Keyword() uri = Keyword()
class Product(Document): product_id = Integer(required=True) title = Text(required=True) description = Text() in_stock = Boolean() price = Float() stock_count = Integer() image_urls = Nested()
class PoeStash(InnerDoc): accountName = Keyword() lastCharacterName = Keyword() id = Keyword() stash = Text() stashType = Keyword() items = Nested(PoeItem) public = Boolean()
class IndexedResourceTag(InnerObjectWrapper): """Nested tag into indexed resource model.""" date_insert = Date() importance_level = Integer() name = Keyword() tag_id = Keyword() type = Boolean()
class Answer(DocType): page = Text(fields={'raw': Keyword()}) wiki_content = Text() qb_content = Text() is_human = Boolean() class Meta: index = 'qb'
class IndexedInternetAddress(InnerObjectWrapper): """Contact indexed address on internet (email, im) model.""" address = Keyword() email_id = Keyword() is_primary = Boolean() label = Text() type = Keyword()
class Link(Document): url = Text() text = Text() type = Text() crawled = Boolean() class Index: name = INDEX
class Post(DocType): title = Text() title_suggest = Completion() created_at = Date() published = Boolean() category = Text( analyzer=html_strip, fields={'raw': Keyword})
class LCP_Document_Inner_Doc(Inner_Doc): """LCP configuration data.""" port = Integer(required=True) https = Boolean(required=True) endpoint = Text() started = Date() last_heartbeat = Date()
class B2BProductIndex(DocType): django_id = Integer() name = String(analyzer='snowball', fields={'raw': String(index='no')}) description = String(analyzer=html_strip) country = Integer() branches = Integer(multi=True) b2b_categories = Integer(multi=True) organization = Integer() price = Double() is_active = Boolean() is_deleted = Boolean() created_at = Date() @staticmethod def get_model(): from b24online.models import B2BProduct return B2BProduct @classmethod def get_queryset(cls): return cls.get_model().objects.all().prefetch_related('company', 'company__countries', 'branches') @classmethod def to_index(cls, obj): index_instance = cls( django_id=obj.pk, name=obj.name, description=obj.description, organization=obj.company.pk, is_active=obj.is_active, is_deleted=obj.is_deleted, country=obj.company.country.pk, price=obj.cost, created_at=obj.created_at ) index_instance.b2b_categories = list(set([item for category in obj.categories.all() for item in category.get_ancestors(include_self=True).values_list('pk', flat=True)])) index_instance.branches = list(set([item for branch in obj.branches.all() for item in branch.get_ancestors(include_self=True).values_list('pk', flat=True)])) return index_instance
class SerializationDoc(Document): i = Long() b = Boolean() d = Double() bin = Binary() ip = Ip() class Index: name = 'test-serialization'
class PhotoIndex(Document): pk = Integer() city_id = Integer() created = Date() is_published = Boolean() class Meta: index = 'Photo'