Exemplo n.º 1
0
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    auteur = indexes.CharField(model_attr='auteur')
    categorie = indexes.CharField(model_attr='categorie')
    contenu = indexes.CharField(model_attr='contenu')
    tags = indexes.MultiValueField(model_attr='tags__nom')
    auteurs_commentaires = indexes.MultiValueField(
        model_attr='commentaires__auteur__full_name')

    def get_model(self):
        return Article

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()
Exemplo n.º 2
0
class MarketingFailedContactIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(
        document=True, use_template=True, template_name='search/failed_contact_emails.txt')

    id = indexes.CharField(model_attr='id')
    email = indexes.EdgeNgramField(model_attr='email')
    email_domain = indexes.EdgeNgramField()
    name = indexes.CharField(model_attr='name')
    company_name = indexes.CharField()
    created_on = indexes.CharField(model_attr='created_on')
    created_on_arrow = indexes.CharField(model_attr='created_on_arrow')
    created_by = indexes.CharField()
    created_by_id = indexes.CharField()
    contact_lists = indexes.MultiValueField()
    contact_lists_id = indexes.MultiValueField()
    contact_lists_name = indexes.MultiValueField()
    contact_lists_count = indexes.IntegerField()


    def get_model(self):
        return FailedContact

    def prepare_email_domain(self, obj):
        return obj.email.split('@')[-1]

    def prepare_contact_lists(self, obj):
        return [[contact_list.id, contact_list.name if contact_list.name else ''] for contact_list in obj.contact_list.all()]

    def prepare_contact_lists_id(self, obj):
        return [contact_list.id for contact_list in obj.contact_list.all().order_by('id')]

    def prepare_contact_lists_name(self, obj):
        return [contact_list.name for contact_list in obj.contact_list.all().order_by('id')]

    def prepare_company_name(self, obj):
        return obj.company_name if obj.company_name else ''

    def prepare_created_by(self, obj):
        return obj.created_by.email if obj.created_by else ''

    def prepare_created_by_id(self, obj):
        return obj.created_by.id if obj.created_by else ''

    def prepare_contact_lists_count(self, obj):
        return obj.contact_list.count()

    def index_queryset(self, using=None):
        return self.get_model().objects.all()
Exemplo n.º 3
0
class UserIndex(indexes.ModelSearchIndex, indexes.Indexable):

    content_type = indexes.CharField(default='User')
    user_roles = indexes.MultiValueField(indexed=True, stored=True)
    interests = indexes.MultiValueField(indexed=True, stored=True)
    country = indexes.CharField(indexed=True, stored=True)
    has_relation = indexes.BooleanField(indexed=True,
                                        stored=True,
                                        default=False)

    is_published = indexes.BooleanField(indexed=True, stored=True)

    class Meta:
        model = get_user_model()
        fields_to_skip = [
            '_total_follower', '_total_following', '_total_love',
            '_total_testify', 'password'
        ]
        excludes = ['password']

    def index_queryset(self, using=None):
        "Used when the entire index for model is updated."
        return self.get_model().objects.filter()

    def prepare_user_roles(self, object):
        return [inst.permalink for inst in object.user_roles.all()]

    def prepare_interests(self, object):
        return [inst.permalink for inst in object.interests.all()]

    def prepare_country(self, object):

        if object.country:
            return object.country.permalink
        else:
            return ''

    def prepare_has_relation(self, object):
        for Model in BaseRelation.__subclasses__():
            if Model.objects.filter(Q(dst_id=object.id)
                                    | Q(src_id=object.id)).count():
                return True

        return False

    def prepare_is_published(self, object):
        # is_published = indexes.BooleanField(indexed=True, stored=True)
        return bool(object.is_active)
