Commit 6befc78fe774a4409db5c0238d95d4e5268c1c23
Committed by
Sergio Oliveira
1 parent
52ba4161
Exists in
master
and in
31 other branches
Noosfero data to haystack.
Add noosfero atributtes to serach_indexes.py Signed-off-by: Thiago Ribeiro <thiagitosouza@hotmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com> Signed-off-by: Gustavo Jaruga <darksshades@gmail.com>
Showing
3 changed files
with
80 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,72 @@ |
1 | +# -*- coding: utf-8 -*- | |
2 | + | |
3 | +import string | |
4 | + | |
5 | +from haystack import indexes | |
6 | +from haystack.utils import log as logging | |
7 | + | |
8 | +from .models import (NoosferoArticle, NoosferoCommunity) | |
9 | + | |
10 | + | |
11 | +logger = logging.getLogger('haystack') | |
12 | + | |
13 | +# The string maketrans always return a string encoded with latin1 | |
14 | +# http://stackoverflow.com/questions/1324067/how-do-i-get-str-translate-to-work-with-unicode-strings | |
15 | +table = string.maketrans( | |
16 | + string.punctuation, | |
17 | + '.' * len(string.punctuation) | |
18 | +).decode('latin1') | |
19 | + | |
20 | + | |
21 | +class NoosferoCommunityIndex(indexes.SearchIndex, indexes.Indexable): | |
22 | + text = indexes.CharField(document=True, use_template=True, stored=False) | |
23 | + title = indexes.CharField(model_attr='name') | |
24 | + description = indexes.CharField(model_attr='description', null=True) | |
25 | + url = indexes.CharField(model_attr='url', indexed=False) | |
26 | + icon_name = indexes.CharField() | |
27 | + type = indexes.CharField() | |
28 | + modified = indexes.DateTimeField(model_attr='modified', null=True) | |
29 | + created_at = indexes.DateTimeField(model_attr='created_at', null=True) | |
30 | + category = indexes.MultiValueField() | |
31 | + | |
32 | + def prepare_category(self, obj): | |
33 | + return [category.name for category in \ | |
34 | + obj.categories.all()] | |
35 | + | |
36 | + def prepare_icon_name(self, obj): | |
37 | + return u'file' | |
38 | + | |
39 | + def get_ful_name(self): | |
40 | + self.objs.name | |
41 | + | |
42 | + def get_model(self): | |
43 | + return NoosferoCommunity | |
44 | + | |
45 | + def prepare_type(self, obj): | |
46 | + return u'noosfero_community' | |
47 | + | |
48 | + | |
49 | +class NoosferoArticleIndex(indexes.SearchIndex, indexes.Indexable): | |
50 | + | |
51 | + text = indexes.CharField(document=True, use_template=True, stored=False) | |
52 | + title = indexes.CharField(model_attr='title') | |
53 | + body = indexes.CharField(model_attr='body', null=True) | |
54 | + url = indexes.CharField(model_attr='url', indexed=False) | |
55 | + icon_name = indexes.CharField() | |
56 | + type = indexes.CharField(model_attr='type') | |
57 | + modified = indexes.DateTimeField(model_attr='modified', null=True) | |
58 | + created_at = indexes.DateTimeField(model_attr='created_at', null=True) | |
59 | + category = indexes.MultiValueField() | |
60 | + | |
61 | + def get_model(self): | |
62 | + return NoosferoArticle | |
63 | + | |
64 | + def prepare_category(self, obj): | |
65 | + return [category.name for category in \ | |
66 | + obj.categories.all()] | |
67 | + | |
68 | + def prepare_icon_name(self, obj): | |
69 | + return u'file' | |
70 | + | |
71 | + def prepare_type(self, obj): | |
72 | + return u'noosfero_articles' | ... | ... |
colab/plugins/noosfero/templates/search/indexes/noosfero/noosferoarticle_text.txt
0 → 100644
colab/plugins/noosfero/templates/search/indexes/noosfero/noosferocommunity_text.txt
0 → 100644