| author | ymh <ymh.work@gmail.com> |
| Fri, 20 Sep 2013 22:21:48 +0200 | |
| changeset 113 | c05567404888 |
| child 114 | 93b45b4f423c |
| permissions | -rw-r--r-- |
|
113
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
# -*- coding: utf-8 -*- |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
''' |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
Created on Sep 20, 2013 |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
5 |
@author: ymh |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
6 |
''' |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
7 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
8 |
from haystack import indexes |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
9 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
10 |
from p4l.models import Record |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
11 |
from p4l.utils import strip_accents |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
12 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
13 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
14 |
class RecordIndex(indexes.SearchIndex, indexes.Indexable): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
15 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
16 |
text = indexes.CharField(document=True, use_template=True, stored=False) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
17 |
identifier = indexes.CharField(model_attr="identifier", stored=True) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
18 |
titles = indexes.MultiValueField(model_attr="get_titles", stored=False) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
19 |
titles_src = indexes.MultiValueField(model_attr="get_titles", stored=True, indexed=False) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
20 |
authors = indexes.MultiValueField(model_attr="get_authors", stored=False) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
21 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
22 |
years = indexes.MultiValueField(model_attr="get_imprints_years", indexed=False, stored=True) |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
23 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
24 |
def prepare_titles(self, obj): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
25 |
return [strip_accents(v) for v in obj.get_titles()] |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
26 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
27 |
def prepare_authors(self, obj): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
28 |
return [strip_accents(v) for v in obj.get_authors()] |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
30 |
def get_model(self): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
31 |
return Record |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
32 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
33 |
def get_updated_field(self): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
34 |
return "modification_date" |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
35 |
|
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
36 |
def index_queryset(self, using=None): |
|
c05567404888
First version of indexation. Replace the list view by a search view
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
37 |
return Record.objects.using(using).all().prefetch_related("imprints","authors", "titles") |