Exemplo n.º 4
0
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)

    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 [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

    def prepare_language(self, obj):
        return [self._prepare_language(language) for language in obj.languages]
Exemplo n.º 5
0
class AdIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True, template_name='search/indexes/ad/ad_text.txt')

    #model fields
    title = indexes.CharField(model_attr='title')
    short_description = indexes.CharField(model_attr='short_description')
    slug = indexes.CharField(model_attr='slug')
    price = indexes.FloatField(model_attr='price')
    pub_date = indexes.DateTimeField(model_attr='pub_date')
    tags = indexes.CharField()
    image1 = indexes.CharField()
    #localities = indexes.CharField(faceted=True)
    #provinces = indexes.CharField(faceted=True)
    #administrative_area_level_2 = indexes.CharField(faceted=True)
    categories = indexes.MultiValueField(faceted=True)
    groups = indexes.MultiValueField(faceted=True)

    location = indexes.LocationField()

    def prepare_location(self, obj):
        # If you're just storing the floats...
        return "%s,%s" % (obj.locations.first().lat, obj.locations.first().lng)

    def prepare_image1(self, obj):
        return str(obj.images.first().image)

    def prepare(self, object):
        self.prepared_data = super(AdIndex, self).prepare(object)

        self.prepared_data['tags'] = [tag.name for tag in object.tags.all()]
        self.prepared_data['categories'] = [category.slug for category in object.categories.all()]
        self.prepared_data['groups'] = [group.slug for group in object.groups.all()]
        #self.prepared_data['categories_slug'] = [category.slug for category in object.categories.all()]
        #self.prepared_data['localities'] = [location.locality for location in object.locations.all()]
        #self.prepared_data['provinces'] = [location.administrative_area_level_1 for location in object.locations.all()]
        #self.prepared_data['administrative_area_level_2'] = [location.administrative_area_level_2 for location in object.locations.all()]

        return self.prepared_data

    class Meta:
        model = Ad

    def get_model(self):
        return Ad

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=datetime.datetime.now()).filter(status=1)
class DocumentIndex(indexes.Indexable, indexes.SearchIndex):
    """Search index used by Haystack"""
    doc_type = indexes.CharField(model_attr='doc_type')
    version = indexes.CharField(model_attr='version', null=True)
    label_string = indexes.CharField(model_attr='label_string')
    text = indexes.CharField(model_attr='text')
    is_root = indexes.BooleanField(model_attr='root')
    is_subpart = indexes.BooleanField()
    title = indexes.MultiValueField()

    regulation = indexes.CharField(model_attr='label_string')
    text = indexes.CharField(document=True, use_template=True)

    def prepare_regulation(self, obj):
        return obj.label_string.split('-')[0]

    def prepare_is_subpart(self, obj):
        return ('Subpart' in obj.label_string or 'Subjgrp' in obj.label_string)

    def prepare_title(self, obj):
        """For compatibility reasons, we make this a singleton list"""
        if obj.title:
            return [obj.title]
        else:
            return []

    def get_model(self):
        return models.Document
Exemplo n.º 7
0
class PostIndex(indexes.SearchIndex, indexes.Indexable):
    """Indexes Post data"""
    text = indexes.CharField(document=True, use_template=True)
    txt = indexes.CharField(model_attr='text')
    author = indexes.CharField(model_attr='author')

    pubdate = indexes.DateTimeField(model_attr='pubdate',
                                    stored=True,
                                    indexed=False)
    topic_title = indexes.CharField(stored=True, indexed=False)
    topic_author = indexes.CharField(stored=True, indexed=False)
    topic_forum = indexes.CharField(stored=True, indexed=False)

    # Groups authorized to read this topic.
    # If a group "public" is defined, the forum is public (and anyone can read it).
    permissions = indexes.MultiValueField()

    def get_model(self):
        return Post

    def index_queryset(self, using=None):
        return self.get_model().objects.filter(is_visible=True, position__gt=1)

    def prepare_topic_title(self, obj):
        return obj.topic.title

    def prepare_topic_author(self, obj):
        return obj.topic.author

    def prepare_topic_forum(self, obj):
        return obj.topic.forum

    def prepare_permissions(self, obj):
        return [group.name
                for group in obj.topic.forum.group.all()] or "public"
Exemplo n.º 8
0
class CourseIndex(BaseCourseIndex, indexes.Indexable):
    model = Course

    course_runs = indexes.MultiValueField()
    expected_learning_items = indexes.MultiValueField()

    prerequisites = indexes.MultiValueField(faceted=True)

    def prepare_course_runs(self, obj):
        return [course_run.key for course_run in obj.course_runs.all()]

    def prepare_expected_learning_items(self, obj):
        return [item.value for item in obj.expected_learning_items.all()]

    def prepare_prerequisites(self, obj):
        return [prerequisite.name for prerequisite in obj.prerequisites.all()]
Exemplo n.º 9
0
class HelpFileIndex(TendenciBaseSearchIndex, indexes.Indexable):
    question = indexes.CharField(model_attr='question')
    answer = indexes.CharField(model_attr='answer')
    syndicate = indexes.BooleanField(model_attr='syndicate', null=True)
    topic = indexes.MultiValueField()

    # RSS field
    can_syndicate = indexes.BooleanField(null=True)
    order = indexes.DateTimeField()

    @classmethod
    def get_model(self):
        return HelpFile

    def prepare_answer(self, obj):
        return strip_html(obj.answer)

    def prepare_topic(self, obj):
        return [topic.pk for topic in obj.topics.all()]

    def prepare_can_syndicate(self, obj):
        return obj.allow_anonymous_view and obj.syndicate \
                and obj.status == 1 and obj.status_detail == 'active' \
                and obj.create_dt <= datetime.now()

    def prepare_order(self, obj):
        return obj.create_dt
Exemplo n.º 10
0
class ThreadIndex(get_base_index()):
    haystack_use_for_indexing = ENABLE_HAYSTACK_SEARCH

    title = indexes.CharField()
    tags = indexes.MultiValueField()

    def get_language(self, obj):
        return obj.language_code

    def get_model(self):
        return get_model('askbot', 'Thread')

    def get_index_kwargs(self, language):
        kwargs = {'deleted': False}

        if self.i18n_enabled:
            kwargs['language_code__startswith'] = language
        return kwargs

    def prepare_tags(self, obj):
        return [tag.name for tag in obj.tags.all()]

    def should_update(self, instance, **kwargs):
        # Update only if thread is not deleted
        return not instance.deleted
Exemplo n.º 11
0
class CustomUserIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    position = indexes.CharField()
    bio = indexes.CharField()
    skills = indexes.MultiValueField()
    #    image = indexes.ImageField()
    skill_area1_title = indexes.CharField()
    skill_area1 = indexes.CharField()
    skill_area2_title = indexes.CharField()
    skill_area2 = indexes.CharField()
    skill_area3_title = indexes.CharField()
    skill_area3 = indexes.CharField()
    skill_area4_title = indexes.CharField()
    skill_area4 = indexes.CharField()
    skill_area5_title = indexes.CharField()
    skill_area5 = indexes.CharField()
    software_hardware = indexes.CharField()
    availability = indexes.CharField()
    rate = indexes.CharField()
    expert = indexes.BooleanField()
    gives_tutorials = indexes.BooleanField()
    tutorial_area = indexes.CharField()

    def get_model(self):
        return CustomUser

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.all()

    def prepare_tags(self, obj):
        return [skill.name for skill in obj.skills.all()]
Exemplo n.º 12
0
class PatronIndex(indexes.Indexable, indexes.SearchIndex):
    text = indexes.CharField(document=True, use_template=False)
    location = indexes.LocationField(model_attr='default_address__position',
                                     null=True)

    username = indexes.CharField(model_attr='username')
    avatar = indexes.CharField(null=True)
    sites = indexes.MultiValueField(faceted=True)
    date_joined_date = indexes.DateField(model_attr='date_joined__date')
    url = indexes.CharField(model_attr='get_absolute_url')

    def get_updated_field(self):
        return "date_joined_date"

    def prepare_sites(self, obj):
        return tuple(obj.sites.values_list('id', flat=True))

    def prepare_avatar(self, obj):
        # FIXME: should we really check for obj.avatar here?
        return obj.thumbnail.url if obj.avatar and obj.thumbnail else None

    def get_model(self):
        return Patron

    def index_queryset(self, using=None):
        return self.get_model().on_site.select_related(
            'default_address__position')
Exemplo n.º 13
0
class ModelWithManyToManyFieldAndAttributeLookupSearchIndex(
        indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    related_models = indexes.MultiValueField(model_attr="related_models__name")

    def get_model(self):
        return ManyToManyLeftSideModel
Exemplo n.º 14
0
class DocumentIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr="title", boost=2)
    # https://github.com/toastdriven/django-haystack/issues/569 - Necessary for sorting
    title_sortable = indexes.CharField(indexed=False)
    oid = indexes.IntegerField(model_attr='id')
    type = indexes.CharField(faceted=True)
    bbox_left = indexes.FloatField(model_attr="bbox_x0", null=True)
    bbox_right = indexes.FloatField(model_attr="bbox_x1", null=True)
    bbox_top = indexes.FloatField(model_attr="bbox_y0", null=True)
    bbox_bottom = indexes.FloatField(model_attr="bbox_y1", null=True)
    abstract = indexes.CharField(model_attr='abstract', boost=1.5)
    owner = indexes.CharField(model_attr="owner", faceted=True, null=True)
    modified = indexes.DateTimeField(model_attr="date")
    detail_url = indexes.CharField(model_attr="get_absolute_url")
    popular_count = indexes.IntegerField(model_attr="popular_count", default=0)
    keywords = indexes.MultiValueField(model_attr="keyword_list", indexed=False, null=True, faceted=True)
    thumbnail_url = indexes.CharField(model_attr="thumbnail_url", null=True)

    def get_model(self):
        return Project

    def prepare_type(self, obj):
        return "document"

    def prepare_title_sortable(self, obj):
        return obj.title.lower().lstrip()
Exemplo n.º 15
0
class AreaIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    uLocStr = indexes.CharField()
    locationId = indexes.IntegerField(model_attr='id')
    locationType = indexes.CharField()
    parent = indexes.IntegerField(model_attr='environment__id')
    name = indexes.CharField(model_attr='name', boost=2.0, faceted=True)
    tags = indexes.MultiValueField(boost=2.0, faceted=True)
    description = indexes.CharField()
    timestamp = indexes.DateTimeField(model_attr='timestamp')

    def get_model(self):
        return Area

    def prepare_uLocStr(self, obj):
        return "area" + str(obj.id)

    def prepare_locationType(self, obj):
        return "area"

    def prepare_tags(self, obj):
        return obj.tags.getList()

    def prepare_description(self, obj):
        desc = u''
        for feat in obj.features.all():
            if feat.category == "default":
                desc += feat.data.to_serializable()

        return desc

    def index_queryset(self):
        ## Used when the entire index for model is updated.
        return self.get_model().objects.filter(
            timestamp__lte=datetime.datetime.now())
Exemplo n.º 16
0
class VoteIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    uid = indexes.CharField(model_attr='uid')
    category = indexes.CharField(default=None, model_attr='category')
    content = indexes.CharField(model_attr='content')
    conflict = indexes.BooleanField(default=None, model_attr='conflict')
    ad = indexes.IntegerField(model_attr='sitting__ad')
    date = indexes.DateField(model_attr='sitting__date')
    vote_seq = indexes.CharField(model_attr='vote_seq')
    result = indexes.CharField(model_attr='result')
    results = indexes.CharField(model_attr='results')
    tags = indexes.MultiValueField()
    tags_num = indexes.IntegerField()

    def get_model(self):
        return Vote

    def prepare_tags(self, obj):
        return [
                   (x.title, x.votes, )
                   for x in
                   Standpoint.objects.filter(vote=obj)\
                                     .annotate(votes=Count('user_standpoint__id'))\
                                     .order_by('-votes')
               ]

    def prepare_tags_num(self, obj):
        return Standpoint.objects.filter(vote=obj)\
                                 .count()
