aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/indicator/search_indexes.py
blob: f225b2c36ca013c622da3a8f5c9b549b45c28a88 (plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-

from haystack import indexes

from indicator import models as im



# IndicatorCategoryIndex {{{
class IndicatorCategoryIndex(indexes.SearchIndex, indexes.Indexable):
    """
    search index for 'Indicator'
    """
    text = indexes.CharField(document=True, use_template=True)
    # pinyin: for ordering the search result
    pinyin = indexes.CharField(model_attr='pinyin')
    addByUser = indexes.CharField(model_attr='addByUser')

    def get_model(self):
        return im.IndicatorCategory

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


# IndicatorIndex {{{
class IndicatorIndex(indexes.SearchIndex, indexes.Indexable):
    """
    search index for 'Indicator'
    """
    text = indexes.CharField(document=True, use_template=True)
    # pinyin: for ordering the search result
    pinyin = indexes.CharField(model_attr='pinyin')
    addByUser = indexes.CharField(model_attr='addByUser')
    dataType = indexes.CharField(model_attr='dataType')
    categories_id = indexes.MultiValueField()

    def get_model(self):
        return im.Indicator

    def prepare_categories(self, obj):
        return [c.id for c in obj.categories.all()]

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



# vim: set ts=4 sw=4 tw=0 fenc=utf-8 ft=python: