search_indexes.py 792 Bytes
Newer Older
1 2
# standard library imports
from __future__ import absolute_import, print_function
3
# third party imports
Daniel W Bond's avatar
Daniel W Bond committed
4
from haystack import indexes
5
# imports from your apps
Daniel W Bond's avatar
Daniel W Bond committed
6 7
from .models import Student

8

Daniel W Bond's avatar
Daniel W Bond committed
9 10 11 12
class StudentIndex(indexes.SearchIndex, indexes.Indexable):

    # search results
    # there can BE ONLY ONE document=True per model
13
    text = indexes.EdgeNgramField(document=True, use_template=True)
Daniel W Bond's avatar
Daniel W Bond committed
14 15 16 17
    # the use_template is in the app directory, just a text file
    # with the fields that we want to display when returning results

    # search filtering
Daniel W Bond's avatar
Daniel W Bond committed
18
    user = indexes.CharField(model_attr='user')
Daniel W Bond's avatar
Daniel W Bond committed
19 20 21 22 23 24

    def get_model(self):
        return Student

    def index_queryset(self, using=None):
        """When the entire index for model is updated."""
Daniel W Bond's avatar
Daniel W Bond committed
25
        return self.get_model().objects.all()