Exemplo n.º 17
0
class PageIndex(indexes.SearchIndex, indexes.Indexable):
    title = indexes.CharField(model_attr='title')
    date = indexes.DateTimeField(model_attr='publish_date')
    description = indexes.CharField(model_attr='description')
    keywords = indexes.MultiValueField()
    get_absolute_url = indexes.CharField(model_attr='get_absolute_url')
    text = indexes.CharField(document=True)

    def full_prepare(self, *args, **kwargs):
        widgy_pre_index.send(sender=self)
        return super(PageIndex, self).full_prepare(*args, **kwargs)

    def get_model(self):
        return WidgyPage

    def index_queryset(self, using=None):
        return self.get_model().objects.published()

    def prepare_text(self, obj):
        context = {'_current_page': obj.page_ptr, 'page': obj.page_ptr}
        html = render_root(context, obj, 'root_node')
        content = html_to_plaintext(html)
        keywords = ' '.join(self.prepare_keywords(obj))
        return ' '.join([obj.title, keywords, obj.description, content])

    def prepare_keywords(self, obj):
        return [unicode(k) for k in obj.keywords.all()]
Exemplo n.º 18
0
class QuestionIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title', boost=1.125)
    title_auto = indexes.EdgeNgramField(model_attr='title')
    model_content = indexes.CharField(model_attr='content')
    answer = indexes.CharField(null=True)
    answered = indexes.BooleanField(model_attr='answered')
    user_email = indexes.CharField(model_attr='user')
    pub_date = indexes.DateTimeField(model_attr='pub_date')
    tags = indexes.MultiValueField(model_attr='tag_list',
                                   faceted=True,
                                   boost=1.5)
    get_absolute_url = indexes.CharField(null=True)

    def get_model(self):
        return Question

    def prepare_get_absolute_url(self, obj):
        return "%s" % obj.get_absolute_url()

    def prepare_user_email(self, obj):
        return "%s" % obj.user_email

    def prepare_answer(self, obj):
        try:
            return textify("%s" %
                           obj.answer_set.all().filter(accepted=True)[0])
        except IndexError:
            return None

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(pub_date__lte=timezone.now())
Exemplo n.º 19
0
class BookIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=False)
    genres = indexes.MultiValueField(null=True)

    def get_model(self):
        return Book

    def index_queryset(self, using=None):
        return self.get_model().objects.prefetch_related(
            'authors', 'comments', 'identifiers', 'languages')

    def prepare_genres(self, obj):
        return ','.join(obj.genres) or None

    def prepare(self, obj):
        self.prepared_data = super(BookIndex, self).prepare(obj)
        text = [obj.title, obj.isbn, obj.uuid]
        if obj.series:
            text.extend([obj.series])
        authors = [author.name for author in obj.authors.all()]
        authors.extend(map(unidecode, authors))
        text.extend(set(authors))
        text.extend(obj.tags.all())
        text.extend(obj.publishers.all())
        text.extend(['lang:%s' % l.lang_code for l in obj.languages.all()])
        text.extend(['publisher:%s' % p.name for p in obj.publishers.all()])
        self.prepared_data['text'] = u' '.join(map(unicode, text))
        return self.prepared_data
Exemplo n.º 20
0
class DocumentIndex(CelerySearchIndex, indexes.Indexable):
    text = indexes.CharField(use_template=True, document=True)
    datetime = indexes.DateTimeField(model_attr="data__datetime")
    parent_ids = indexes.MultiValueField()
    suggestions = indexes.FacetCharField()

    def get_model(self):
        return Document

    def index_queryset(self, using=None):
        return self.get_model().objects.all().exclude(parent=None)

    def prepare_parent_ids(self, obj):
        return _parent_ids(obj)

    def prepare(self, obj):
        data = super().prepare(obj)
        file_obj = obj.data.file
        extracted_data = self.get_backend().extract_file_contents(file_obj)
        t = loader.select_template(
            ('search/indexes/documents/document_text.txt', ))
        data['text'] = t.render(
            Context({
                'object': obj,
                'extracted': extracted_data
            }))
        # data['suggestions'] = data['text'][:30000]

        return data
