This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
search_indexes.py
56 lines (41 loc) · 1.65 KB
/
search_indexes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.conf import settings
from aldryn_search.utils import get_index_base
from haystack.constants import DEFAULT_ALIAS
from .models import Article
class ArticleIndex(get_index_base()):
haystack_use_for_indexing = getattr(
settings, 'ALDRYN_NEWSBLOG_SEARCH', True)
index_title = True
def get_language(self, obj):
return getattr(obj, '_current_language', None)
def get_title(self, obj):
return obj.title
def get_url(self, obj):
using = getattr(self, '_backend_alias', DEFAULT_ALIAS)
language = self.get_current_language(using=using, obj=obj)
return obj.get_absolute_url(language)
def get_description(self, obj):
return obj.lead_in
def get_index_kwargs(self, language):
"""
This is called to filter the index queryset.
"""
kwargs = {
'app_config__search_indexed': True,
'translations__language_code': language,
}
return kwargs
def get_index_queryset(self, language):
queryset = super(ArticleIndex, self).get_index_queryset(language)
return queryset.published().language(language)
def get_model(self):
return Article
def get_search_data(self, article, language, request):
return article.search_data
def should_update(self, instance, **kwargs):
using = getattr(self, '_backend_alias', DEFAULT_ALIAS)
language = self.get_current_language(using=using, obj=instance)
translations = instance.get_available_languages()
return translations.filter(language_code=language).exists()