[英]Django Haystack search in Html
i was just wondering (since i didn't find anything quick on Google) if its possible (and how do i achieve that) to search directly in an html file, and ignore the tags or not as i please? 我只是想知道(因为我没有在Google上快速找到任何东西)是否有可能(以及如何实现这一点)直接在html文件中进行搜索,而忽略标签则不是我所希望的?
explaining a bit further. 进一步解释。 we wrote a crawler and obviously the crawler gives back the HTML of the page.
我们编写了一个搜寻器,很显然,该搜寻器返回了页面的HTML。 But if i feel like searching the content of the crawler, do i need 2 separate fields one with html and one without or i can just have one field with html and search ignoring the html tags or not.
但是,如果我想搜索爬虫的内容,我是否需要2个单独的字段,其中一个带有html,一个不带html,或者我只能拥有一个带有html的字段,并且搜索是否忽略html标签。
thanks in advance. 提前致谢。
If i correctly understand you, all you need is to set search indexes without html tags? 如果我正确理解您的意思,那么您所需要做的就是设置没有html标签的搜索索引?
We solved that problem this way: 我们通过以下方式解决了这个问题:
class PostIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(model_attr='text', use_template=True, document=True)
and in template ( search/indexes/blogs/post_test.html
) we just used striptags
filter 在模板(
search/indexes/blogs/post_test.html
)中,我们仅使用了striptags
过滤器
{{ object.content|striptags }}
After that you need to build_schema
and rebuild_index
. 之后,您需要
build_schema
和rebuild_index
。 Now it search correctly without tags. 现在,它可以正确搜索无标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.