I find myself looking for a way to dynamically restrict search results so that all searches must be present:
["A TE","SOME"] search array:
"MS A TEXT B SOMETHING" --> matches
"MS A B SOMETHING" --> doesnt match
so I'm using a GIN index and LIKE ALL:
CREATE INDEX ix_gin_code ON ilike_test USING GIN(code gin_trgm_ops);
select * from ilike_test where code ilike ALL (:search_terms::text[]);
however, the index doesn't get used when filtering by ALL, only with direct LIKE and LIKE ANY.
Is there any reason for this? Or what's an alternative (fast) way to do this search?
Actual database:
- 500k rows
- text column median row size of 4kb
Fiddles with explains:
http://sqlfiddle.com/#!17/cc555/14 -- disable seq scan, yielding an strange LIKE ALL explain