【问题标题】:django-fts: How to create indexes for psqldjango-fts:如何为 psql 创建索引
【发布时间】:2010-10-06 07:33:37
【问题描述】:

我正在研究http://code.google.com/p/django-fts/ 应用程序的工作原理。我正在尝试设置 psql FTS 以使用该应用程序,但无法理解如何正确创建索引。

不明白如何创建文档中指定的 GIN 索引。

我的模型如下:

class Product(fts.SearchableModel):
    name =  models.CharField(max_length = 1000)
    description = models.TextField(blank = True)

在数据库中我有一个表 store_product

但是当我在我的 psql 中运行以下命令时,我有一个错误:

base=# CREATE INDEX "store_product_index" ON "store_product" USING gin("name");
ERROR:  data type character varying has no default operator class for access method "gin"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.

你能帮我理解这里有什么问题吗?

【问题讨论】:

    标签: django postgresql full-text-search


    【解决方案1】:

    你需要:

    CREATE INDEX "store_product_index" ON "store_product" USING gin(to_tsvector('english', "name"));
    

    (假设您想要英文索引)。请参阅http://www.postgresql.org/docs/9.0/static/textsearch-tables.html#TEXTSEARCH-TABLES-INDEX 文档中的第 12.2.2 节

    【讨论】:

    • db=# CREATE INDEX "store_product_index" ON "store_product" USING gin( to_tsvector('english', name) );错误:函数 to_tsvector("unknown", character varying) 不存在 LINE 1: ...tore_product_index" ON "store_product" USING gin( to_tsvecto... ^ 提示:没有函数匹配给定的名称和参数类型。您可能需要添加显式类型转换。
    • 您使用的是哪个版本的 PostgreSQL?您确定您使用的是具有内置全文搜索功能的设备吗?如果没有,则需要安装 tsearch 模块...
    猜你喜欢
    • 2021-11-13
    • 2011-11-21
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 2020-07-22
    • 2017-10-03
    • 1970-01-01
    • 2018-02-08
    相关资源
    最近更新 更多