【发布时间】:2017-03-31 16:11:55
【问题描述】:
我正在尝试将 django 1.10 的全文搜索与 postgres 数据库集成。 我正在关注教程 https://docs.djangoproject.com/en/1.10/ref/contrib/postgres/search/
class Question(models.Model):
text = models.TextField(max_length=500)
ans = models.TextField(max_length=1500, blank=True)
我在数据库中有几个问题,例如在其文本字段中包含文本“for”:一个问题是:
text: what is best for me?
ans: this is best for you.
我正在尝试进行类似
的查询q = Question.objects.filter(text__search='for')
但是这个查询没有返回任何结果。谁能告诉我为什么?
【问题讨论】:
-
要使用搜索查找,'django.contrib.postgres' 必须在您的 INSTALLED_APPS 中。你把它放在那里了吗
-
(1) 通过在 PostgreSQL 中打开语句日志并检查日志来检查实际正在运行的查询。 (2) 确保“for”不是字典中的停用词并被过滤掉。
-
我在 postgres 中添加了 'django.contrib.postgres'。它不仅适用于“为”字。如果我用“the”之类的其他词替换 for,那么它也不会显示正确的结果。 2) 我的查询: SELECT ••• FROM "faq_question" WHERE to_tsvector(COALESCE("faq_question"."text", '')) @@ (plainto_tsquery('for')) = true
标签: sql django postgresql full-text-search