~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wiki/search_indexes.py

  • Committer: franku
  • Date: 2017-09-12 18:04:34 UTC
  • mto: This revision was merged to the branch mainline in revision 473.
  • Revision ID: somal@arcor.de-20170912180434-oywhxkfkq5yq2267
added news and wiki; css changes; removed django_sphinx

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from haystack import indexes
 
2
from wiki.models import Article
 
3
from haystack.fields import DateField
 
4
from datetime import date
 
5
 
 
6
 
 
7
class ArticleIndex(indexes.SearchIndex, indexes.Indexable):
 
8
 
 
9
    """Create a search index. Changes made here need to be reindexed. Defined
 
10
    fields are stored in the index, so when displaying the result the data is
 
11
    read from the index and do not hit the database.
 
12
 
 
13
    Except the 'text' field all defined fields will be in the index.
 
14
 
 
15
    'text' indicates the template where the concatenated data
 
16
           is gathered and the search runs over.
 
17
 
 
18
    'date' is the field which is used for sorting
 
19
 
 
20
    """
 
21
 
 
22
    text = indexes.CharField(document=True, use_template=True)
 
23
    title = indexes.CharField(model_attr='title')
 
24
    summary = indexes.CharField(model_attr='summary', null=True)
 
25
    content = indexes.CharField(model_attr='content')
 
26
    # To get date related search working
 
27
    # we assume the index is always up to date
 
28
    date = DateField(default=date.today())
 
29
 
 
30
    def get_model(self):
 
31
        return Article
 
32
 
 
33
    def get_updated_field(self):
 
34
        return 'last_update'