django haystack我如何找到字串中的子字符串? [英] django haystack how do I find substrings in words?

查看:118
本文介绍了django haystack我如何找到字串中的子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的字段中,内容是example。
我不仅要找到确切的单词example,还想找到examp。我怎样才能做到这一点?有什么选择找不到任何东西。

In my field the content is "example". I want to find not only the exact word "example", I also want to find "examp". How can I do that? Are there any options. Can't find anything.

推荐答案

如果您只想搜索一些以某个字符串开头的对象,那么请看Haystack SearchQuerySet API文档。它类似于Django QuerySet API,所以可以写:

If you just want to search for objects starting with some string, then just look at Haystack SearchQuerySet API documentation. It resembles the Django QuerySet API, so it is possible to write:

SearchQuerySet().filter(content__startswith='examp')
SearchQuerySet().filter(content__contains='examp')

或任何你想要的。

但是这个问题还有更深入的一点。我不认为你真的需要。由于搜索引擎的工作原理 - 当有人搜索e.q. 监视它被阻止(这是获得类似于该词的根源的过程 - 所以我们将从监视中获得监视),实际上将被搜索。搜索索引中的所有内容都会被阻止,因此搜索监视器将返回包含f.e的结果。 '监视','监视','监视'等。

But there is also something deeper in this question. I don't think you really need to. Because of the way search engines works - when someone searches for e.q. 'monitoring' it gets stemmed (it is process of getting something similar to root of the word - so we will have f.e. 'monitor' from 'monitoring') and that will be searched for in fact. Also everything in search indexes gets stemmed, so searching for monitor will return results containing f.e. 'monitors', 'monitoring', 'monitorize' etc.

这篇关于django haystack我如何找到字串中的子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