class PublicationIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.NgramField(document=True, use_template=True) title = indexes.NgramField(model_attr='titre') bureaux = indexes.FacetMultiValueField(null=True, stored=True) annee = indexes.FacetField(stored=True, null=True) section = indexes.FacetField(stored=True, null=True) date_pub = indexes.DateField(model_attr='date_pub', null=True) def prepare_bureaux(self, obj): try: return [b.nom for b in obj.bureau.all()] except ObjectDoesNotExist as e: print(e) return [u'Non précisé'] def prepare_annee(self, obj): if obj.date_pub is not None: return str(obj.date_pub.year) def get_model(self): return Publication def prepare_section(self, obj): return u"Publication" def index_queryset(self, using=None): return Publication.objects.filter( status__in=[3, 5, 6]).order_by("date_pub")
class BaseCourseIndex(OrganizationsMixin, BaseIndex): key = indexes.CharField(model_attr='key', stored=True) title = indexes.CharField(model_attr='title', boost=TITLE_FIELD_BOOST) title_autocomplete = indexes.NgramField(model_attr='title', boost=TITLE_FIELD_BOOST) authoring_organizations_autocomplete = indexes.NgramField(boost=ORG_FIELD_BOOST) authoring_organization_bodies = indexes.MultiValueField() short_description = indexes.CharField(model_attr='short_description', null=True) full_description = indexes.CharField(model_attr='full_description', null=True) subjects = indexes.MultiValueField(faceted=True) organizations = indexes.MultiValueField(faceted=True) authoring_organizations = indexes.MultiValueField(faceted=True) logo_image_urls = indexes.MultiValueField() sponsoring_organizations = indexes.MultiValueField(faceted=True) level_type = indexes.CharField(null=True, faceted=True) partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True) def prepare_logo_image_urls(self, obj): orgs = obj.authoring_organizations.all() return [org.logo_image_url for org in orgs] def prepare_subjects(self, obj): return [subject.name for subject in obj.subjects.all()] def prepare_organizations(self, obj): return self.prepare_authoring_organizations(obj) + self.prepare_sponsoring_organizations(obj) def prepare_authoring_organizations(self, obj): return self._prepare_organizations(obj.authoring_organizations.all()) def prepare_sponsoring_organizations(self, obj): return self._prepare_organizations(obj.sponsoring_organizations.all()) def prepare_level_type(self, obj): return obj.level_type.name if obj.level_type else None
class UserIndex(indexes.SearchIndex, indexes.Indexable): model = User text = indexes.CharField(document=True, stored=False) fullname = indexes.NgramField() fullname_orderby = indexes.CharField() username = indexes.NgramField(model_attr='username') username_orderby = indexes.CharField(model_attr='username') organization = BooleanField() def get_model(self): return self.model def prepare(self, object): self.prepared_data = super(UserIndex, self).prepare(object) try: is_organization = object.organization is not None except: is_organization = False self.prepared_data['fullname'] = self.prepared_data[ 'fullname_orderby'] = '%s' % (object.get_full_name()) self.prepared_data['organization'] = is_organization self.prepared_data['text'] = '%s %s' % (object.get_full_name(), object.username) return self.prepared_data
class MediaFondsIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #item_acces = indexes.CharField(model_attr='public_access', faceted=True) #item_status = indexes.CharField(model_attr='document_status', faceted=True) digitized = indexes.BooleanField(default=False, faceted=True) #media_type = indexes.CharField(model_attr='media_type', null='None', faceted=True) #recording_context = indexes.CharField(model_attr='recording_context', default='', faceted=True) #physical_format = indexes.CharField(model_attr='physical_format', default='', faceted=True) #content_auto = indexes.EdgeNgramField(model_attr='content') #advance search title = indexes.NgramField(model_attr='title') code = indexes.NgramField(model_attr='code', default='') #location_principal = indexes.CharField(default='', boost=1.05) #location_relation = indexes.CharField() #ethnic_group = indexes.CharField(default='') #instruments = indexes.NgramField(default='') #collectors = indexes.NgramField(model_attr='collector', default='') #recorded_from_date = indexes.DateField(model_attr='recorded_from_year', null=True) #recorded_to_date = indexes.DateField(model_attr='recorded_to_year', null=True) #year_published = indexes.IntegerField(model_attr='year_published', default='') def prepare_digitized(self, obj): return obj.has_mediafile def get_model(self): return MediaFonds
class ListingIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=False) listing_id = indexes.IntegerField(model_attr='id') artist_id = indexes.IntegerField(model_attr='get_artist_id') artist_avatar = indexes.CharField(model_attr='get_artist_avatar') artist_name = indexes.CharField(model_attr='get_artist_name') salon_id = indexes.IntegerField(model_attr='get_salon_id') salon_name = indexes.CharField(model_attr='get_salon_name') salon_avatar = indexes.CharField(model_attr='get_salon_avatar') title = indexes.NgramField(model_attr='title') location = indexes.LocationField(model_attr='get_location') description = indexes.NgramField(model_attr='description') get_picture = indexes.CharField(model_attr='get_picture') metadata = indexes.CharField(model_attr='metadata') currency = indexes.CharField(model_attr='currency') price = indexes.FloatField(model_attr='price') likes = indexes.IntegerField(model_attr='likes') comments = indexes.IntegerField(model_attr='comments') tags = indexes.NgramField(model_attr='get_tags') status = indexes.IntegerField(model_attr='status') gender = indexes.IntegerField(model_attr='gender') rating = indexes.IntegerField(model_attr='get_rating') style = indexes.NgramField(model_attr='get_style') def get_model(self): return Listing def index_queryset(self, using=None): return self.get_model().objects.all().select_related('artist')
class ProgramIndex(BaseIndex, indexes.Indexable, OrganizationsMixin): model = Program uuid = indexes.CharField(model_attr='uuid') title = indexes.CharField(model_attr='title', boost=TITLE_FIELD_BOOST) title_autocomplete = indexes.NgramField(model_attr='title', boost=TITLE_FIELD_BOOST) subtitle = indexes.CharField(model_attr='subtitle') type = indexes.CharField(model_attr='type__name', faceted=True) marketing_url = indexes.CharField(null=True) organizations = indexes.MultiValueField(faceted=True) authoring_organizations = indexes.MultiValueField(faceted=True) authoring_organizations_autocomplete = indexes.NgramField(boost=ORG_FIELD_BOOST) authoring_organization_uuids = indexes.MultiValueField() subject_uuids = indexes.MultiValueField() staff_uuids = indexes.MultiValueField() authoring_organization_bodies = indexes.MultiValueField() credit_backing_organizations = indexes.MultiValueField(faceted=True) card_image_url = indexes.CharField(model_attr='card_image_url', null=True) status = indexes.CharField(model_attr='status', faceted=True) partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True) start = indexes.DateTimeField(model_attr='start', null=True, faceted=True) seat_types = indexes.MultiValueField(model_attr='seat_types', null=True, faceted=True) published = indexes.BooleanField(null=False, faceted=True) min_hours_effort_per_week = indexes.IntegerField(model_attr='min_hours_effort_per_week', null=True) max_hours_effort_per_week = indexes.IntegerField(model_attr='max_hours_effort_per_week', null=True) weeks_to_complete_min = indexes.IntegerField(model_attr='weeks_to_complete_min', null=True) weeks_to_complete_max = indexes.IntegerField(model_attr='weeks_to_complete_max', null=True) language = indexes.MultiValueField(faceted=True) hidden = indexes.BooleanField(model_attr='hidden', faceted=True) is_program_eligible_for_one_click_purchase = indexes.BooleanField( model_attr='is_program_eligible_for_one_click_purchase', null=False ) def prepare_aggregation_key(self, obj): return 'program:{}'.format(obj.uuid) def prepare_published(self, obj): return obj.status == ProgramStatus.Active def prepare_organizations(self, obj): return self.prepare_authoring_organizations(obj) + self.prepare_credit_backing_organizations(obj) def prepare_subject_uuids(self, obj): return set([str(subject.uuid) for course in obj.courses.all() for subject in course.subjects.all()]) def prepare_staff_uuids(self, obj): return set([str(staff.uuid) for course_run in obj.course_runs for staff in course_run.staff.all()]) def prepare_credit_backing_organizations(self, obj): return self._prepare_organizations(obj.credit_backing_organizations.all()) def prepare_marketing_url(self, obj): return obj.marketing_url def prepare_language(self, obj): return [self._prepare_language(language) for language in obj.languages]
class PostIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') def get_model(self): return postblog def index_queryset(self, using=None): return self.get_model().objects.order_by('-timedata')
class ProgramIndex(BaseIndex, indexes.Indexable, OrganizationsMixin): model = Program uuid = indexes.CharField(model_attr='uuid') title = indexes.CharField(model_attr='title', boost=TITLE_FIELD_BOOST) title_autocomplete = indexes.NgramField(model_attr='title', boost=TITLE_FIELD_BOOST) subtitle = indexes.CharField(model_attr='subtitle') type = indexes.CharField(model_attr='type__name', faceted=True) marketing_url = indexes.CharField(null=True) organizations = indexes.MultiValueField(faceted=True) authoring_organizations = indexes.MultiValueField(faceted=True) authoring_organizations_autocomplete = indexes.NgramField( boost=ORG_FIELD_BOOST) authoring_organization_uuids = indexes.MultiValueField() subject_uuids = indexes.MultiValueField() staff_uuids = indexes.MultiValueField() authoring_organization_bodies = indexes.MultiValueField() credit_backing_organizations = indexes.MultiValueField(faceted=True) card_image_url = indexes.CharField(model_attr='card_image_url', null=True) status = indexes.CharField(model_attr='status', faceted=True) partner = indexes.CharField(model_attr='partner__short_code', null=True, faceted=True) start = indexes.DateTimeField(model_attr='start', null=True, faceted=True) seat_types = indexes.MultiValueField(model_attr='seat_types', null=True, faceted=True) published = indexes.BooleanField(null=False, faceted=True) def prepare_published(self, obj): return obj.status == ProgramStatus.Active def prepare_organizations(self, obj): return self.prepare_authoring_organizations( obj) + self.prepare_credit_backing_organizations(obj) def prepare_subject_uuids(self, obj): return [ str(subject.uuid) for course in obj.courses.all() for subject in course.subjects.all() ] def prepare_staff_uuids(self, obj): return [ str(staff.uuid) for course_run in obj.course_runs for staff in course_run.staff.all() ] def prepare_credit_backing_organizations(self, obj): return self._prepare_organizations( obj.credit_backing_organizations.all()) def prepare_marketing_url(self, obj): return obj.marketing_url
class BookIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #给title,content设置索引 book_id = indexes.NgramField(model_attr='book_id') book_name = indexes.NgramField(model_attr='book_name') def get_model(self): return Book def index_queryset(self, using=None): return self.get_model().objects.order_by('book_id')
class ProductIndex(indexes.SearchIndex,indexes.Indexable): text =indexes.CharField(document=True ,use_template=True, template_name="search/indexes/search/product_search.txt") name =indexes.NgramField(model_attr='name') content_auto = indexes.NgramField(model_attr='name') def get_model(self): return Product def index_query(self,using=None): return self.get_model().objects.all()
class PostIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #固定字段 #给title,content设置索引 title = indexes.NgramField(model_attr='title') #必须和model的字段对应(用于搜索的字段) content = indexes.NgramField(model_attr='content') #必须和model的字段对应(用于搜索的字段) def get_model(self): #重写父类方法 return Post def index_queryset(self, using=None): return self.get_model().objects.order_by('-created')
class PostIndex(indexes.SearchIndex,indexes.Indexable): #页面中的 text = indexes.CharField(document=True, use_template=True) #给title,content设置索引 对应模型类的属性名 title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') # 重写: 返回搜索的模型类 def get_model(self): return Post def index_queryset(self, using=None): return self.get_model().objects.order_by('-created')
class ProductIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) title = indexes.NgramField(model_attr='name') tags = indexes.NgramField(model_attr='tags') lastupdate = indexes.DateTimeField(model_attr='modified') def get_model(self): return Product def index_queryset(self, using=None): """Used when the entire index for model is updated.""" return Product.objects.none()
class HomeIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #给title,content设置索引 source_name = indexes.NgramField(model_attr='source_name') source_name = indexes.NgramField(model_attr='source_name') def get_model(self): return CustomerSource def index_queryset(self, using=None): return self.get_model().objects.order_by('-created')
class InformationIndex(indexes.SearchIndex,indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #给title,content设置索引 iname = indexes.NgramField(model_attr='iname') iauthor = indexes.NgramField(model_attr='iauthor') def get_model(self): return Information def index_queryset(self, using=None): return self.get_model().objects.order_by('inum')
class PostIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) # 给搜索字段设置索引:title,content title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') def get_model(self): return Post def index_queryset(self, using=None): return self.get_model().objects.order_by('-created')
class ArticleIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #给title,content设置索引 title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') def get_model(self): return Article def index_queryset(self, using=None): return self.get_model().objects.order_by('-creation_time')
class PostIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) # 给title,content设置索引 bk_name = indexes.NgramField(model_attr='bk_name') intro = indexes.NgramField(model_attr='intro') def get_model(self): return MainprojectBooks def index_queryset(self, using=None): return self.get_model().objects.order_by('-bk_id')
class PostIndex(indexes.SearchIndex, indexes.Indexable): #固定字段 text = indexes.CharField(document=True, use_template=True) #设置索引 title = indexes.NgramField(model_attr="title") content = indexes.NgramField(model_attr="content") def get_model(self): return models.Post def get_queryset(self, using=None): return self.get_model().objects.order_by("-created")
class BlogIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) # 给title,content设置索引 title = indexes.NgramField(model_attr='title') abstract = indexes.NgramField(model_attr='abstract') content = indexes.NgramField(model_attr='content') def get_model(self): return Blog def index_queryset(self, using=None): return self.get_model().objects.all()
class PostIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) # 固定字段 # 给title, content设置索引 # model_attr='title' 对应模型类当中的那个字段 title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') def get_model(self): # 重写父类的方法 return Post def index_queryset(self, using=None): return self.get_model().objects.order_by('-created')
class BlogContentIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) #给模型类中的字段设置索引 title = indexes.NgramField(model_attr='title') content = indexes.NgramField(model_attr='content') def get_model(self): #重写index索引方法 return BlogContent def index_queryset(self, using=None): return self.get_model().objects.order_by( '-creat_time') #返回模型类查询的结果并以某个字段排序
class TaxonIndex(indexes.SearchIndex, indexes.Indexable): model_pk = indexes.IntegerField(model_attr='pk') text = indexes.EdgeNgramField(document=True, use_template=True) canonical_name = indexes.NgramField(indexed=True, model_attr='canonical_name') canonical_name_char = indexes.CharField(indexed=True, model_attr='canonical_name') scientific_name = indexes.NgramField(indexed=True, model_attr='scientific_name') scientific_name_auto = indexes.EdgeNgramField(model_attr='scientific_name') canonical_name_auto = indexes.EdgeNgramField(model_attr='canonical_name') author = indexes.CharField(indexed=True, model_attr='author', null=True) iucn_status_category = indexes.CharField(indexed=True) id = indexes.IntegerField(indexed=True) validated_collections = indexes.CharField() def prepare_validated_collections(self, obj): bios = BiologicalCollectionRecord.objects.filter( taxonomy=obj.pk, validated=True).values_list('pk', flat=True).distinct() return ','.join(str(bio) for bio in bios) def prepare_iucn_status_category(self, obj): if obj.iucn_status: return obj.iucn_status.get_status() else: return '' def prepare_id(self, obj): if obj.pk: return obj.pk return 0 class Meta: app_label = 'bims' def index_queryset(self, using=None): """Used when the entire index for model is updated.""" return self.get_model().objects.all() def get_model(self): return Taxonomy
class PublicacionIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.NgramField(document=True, use_template=True) titulo = indexes.NgramField(model_attr='titulo') resumen = indexes.NgramField(model_attr='resumen', null=True) tematica = indexes.NgramField(model_attr='tematica', null=True) def get_model(self): return Publicacion def prepare_tematica(self, obj): return obj.tematica.nombre def index_queryset(self, using=None): return self.get_model().objects.order_by('-id')
class ResourceIndex(indexes.SearchIndex,indexes.Indexable): text = indexes.CharField(document=True, use_template=True) resource_type = indexes.CharField(model_attr='resource_type', faceted=True) content_auto = indexes.NgramField(model_attr='prefLabel') pref_labels = indexes.CharField(model_attr='all_preferred_labels', boost=2.0) alt_labels = indexes.CharField(model_attr='all_alternate_labels', boost=1.5) scope_notes = indexes.CharField(model_attr='all_scope_notes') #relationships = indexes.CharField(model_attr='all_relationships') def get_model(self): return Resource def index_queryset(self, using=None): """Used when the entire index for model is updated.""" return self.get_model().objects.all() #class PropertyIndex(indexes.SearchIndex,indexes.Indexable): # text = indexes.CharField(document=True, use_template=True) # property_type = indexes.CharField(model_attr='property_type', faceted=True) # # def get_model(self): # return Property # # def index_queryset(self, using=None): # return self.get_model().objects.all() # #class RelationshipIndex(indexes.SearchIndex,indexes.Indexable): # text = indexes.CharField(document=True, use_template=True) # relationship_type = indexes.CharField(model_attr='relationship_type', faceted=True) # # def get_model(self): # return Relationship # # def index_queryset(self, using=None): # return self.get_model().objects.all()
class CourseIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.NgramField(document=True, use_template=True) no = indexes.CharField(model_attr='no') code = indexes.CharField(model_attr='code') eng_title = indexes.CharField(model_attr='eng_title') chi_title = indexes.CharField(model_attr='chi_title') note = indexes.CharField(model_attr='note') objective = indexes.CharField(model_attr='objective') time = indexes.CharField(model_attr='time') time_token = indexes.CharField(model_attr='time_token') teacher = indexes.CharField(model_attr='teacher') room = indexes.CharField(model_attr='room') ge = indexes.CharField(model_attr='ge') credit = indexes.IntegerField(model_attr='credit') limit = indexes.IntegerField(model_attr='limit') prerequisite = indexes.BooleanField(model_attr='prerequisite') hit = indexes.IntegerField(model_attr='hit') syllabus = indexes.CharField(model_attr='syllabus') def get_model(self): return Course
class BaseSearchConfig(indexes.SearchIndex, indexes.Indexable): """ Base config class to provide list of attributes that sub class must provide """ text = indexes.CharField(document=True, use_template=False) text_ngram = indexes.NgramField(document=False, use_template=False) # admin setting list_per_page = 50 @property def model(self): raise NotImplementedError("Config class must provide model attribute") @property def list_display(self): raise NotImplementedError( "Config class must provide list_display fields") def get_model(self): return self.model def prepare_text(self, obj): raise NotImplementedError( "Config class must provide prepare_text method for index") def prepare_text_ngram(self, obj): return self.prepare_text(obj)
class PublicBodyIndex(SearchIndex, indexes.Indexable): text = indexes.EdgeNgramField(document=True, use_template=True) name = indexes.CharField(model_attr='name', boost=1.5) name_auto = indexes.NgramField(model_attr='name') jurisdiction = indexes.FacetCharField(model_attr='jurisdiction__name', default='') tags = indexes.FacetMultiValueField() url = indexes.CharField(model_attr='get_absolute_url') def get_model(self): return PublicBody def index_queryset(self, **kwargs): """Used when the entire index for model is updated.""" return self.get_model().objects.get_for_search_index() def prepare_tags(self, obj): return [t.name for t in obj.tags.all()] def prepare(self, obj): data = super(PublicBodyIndex, self).prepare(obj) if obj.classification in PUBLIC_BODY_BOOSTS: data['boost'] = PUBLIC_BODY_BOOSTS[obj.classification] print("Boosting %s at %f" % (obj, data['boost'])) return data
class ReportIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.EdgeNgramField(document=True, use_template=True) part_number = indexes.NgramField(model_attr='part_number') created_at = indexes.DateTimeField(model_attr='created_at') def get_model(self): return Report
class ResourceIndex(indexes.SearchIndex, indexes.Indexable): text = indexes.NgramField(document=True, use_template=True) name = indexes.CharField(model_attr='name') data_types = indexes.MultiValueField(faceted=True) categories = indexes.MultiValueField(faceted=True) cities = indexes.MultiValueField(faceted=True) counties = indexes.MultiValueField(faceted=True) def get_model(self): return Resource def index_queryset(self, using=None): return self.get_model().objects.all() def prepare_categories(self, obj): return [category.name for category in obj.categories.all()] def prepare_cities(self, obj): return [city.name for city in obj.cities.all()] def prepare_counties(self, obj): return [county.name for county in obj.counties.all()] def prepare_data_types(self, obj): return [type_.name for type_ in obj.data_types.all()]