Set the correct language during indexing
This commit is contained in:
parent
7c4b3a7c76
commit
beb058f27e
1 changed files with 32 additions and 30 deletions
|
@ -3,6 +3,7 @@ from aldryn_search.helpers import get_plugin_index_data
|
||||||
from aldryn_search.utils import get_index_base, strip_tags
|
from aldryn_search.utils import get_index_base, strip_tags
|
||||||
from django.utils.encoding import force_text
|
from django.utils.encoding import force_text
|
||||||
from haystack import indexes
|
from haystack import indexes
|
||||||
|
from parler.utils.context import switch_language
|
||||||
|
|
||||||
from .models import Post
|
from .models import Post
|
||||||
from .settings import get_setting
|
from .settings import get_setting
|
||||||
|
@ -44,36 +45,37 @@ class PostIndex(get_index_base()):
|
||||||
return Post
|
return Post
|
||||||
|
|
||||||
def get_search_data(self, post, language, request):
|
def get_search_data(self, post, language, request):
|
||||||
description = post.get_description()
|
with switch_language(post, language):
|
||||||
abstract = strip_tags(post.safe_translation_getter('abstract', default=''))
|
description = post.get_description()
|
||||||
keywords = post.get_keywords()
|
abstract = strip_tags(post.safe_translation_getter('abstract', default=''))
|
||||||
|
keywords = post.get_keywords()
|
||||||
|
|
||||||
text_bits = []
|
text_bits = []
|
||||||
if abstract:
|
if abstract:
|
||||||
text_bits.append(abstract)
|
text_bits.append(abstract)
|
||||||
if description:
|
if description:
|
||||||
text_bits.append(description)
|
text_bits.append(description)
|
||||||
if keywords:
|
if keywords:
|
||||||
text_bits.append(' '.join(keywords))
|
text_bits.append(' '.join(keywords))
|
||||||
self.prepared_data['keywords'] = ','.join(keywords)
|
self.prepared_data['keywords'] = ','.join(keywords)
|
||||||
for category in post.categories.all():
|
for category in post.categories.all():
|
||||||
text_bits.append(
|
text_bits.append(
|
||||||
force_text(category.safe_translation_getter('name')))
|
force_text(category.safe_translation_getter('name')))
|
||||||
for tag in post.tags.all():
|
for tag in post.tags.all():
|
||||||
text_bits.append(force_text(tag.name))
|
text_bits.append(force_text(tag.name))
|
||||||
|
|
||||||
if get_setting('USE_PLACEHOLDER'):
|
if get_setting('USE_PLACEHOLDER'):
|
||||||
plugins = post.content.cmsplugin_set.filter(language=language)
|
plugins = post.content.cmsplugin_set.filter(language=language)
|
||||||
content_bits = []
|
content_bits = []
|
||||||
for base_plugin in plugins:
|
for base_plugin in plugins:
|
||||||
content = get_plugin_index_data(base_plugin, request)
|
content = get_plugin_index_data(base_plugin, request)
|
||||||
content_bits.append(' '.join(content))
|
content_bits.append(' '.join(content))
|
||||||
post_text = ' '.join(content_bits)
|
post_text = ' '.join(content_bits)
|
||||||
else:
|
else:
|
||||||
post_text = post.safe_translation_getter('post_text')
|
post_text = post.safe_translation_getter('post_text')
|
||||||
if post_text:
|
if post_text:
|
||||||
post_text = strip_tags(post_text)
|
post_text = strip_tags(post_text)
|
||||||
self.prepared_data['post_text'] = post_text
|
self.prepared_data['post_text'] = post_text
|
||||||
text_bits.append(post_text)
|
text_bits.append(post_text)
|
||||||
|
|
||||||
return ' '.join(text_bits)
|
return ' '.join(text_bits)
|
||||||
|
|
Loading…
Add table
Reference in a new issue