[英]How to index string with underscore in Django with Haystack/Whoosh
I am trying to implement search with Haystack and Whoosh in a Django project. 我正在尝试在Django项目中使用Haystack和Whoosh实现搜索。
The CharField
I am trying to index has data like something_like_this
. 我尝试索引的
CharField
具有类似something_like_this
数据。 But it won't show up in the search result if I search for 'something' or 'this. 但是,如果我搜索“某物”或“本”,它将不会显示在搜索结果中。 It only works if I search for 'something_like_this'.
它仅在我搜索“ something_like_this”时有效。 Is there anyway to search the keywords in the
CharFiled
? 无论如何,有没有在
CharFiled
搜索关键字?
All I can think of is to create another CharField
, store the string without underscore of the original string and then index it. 我所能想到的就是创建另一个
CharField
,存储不带原始字符串下划线的字符串,然后对其进行索引。 But that seems like stupid idea. 但这似乎是愚蠢的主意。
Make data_field
a MultiValueField
and implement the prepare_data_field
method where you could do something like this: 将
data_field
为MultiValueField
并实现prepare_data_field
方法,您可以在其中执行以下操作:
prepare_data_field(self, obj):
return obj.data_field.split('_')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.