用django haystack和弹性搜索搜索结果 [英] Unescape search results with django haystack and elasticsearch
本文介绍了用django haystack和弹性搜索搜索结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
&
,'
或的书籍名称
。索引数据转义这些字符,搜索结果显示转义的数据。 $ p $ b
或
<当我想在非HTML上下文(即纯文本)中使用结果时,li> unescape的字符?
这是我的代码:
#search_indexes.py
class Book(indexes.SearchIndex,indexes.Indexable):
text = indexes.EdgeNgramField(document = True,use_template = True)
def get_model自我):
返回书
#template
{{object.name}}
#query
SearchQuerySet()。autocomplete text = my_query)
解决方案
在您的模板中,您可以使用过滤器和标签,如:
{%autoescape on%}
{{object.name}}
{ %endautoescape%}
或
{{object.name | striptags}}
I'm using django-haystack with elasticsearch backend. The data contains names of books that may contain special characters like &
, '
or ""
. The indexed data escapes these characters and the search results shows the escaped data. How do I tell haystack or elasticsearch to
- turn off escaping
OR - unescape the characters when I want to use the results in a non-HTML context i.e. as plain text ?
Here's my code:
#search_indexes.py
class Book(indexes.SearchIndex, indexes.Indexable):
text = indexes.EdgeNgramField(document=True, use_template=True)
def get_model(self):
return Book
#template
{{object.name}}
#query
SearchQuerySet().autocomplete(text=my_query)
解决方案
In your template you can use filters and tags like:
{% autoescape on %}
{{ object.name }}
{% endautoescape %}
or
{{ object.name|striptags }}
这篇关于用django haystack和弹性搜索搜索结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文