Django文本搜索与部分句子匹配 [英] Django text search with partial sentence match

查看:214
本文介绍了Django文本搜索与部分句子匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个网站,我想在这个网站上实现一些对象的标题和描述的文本搜索。由于我的对象数量很少(约500个文件),所以我不考虑Haystack等。

我只需要2个特征:


  • 能够在描述的优先顺序上标注匹配(带有某种权重)。
  • 允许部分匹配句子。例如,如果我搜索'冰淇淋',也可以得到'冰'和'奶油'的结果。


我有看着 django-watson django-full-text-search ,但我不确定它们是否允许部分匹配。
有什么想法?

解决方案

每个文档,有多少数据存储?



如果我们正在谈论500个文档,并且按分钟点击几次,或许django api就足够了:

  q =无
用于search_string.split()中的单词:
q_aux = Q(title__icontains = word) Q(description__icontains = word)
q =(q_aux& q)if bool(q)else q_aux

result = Document.objects.filter(q)

你有没有考虑过这个选项?

注意:




  • 这种方法不会优先于标题而不是描述

  • 只有所有单词匹配才会显示在结果中。


I am building a site in which I want to implement text search for the title and description of some objects. Since I will have little amount of objects (~500 documents) I am not considering Haystack and the such.

I only need 2 features:

  • Be able to prioritize matches on the title over the description (with some kind of weight).
  • Allow partial match of the sentence. For example, if I search for 'ice cream', get also the results for 'ice' and 'cream'.

I have looked into django-watson and django-full-text-search but I am not sure if they allow partial matching. Any ideas?

解决方案

How many hits by second have your site? Each document, how many data stores?

If we are talking about 500 docs and few hits by minute perhaps django api is enough:

q = None
for word in search_string.split():
   q_aux = Q( title__icontains = word ) | Q( description__icontains = word )
   q = ( q_aux & q ) if bool( q ) else q_aux

result = Document.objects.filter( q ) 

You ever considered this option?

Be careful:

  • This approach don't priorize title over description
  • Only "all words" matches appear in results.

这篇关于Django文本搜索与部分句子匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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