views:

26

answers:

1

Hi,

I am investigating how the http://code.google.com/p/django-fts/ application works. I am trying to setup psql FTS to work with the application, but can't understand how to create index correctly.

Don't understand how to create the GIN index as it was specified in doc.

My model is following:

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

in the database I have a table store_product

But when I am running the following in my psql, I have an error:

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.

Can you help me to understand what is wrong here?

A: 

You need:

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

(assuming you want the index on english). See section 12.2.2 in the documentation at http://www.postgresql.org/docs/9.0/static/textsearch-tables.html#TEXTSEARCH-TABLES-INDEX

Magnus Hagander
Thanks for the answer. It gives me an error:
Oleg Tarasenko
db=# CREATE INDEX "store_product_index" ON "store_product" USING gin( to_tsvector('english', name) );ERROR: function to_tsvector("unknown", character varying) does not existLINE 1: ...tore_product_index" ON "store_product" USING gin( to_tsvecto... ^HINT: No function matches the given name and argument types. You may need to add explicit type casts.
Oleg Tarasenko
What version of PostgreSQL are you on? Are you sure you are on one that has the builtin full text search? If not, you need to install the tsearch module...
Magnus Hagander