~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/search_indexes.py

  • Committer: Holger Rapp
  • Date: 2009-02-21 18:24:02 UTC
  • Revision ID: sirver@kallisto.local-20090221182402-k3tuf5c4gjwslbjf
Main Page contains now the same informations as before

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from haystack import indexes
2
 
from pybb.models import Topic, Post
3
 
 
4
 
 
5
 
class TopicIndex(indexes.SearchIndex, indexes.Indexable):
6
 
 
7
 
    """Create a search index. Changes made here need to be reindexed. Defined
8
 
    fields are stored in the index, so when displaying the result the data is
9
 
    read from the index and do not hit the database.
10
 
 
11
 
    Except the 'text' field all defined fields will be in the index.
12
 
 
13
 
    'text' indicates the template where the concatenated data
14
 
           is gathered and the search runs over.
15
 
 
16
 
    'date' is the field which is used for sorting
17
 
 
18
 
    """
19
 
 
20
 
    text = indexes.CharField(document=True, use_template=True)
21
 
    date = indexes.DateTimeField(model_attr='created')
22
 
    name = indexes.CharField(model_attr='name')
23
 
    # Following fields get stored in the index but are not be used for indexing
24
 
    # This avoids hitting the database when the results are rendered
25
 
    user = indexes.CharField(model_attr='user', indexed=False)
26
 
    topic_link = indexes.CharField(model_attr='get_absolute_url', indexed=False)
27
 
 
28
 
    def get_model(self):
29
 
        return Topic
30
 
 
31
 
    def index_queryset(self, using=None):
32
 
        """Do not index hidden topics."""
33
 
        return self.get_model().objects.exclude(posts__hidden=True)
34
 
 
35
 
    def get_updated_field(self):
36
 
        return 'updated'
37
 
 
38
 
 
39
 
class PostIndex(indexes.SearchIndex, indexes.Indexable):
40
 
 
41
 
    text = indexes.CharField(document=True, use_template=True)
42
 
    date = indexes.DateTimeField(model_attr='created')
43
 
    body_text = indexes.CharField(model_attr='body_text')
44
 
    # Following fields get stored in the index but are not be used for indexing
45
 
    # This avoids hitting the database when the results are rendered
46
 
    user = indexes.CharField(model_attr='user', indexed='false')
47
 
    post_link = indexes.CharField(
48
 
        model_attr='get_absolute_url', indexed='false')
49
 
 
50
 
    def get_model(self):
51
 
        return Post
52
 
 
53
 
    def index_queryset(self, using=None):
54
 
        """Do not index hidden posts."""
55
 
        return self.get_model().objects.exclude(hidden=True)
56
 
 
57
 
    def get_updated_field(self):
58
 
        return 'created'