Merge pull request #303 from nephila/hotfix/haystack
Set the correct language during indexing
This commit is contained in:
commit
80c557ed0f
3 changed files with 42 additions and 30 deletions
|
@ -4,6 +4,12 @@
|
|||
History
|
||||
=======
|
||||
|
||||
******************
|
||||
0.8.6 (unreleased)
|
||||
******************
|
||||
|
||||
* Set the correct language during indexing
|
||||
|
||||
******************
|
||||
0.8.5 (2016-06-26)
|
||||
******************
|
||||
|
|
|
@ -3,6 +3,7 @@ from aldryn_search.helpers import get_plugin_index_data
|
|||
from aldryn_search.utils import get_index_base, strip_tags
|
||||
from django.utils.encoding import force_text
|
||||
from haystack import indexes
|
||||
from parler.utils.context import switch_language
|
||||
|
||||
from .models import Post
|
||||
from .settings import get_setting
|
||||
|
@ -44,36 +45,37 @@ class PostIndex(get_index_base()):
|
|||
return Post
|
||||
|
||||
def get_search_data(self, post, language, request):
|
||||
description = post.get_description()
|
||||
abstract = strip_tags(post.safe_translation_getter('abstract', default=''))
|
||||
keywords = post.get_keywords()
|
||||
with switch_language(post, language):
|
||||
description = post.get_description()
|
||||
abstract = strip_tags(post.safe_translation_getter('abstract', default=''))
|
||||
keywords = post.get_keywords()
|
||||
|
||||
text_bits = []
|
||||
if abstract:
|
||||
text_bits.append(abstract)
|
||||
if description:
|
||||
text_bits.append(description)
|
||||
if keywords:
|
||||
text_bits.append(' '.join(keywords))
|
||||
self.prepared_data['keywords'] = ','.join(keywords)
|
||||
for category in post.categories.all():
|
||||
text_bits.append(
|
||||
force_text(category.safe_translation_getter('name')))
|
||||
for tag in post.tags.all():
|
||||
text_bits.append(force_text(tag.name))
|
||||
text_bits = []
|
||||
if abstract:
|
||||
text_bits.append(abstract)
|
||||
if description:
|
||||
text_bits.append(description)
|
||||
if keywords:
|
||||
text_bits.append(' '.join(keywords))
|
||||
self.prepared_data['keywords'] = ','.join(keywords)
|
||||
for category in post.categories.all():
|
||||
text_bits.append(
|
||||
force_text(category.safe_translation_getter('name')))
|
||||
for tag in post.tags.all():
|
||||
text_bits.append(force_text(tag.name))
|
||||
|
||||
if get_setting('USE_PLACEHOLDER'):
|
||||
plugins = post.content.cmsplugin_set.filter(language=language)
|
||||
content_bits = []
|
||||
for base_plugin in plugins:
|
||||
content = get_plugin_index_data(base_plugin, request)
|
||||
content_bits.append(' '.join(content))
|
||||
post_text = ' '.join(content_bits)
|
||||
else:
|
||||
post_text = post.safe_translation_getter('post_text')
|
||||
if post_text:
|
||||
post_text = strip_tags(post_text)
|
||||
self.prepared_data['post_text'] = post_text
|
||||
text_bits.append(post_text)
|
||||
if get_setting('USE_PLACEHOLDER'):
|
||||
plugins = post.content.cmsplugin_set.filter(language=language)
|
||||
content_bits = []
|
||||
for base_plugin in plugins:
|
||||
content = get_plugin_index_data(base_plugin, request)
|
||||
content_bits.append(' '.join(content))
|
||||
post_text = ' '.join(content_bits)
|
||||
else:
|
||||
post_text = post.safe_translation_getter('post_text')
|
||||
if post_text:
|
||||
post_text = strip_tags(post_text)
|
||||
self.prepared_data['post_text'] = post_text
|
||||
text_bits.append(post_text)
|
||||
|
||||
return ' '.join(text_bits)
|
||||
return ' '.join(text_bits)
|
||||
|
|
4
tox.ini
4
tox.ini
|
@ -10,18 +10,22 @@ deps =
|
|||
django16: django-mptt<0.8
|
||||
django16: django-filer<1.2
|
||||
django16: cmsplugin-filer<1.1
|
||||
django16: django-haystack<2.5
|
||||
django17: Django>=1.7,<1.8
|
||||
django17: django-mptt<0.8
|
||||
django17: django-filer<1.3
|
||||
django17: cmsplugin-filer<1.2
|
||||
django17: django-haystack
|
||||
django18: Django>=1.8,<1.9
|
||||
django18: django-mptt>=0.8
|
||||
django18: django-filer<1.3
|
||||
django18: cmsplugin-filer<1.2
|
||||
django18: django-haystack
|
||||
django19: Django>=1.9,<1.10
|
||||
django19: django-mptt>=0.8
|
||||
django19: django-filer<1.3
|
||||
django19: cmsplugin-filer<1.2
|
||||
django19: django-haystack
|
||||
cms30: https://github.com/divio/django-cms/archive/release/3.0.x.zip
|
||||
cms30: djangocms-text-ckeditor<2.8
|
||||
cms31: https://github.com/divio/django-cms/archive/release/3.1.x.zip
|
||||
|
|
Loading…
Reference in a new issue