~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to news/search_indexes.py

  • Committer: kaputtnik
  • Date: 2019-05-30 18:20:02 UTC
  • mto: This revision was merged to the branch mainline in revision 540.
  • Revision ID: kaputtnik-20190530182002-g7l91m1xo28clghv
adjusted README; first commit on the new server

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from haystack import indexes
 
2
from news.models import Post
 
3
import datetime
 
4
 
 
5
 
 
6
class PostIndex(indexes.SearchIndex, indexes.Indexable):
 
7
 
 
8
    """Create a search index. Changes made here need to be reindexed.
 
9
    Defined fields are stored in the index, so when displaying the result the
 
10
    data is read from the index and do not hit the database.
 
11
 
 
12
    Except the 'text' field all defined fields will be in the index.
 
13
 
 
14
    'text' indicates the template where the concatenated data
 
15
           is gathered and the search runs over.
 
16
 
 
17
    'date' is the field which is used for sorting
 
18
 
 
19
    """
 
20
 
 
21
    text = indexes.CharField(document=True, use_template=True)
 
22
    title = indexes.CharField(model_attr='title')
 
23
    body = indexes.CharField(model_attr='body')
 
24
    date = indexes.DateTimeField(model_attr='publish')
 
25
 
 
26
    def get_model(self):
 
27
        return Post
 
28
    
 
29
    def index_queryset(self, using=None):
 
30
        "Don't index news of the future"
 
31
        return self.get_model().objects.filter(publish__lte=datetime.datetime.now())
 
32
 
 
33
    def get_updated_field(self):
 
34
        return "created"