File: search_indexes.py

package info (click to toggle)
django-haystack 2.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,220 kB
  • sloc: python: 15,512; xml: 1,708; makefile: 71; sh: 45
file content (37 lines) | stat: -rw-r--r-- 926 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# encoding: utf-8

from __future__ import absolute_import, division, print_function, unicode_literals

from haystack import indexes
from haystack.indexes import Indexable, SearchIndex

from .models import Bar, Foo


# To test additional ignores...
class BaseIndex(indexes.SearchIndex):
    text = indexes.CharField(document=True, model_attr='body')

    def get_model(self):
        return Foo


class FooIndex(BaseIndex, indexes.Indexable):
    def index_queryset(self, using=None):
        qs = super(FooIndex, self).index_queryset(using=using)
        if using == "filtered_whoosh":
            qs = qs.filter(body__contains="1")
        return qs


# Import the old way & make sure things don't explode.


class BarIndex(SearchIndex, Indexable):
    text = indexes.CharField(document=True)

    def get_model(self):
        return Bar

    def prepare_text(self, obj):
        return u"%s\n%s" % (obj.author, obj.content)