Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indexing column for full text search

I have column col with data type CHARACTER VARYING

I need that index this column as gin index. If trying directly set gin index to column, returned 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

If trying:

 create index col_vector 
 on mytable 
 using gin (to_tsvector(col))

I got error: functions in index expression must be marked IMMUTABLE

How to create gin index for CHARACTER VARYING column ?

p.s. I need this for full text search

like image 640
Oto Shavadze Avatar asked May 13 '13 08:05

Oto Shavadze


People also ask

How do I make a column full-text indexed?

To create a full text index choose your table and right click on that table and select “Define Full-Text Index” option. Now select Unique Index. It is compulsory that for “Full Text Index” table must have at least one unique index. Select columns name and language types for columns.

What is full-text indexing?

The information in full-text indexes is used by the Full-Text Engine to compile full-text queries that can quickly search a table for particular words or combinations of words. A full-text index stores information about significant words and their location within one or more columns of a database table.

How do I do a full-text search?

To implement a full-text search in a SQL database, you must create a full-text index on each column you want to be indexed. In MySQL, this would be done with the FULLTEXT keyword. Then you will be able to query the database using MATCH and AGAINST.


1 Answers

Try This Code:

CREATE INDEX "name " ON "tablename" USING gin(to_tsvector('english', "columnname"));
like image 160
Sathish Avatar answered Oct 10 '22 20:10

Sathish