Combining Trigram and Tsearch

39 views
Skip to first unread message

Jonathan Greenberg

unread,
Jul 8, 2014, 12:58:57 AM7/8/14
to casecom...@googlegroups.com
I recently posted a question but either it is being moderated or it failed to post so forgive me if this is redundant.

I have a use case as follows:

I am trying to search across an Image model against two fields: image_file_name and image_description. I want to be able to retrieve an image with filename 'image_foo.jpg' with query 'foo'. I also want to be able to search for images that might have a long description. Ideally this would be done with one pg_search_scope.

Separately I can achieve this with a trigram search on image_file_name and a tsearch for the description but i a search against both then the trigram fails to find the filename for 'foo' because concatenation makes the threshold too high.

Do you have any suggestions about what can be done currently or how I could work on a pull request that might be acceptable in this scenario.

I was thinking something like:

 pg_search_scope :fulltext_search,·
                  against: [:image_file_name, :image_description],·
                  using: [
                    [:tsearch, { prefix: true, dictionary: 'english'}],
                    [:trigram, { only: :image_file_name }]]

Thanks!




Reply all
Reply to author
Forward
0 new messages