【发布时间】:2018-07-16 08:29:40
【问题描述】:
我正在使用 Django 2.0 和 postgres (PostgreSQL) 9.6.1
我有以下带有标题和正文文本的模型:
class Entry(models.Model):
headline = models.CharField(max_length=255)
body_text = models.TextField()
def __str__(self):
return self.headline
以下是我的内容
headline: cheese making
body_text:
The simplest way to use full text search is to search a single term against a single column in the database. For example: >>> Entry.objects.filter(body_text__search='Cheese') [<Entry: Cheese on Toast recipes>, <Entry: Pizza Recipes>]. This creates a to_tsvector in the database from the body_text field and a plainto_tsquery ...
以下搜索结果使用search lookup。我在 INSTALLED_APPS 中添加了 'django.contrib.postgres'。
Case 1: Works
In [1]: Entry.objects.filter(body_text__search='Cheese')
Out[1]: <QuerySet [<Entry: cheese making>]>
Case 2: Not working
In [2]: Entry.objects.filter(body_text__search='Pizza')
Out[2]: <QuerySet []>
(the word Pizza is there in the body_text still is not searching)
Case 3: Not working
In [3]: Entry.objects.filter(body_text__search='vector')
Out[3]: <QuerySet []>
(the word vector is there in to_tsvector
Case 4: Not working
In [9]: Entry.objects.filter(body_text__search='Entry')
Out[9]: <QuerySet []>
Case 5: Not working
In [10]: Entry.objects.filter(body_text__search='data')
Out[10]: <QuerySet []>
如何搜索不起作用的术语。
【问题讨论】:
标签: django postgresql full-text-search