Python django orm搜索与postgres

Python django orm搜索与postgres,python,django,django-models,full-text-search,django-orm,Python,Django,Django Models,Full Text Search,Django Orm,对于PostgreSQL中的小型搜索,可以很容易地使用,如文档所示 以下是我用来实现它的步骤- '''call the libraries''' from djorm_pgfulltext.models import SearchManager from djorm_pgfulltext.fields import VectorField class Notes(models.Model): title = models.CharField() description = mod

对于PostgreSQL中的小型搜索,可以很容易地使用,如文档所示

以下是我用来实现它的步骤-

'''call the libraries'''
from djorm_pgfulltext.models import SearchManager
from djorm_pgfulltext.fields import VectorField


class Notes(models.Model):
   title = models.CharField()
   description = models.TextField()

    # create a vector field
    search_index = VectorField()

    objects = models.Manager()
    search_manager = SearchManager(
        fields=('title', 'description'),
        config='pg_catalog.english',
        search_field='search_index',
        auto_update_search_field=True
    )
运行迁移,所有更改都将反映在数据库中。 最后一步- 在我的postgresql数据库中,我执行了以下操作-

sudo -u postgres psql postgres // login as root

CREATE EXTENSION unaccent;
ALTER FUNCTION unaccent(text) IMMUTABLE;
所有这些都完成了,现在我打开我的外壳

from myapp.models import Notes
  In [2]: Note.search_manager.search("p")
  Out[3]: [] 
你知道我为什么没有结果吗


缺少什么?

可能是数据库中的数据吗?或者您已经有了包含p的数据?不,我也没有得到任何其他关键字的结果。您来自迁移。您是否尝试过更新Notes.objects.all()中x的索引:
:x._orm_manager.update_index(pk=x.pk)
?PostgreSQL全文搜索是通过单词而不是字符进行的。@andreyantukh感谢它成功了。