Exemplo n.º 21
0
class PersonIndex(BaseIndex, indexes.Indexable):
    model = Person
    uuid = indexes.CharField(model_attr='uuid')
    salutation = indexes.CharField(model_attr='salutation', null=True)
    full_name = indexes.CharField(model_attr='full_name')
    partner = indexes.CharField(null=True)
    bio = indexes.CharField(model_attr='bio', null=True)
    bio_language = indexes.CharField(model_attr='bio_language', null=True)
    get_profile_image_url = indexes.CharField(
        model_attr='get_profile_image_url', null=True)
    position = indexes.MultiValueField()

    def prepare_aggregation_key(self, obj):
        return 'person:{}'.format(obj.uuid)

    def prepare_position(self, obj):
        try:
            position = Position.objects.get(person=obj)
        except Position.DoesNotExist:
            return []
        return [position.title, position.organization_override]

    def prepare_bio_language(self, obj):
        if obj.bio_language:
            return obj.bio_language.name
        return
Exemplo n.º 22
0
class FeatureIndex(indexes.SearchIndex, indexes.Indexable):
    """Feature search index definition."""

    # This is a workaround for the Haystack limitation that all document=True fields
    # on all indices in the whole application must be of the same type. Therefore, we
    # use a CharField and have a separate MultiValueField.
    text = indexes.CharField(document=True)
    genes = indexes.MultiValueField()
    source = indexes.CharField(model_attr='source')

    name_auto = indexes.EdgeNgramField(boost=10.0)
    aliases_auto = indexes.EdgeNgramField()

    def get_model(self):
        """Model to index."""
        return Feature

    def prepare_text(self, obj):
        """Prepare the value for the 'text' field during indexing."""
        return '\n'.join(self.prepare_genes(obj))

    def prepare_genes(self, obj):
        """Prepare the value for the 'genes' field during indexing."""
        return [obj.name, obj.feature_id] + obj.aliases

    def prepare_name_auto(self, obj):
        """Prepare the value for the 'name_auto' field during indexing."""
        return ' '.join([obj.name, obj.feature_id])

    def prepare_aliases_auto(self, obj):
        """Prepare the value for the 'aliases_auto' field during indexing."""
        return ' '.join(obj.aliases)
Exemplo n.º 23
0
class TextIndex(indexes.SearchIndex, indexes.Indexable):
    """
    Index annotatable texts.
    """
    text = indexes.CharField(document=True, use_template=False)
    title = indexes.EdgeNgramField(model_attr='title', indexed=False)
    created = indexes.DateField(model_attr='created',
                                faceted=True,
                                indexed=False,
                                null=True)
    added = indexes.DateField(model_attr='added', faceted=True, indexed=False)
    addedBy = indexes.CharField(model_attr='addedBy')
    uri = indexes.CharField(model_attr='id')
    relation_count = indexes.CharField(model_attr='relation_count')
    collections = indexes.MultiValueField(indexed=False,
                                          faceted=True,
                                          null=True)

    def get_model(self):
        """ Get model to be used for indexing """
        return Text

    def index_queryset(self, using=None):
        """ Used when entire index for model is updated """
        return self.get_model().objects.all()

    def prepare_text(self, instance):
        return instance.title

    def prepare_added(self, instance):
        return instance.added.date()

    def prepare_collections(self, instance):
        return [c.id for c in instance.partOf.all()]
Exemplo n.º 24
0
class UserIndex(BaseSearchIndex, indexes.Indexable):
    """A Haystack search index for users."""

    model = User
    local_site_attr = 'local_site'

    username = indexes.CharField(model_attr='username')
    email = indexes.CharField(model_attr='email')
    full_name = indexes.CharField(model_attr='get_full_name')
    url = indexes.CharField(model_attr='get_absolute_url')
    show_profile = indexes.BooleanField(model_attr='is_profile_visible')
    groups = indexes.MultiValueField(indexed=False)

    def index_queryset(self, using=None):
        """Query the list of users for the index.

        All active users will be returned.
        """
        return self.get_model().objects.filter(is_active=True)

    def prepare_groups(self, user):
        """Prepare a user's list of groups for the index.

        Only publicly-accessible groups will be stored in the index.
        """
        return [
            group.name
            for group in user.review_groups.filter(invite_only=False)
        ]
