pg-trgm

Optimizing a postgres similarity query (pg_trgm + gin index)

喜夏-厌秋 提交于 2021-02-17 22:52:16
问题 I have defined the following index: CREATE INDEX users_search_idx ON auth_user USING gin( username gin_trgm_ops, first_name gin_trgm_ops, last_name gin_trgm_ops ); I am performing the following query: PREPARE user_search (TEXT, INT) AS SELECT username, email, first_name, last_name, ( -- would probably do per-field weightings here s_username + s_first_name + s_last_name ) rank FROM auth_user, similarity(username, $1) s_username, similarity(first_name, $1) s_first_name, similarity(last_name, $1

Regex pattern matching with pg_trgm (trigram matching)

点点圈 提交于 2021-01-28 07:44:09
问题 I have a database in postgresql called mydata with a field called text. I'm interested in doing regex pattern matching and only returning the snippet of the match, not the entire text. I know you can use pg_trgm (creates a trigram matching index) to speed up the search, but is there a way to do both the searching and matching as a combined statement? I'll provide some context: CREATE EXTENSION pg_trgm; CREATE INDEX text_trgm_idx ON mydata USING GIN(text gin_trgm_ops); I'll use the example

Search in 300 million addresses with pg_trgm

家住魔仙堡 提交于 2019-12-21 04:59:26
问题 I have 300 million addresses in my PostgreSQL 9.3 DB and I want to use pg_trgm to fuzzy search the rows. The final purpose is to implement a search function just like Google Map search. When I used pg_trgm to search these addresses, it cost about 30s to get the results. There are many rows matching the default similarity threshold condition of 0.3 but I just need about 5 or 10 results. I created a trigram GiST index: CREATE INDEX addresses_trgm_index ON addresses USING gist (address gist_trgm

Postgres `gin_trgm_ops` index not being used

℡╲_俬逩灬. 提交于 2019-12-11 15:56:53
问题 I'm trying to speed up some text matching in Postgres, using the pg_trgm extensions: CREATE TABLE test3 (id bigint, key text, value text); insert into test3 values (1, 'first 1', 'second 3'); insert into test3 values (2, 'first 1', 'second 2'); insert into test3 values (2, 'first 2', 'second 3'); insert into test3 values (3, 'first 1', 'second 2'); insert into test3 values (3, 'first 1', 'second 3'); insert into test3 values (4, 'first 2', 'second 3'); insert into test3 values (4, 'first 2',