2010-10-06 99 views
1

我正在研究http://code.google.com/p/django-fts/应用程序的工作方式。我试图设置psql FTS来处理应用程序,但无法理解如何正确创建索引。django-fts:如何为psql创建索引

不明白如何创建GIN索引,因为它是在doc中指定的。

我的模型如下:

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. 

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

回答

2

您需要:

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

(假设你想在英国的指数)。请参阅文档中的12.2.2部分:http://www.postgresql.org/docs/9.0/static/textsearch-tables.html#TEXTSEARCH-TABLES-INDEX

+0

感谢您的回答。它给了我一个错误: – 2010-10-06 12:26:51

+0

db =#CREATE INDEX“store_product_index”ON“store_product”使用杜松子酒(to_tsvector('english',name)); 错误:函数to_tsvector(“未知”,字符变化)不存在 线1:... tore_product_index“ON”store_product“使用杜松子酒(to_tsvecto ... ^ 提示:没有函数匹配给定的名称和参数类型你可能需要添加明确的类型转换 – 2010-10-06 12:27:15

+1

你使用的是什么版本的PostgreSQL?你确定你是一个内置的全文搜索的吗?如果没有,你需要安装tsearch模块... – 2010-10-07 17:15:44