Exemplo n.º 25
0
class HelpFileIndex(TendenciBaseSearchIndex):
    question = indexes.CharField(model_attr='question')
    answer = indexes.CharField(model_attr='answer')
    syndicate = indexes.BooleanField(model_attr='syndicate')
    topic = indexes.MultiValueField()
    
    # RSS field
    can_syndicate = indexes.BooleanField()
    order = indexes.DateTimeField()
    
    def prepare_answer(self, obj):
        answer = obj.answer
        answer = strip_tags(answer)
        answer = strip_entities(answer)
        return answer
    
    def prepare_topic(self, obj):
        return [topic.pk for topic in obj.topics.all()]

    def prepare_can_syndicate(self, obj):
        return obj.allow_anonymous_view and obj.syndicate \
                and obj.status == 1  and obj.status_detail == 'active' \
                and obj.create_dt <= datetime.now()

    def prepare_order(self, obj):
        return obj.create_dt
Exemplo n.º 26
0
class AllTypesWhooshMockSearchIndex(indexes.SearchIndex):
    text = indexes.CharField(document=True, use_template=True)
    name = indexes.CharField(model_attr='author', indexed=False)
    pub_date = indexes.DateField(model_attr='pub_date')
    sites = indexes.MultiValueField()
    seen_count = indexes.IntegerField(indexed=False)
    is_active = indexes.BooleanField(default=True)
Exemplo n.º 27
0
class ExperimentIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    experiment_id_stored = indexes.IntegerField(model_attr='id')
    experiment_title = indexes.CharField(model_attr='title')
    experiment_description = indexes.CharField(model_attr='description')
    experiment_created_time = indexes.DateTimeField(model_attr='created_time')
    experiment_start_time = indexes.DateTimeField(model_attr='start_time', default=None)
    experiment_end_time = indexes.DateTimeField(model_attr='end_time', default=None)
    experiment_update_time = indexes.DateTimeField(model_attr='update_time', default=None)
    experiment_institution_name = indexes.CharField(model_attr='institution_name', default=None)
    experiment_creator=indexes.CharField(model_attr='created_by__username')
    experiment_author = indexes.MultiValueField()

    def prepare_text(self, obj):
        return '{} {}'.format(obj.title.encode('utf-8'), obj.description.encode('utf-8'))

    def prepare_experimentauthor(self, obj):
        return [author.author for author in obj.experimentauthor_set.all()]

    def get_model(self):
        return Experiment

    def index_queryset(self, using=None):
        """Used when the entire index for model is updated."""
        return self.get_model().objects.filter(created_time__lte=datetime.datetime.now())
Exemplo n.º 28
0
class ChapterIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    # A Chapter belongs to a Part (big-tuto) **or** a Tutorial (mini-tuto)
    part = indexes.CharField(model_attr='part', null=True)
    tutorial = indexes.CharField(model_attr='tutorial', null=True)

    # Groups authorized to read this topic.
    # If a group "public" is defined, the forum is public (and anyone can read it).
    permissions = indexes.MultiValueField()

    def get_model(self):
        return Chapter

    def index_queryset(self, using=None):
        """Only chapters online."""
        published_content = GetPublished().get_published_content()

        return self.get_model().objects.filter(
            Q(tutorial__sha_public__isnull=False)
            | Q(part__tutorial__sha_public__isnull=False),
            id__in=published_content["chapters"])

    def prepare_permissions(self, obj):
        return "public"
Exemplo n.º 29
0
class MultiValueValidSearchIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True)
    author = indexes.MultiValueField(stored=False)
    title = indexes.CharField(indexed=False)

    def get_model(self):
        return MockModel
Exemplo n.º 30
0
class ExtractIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    title = indexes.CharField(model_attr='title')
    chapter = indexes.CharField(model_attr='chapter')
    txt = indexes.CharField(model_attr='text')

    # Groups authorized to read this topic.
    # If a group "public" is defined, the forum is public (and anyone can read it).
    permissions = indexes.MultiValueField()

    def get_model(self):
        return Extract

    def index_queryset(self, using=None):
        """Only extracts online."""

        published_content = GetPublished().get_published_content()

        return self.get_model().objects.filter(
            Q(chapter__tutorial__sha_public__isnull=False)
            | Q(chapter__part__tutorial__sha_public__isnull=False),
            id__in=published_content["extracts"])

    def prepare_permissions(self, obj):
        return "public"