Postgres 允许使用pg_trgm 模块进行三元索引。
这是他们在“索引支持”部分提供的示例代码:
CREATE TABLE test_trgm (t text);
CREATE INDEX trgm_idx ON test_trgm USING GIST (t gist_trgm_ops);
这是我提出的迁移:
class AddTitleTrigramIndexToContacts < ActiveRecord::Migration[5.1]
def change
enable_extension 'pg_trgm'
execute "CREATE INDEX contacts_title_trigram_ix ON contacts USING GIST (title gist_trgm_ops);"
end
end
有没有更好的方法来添加这个迁移?我什至不确定这是否正确。