1# encoding: utf-8
2
3from __future__ import absolute_import, division, print_function, unicode_literals
4
5from haystack import indexes
6from haystack.indexes import Indexable, SearchIndex
7
8from .models import Bar, Foo
9
10
11# To test additional ignores...
12class BaseIndex(indexes.SearchIndex):
13    text = indexes.CharField(document=True, model_attr='body')
14
15    def get_model(self):
16        return Foo
17
18
19class FooIndex(BaseIndex, indexes.Indexable):
20    def index_queryset(self, using=None):
21        qs = super(FooIndex, self).index_queryset(using=using)
22        if using == "filtered_whoosh":
23            qs = qs.filter(body__contains="1")
24        return qs
25
26
27# Import the old way & make sure things don't explode.
28
29
30class BarIndex(SearchIndex, Indexable):
31    text = indexes.CharField(document=True)
32
33    def get_model(self):
34        return Bar
35
36    def prepare_text(self, obj):
37        return u"%s\n%s" % (obj.author, obj.content)
38