How to specify conditions before performing trigram search in PostgreSQL? -


i'm new fuzzy searching , trigrams in postgresql. have few hundred thousand products in database , want able select products name closest product's name.

after few hours of experimenting , research, have installed pg_trgm extension , created trigram index this:

create index simpleproduct_name_lowercase on simpleproduct using gist(lower(name) gist_trgm_ops); 

the following query executes in 0.07s, satisfying now:

select  'coffee' <-> lower(name) distance, gtin, name simpleproduct order distance limit 10 

the thing is, need further specify kind of products want searching through. imagined if that, faster before because not fuzzy searching whole database specific group of products. reason though, if e.g. following:

select  'coffee' <-> lower(name) distance, gtin, name simpleproduct id < 10000 order distance limit 10 

... execution time doubles. explain why case? also, if experienced in area, recommend against using postgresql , going e.g. elastic?


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -