【问题标题】:django 1.10 postgres full text search is not workingdjango 1.10 postgres全文搜索不起作用
【发布时间】: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


【解决方案1】:

其实是我的错。对于 Postgres 创建索引时的全文搜索,默认情况下会忽略“the”、“for”、“are”、“is”等常用词。因此,如果您尝试使用此关键字进行搜索,即使存在搜索查询也会返回空有很多带有这些词的句子。 我不知道这个。所以我以为我配置错误。

【讨论】:

    猜你喜欢
    • 2018-07-18
    • 1970-01-01
    • 2019-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多