简体   繁体   English

使用django haystack和elasticsearch逃脱搜索结果

[英]Unescape search results with django haystack and elasticsearch

I'm using django-haystack with elasticsearch backend. 我正在将django-haystack与elasticsearch后端一起使用。 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 我如何告诉干草堆或elasticsearch

  1. turn off escaping 关闭转义
    OR 要么
  2. unescape the characters when I want to use the results in a non-HTML context ie as plain text ? 当我想在非HTML上下文中(即作为纯文本)使用结果时,请取消转义字符?

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 }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM