462.3.1
by franku
first functioning search with haystack and whoosh; working: wlmaps, pybb.topic, pybb.post |
1 |
from haystack import indexes |
462.3.25
by franku
some refactoring and beautification |
2 |
from haystack.fields import DateField |
462.3.1
by franku
first functioning search with haystack and whoosh; working: wlmaps, pybb.topic, pybb.post |
3 |
from wlmaps.models import Map |
462.3.25
by franku
some refactoring and beautification |
4 |
from datetime import date |
462.3.1
by franku
first functioning search with haystack and whoosh; working: wlmaps, pybb.topic, pybb.post |
5 |
|
6 |
||
7 |
class MapIndex(indexes.SearchIndex, indexes.Indexable): |
|
8 |
||
9 |
"""Create a search index. Changes made here need to be reindexed.
|
|
10 |
Defined fields are stored in the index, so when displaying the result the
|
|
11 |
data is 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 |
author = indexes.CharField(model_attr='author') |
|
462.3.25
by franku
some refactoring and beautification |
24 |
date = DateField(default=date.today()) |
25 |
pub_date = indexes.DateTimeField(model_attr='pub_date') |
|
462.3.1
by franku
first functioning search with haystack and whoosh; working: wlmaps, pybb.topic, pybb.post |
26 |
|
27 |
def get_model(self): |
|
28 |
return Map |
|
462.3.6
by franku
make running update_index faster; added highlighting; adjust search indexes |
29 |
|
30 |
def get_updated_field(self): |
|
31 |
return "pub_date" |