Search code examples
ruby-on-railspg-search

pgsearch for whole words with multisearchable


Please pardon me if this is a duplicate question. I am a junior level rails developer and have recently installed pgsearch on my app.

I have the pg_trgm contrib package installed (:trigram and :dmetaphone).

When I search for "how to interview" I receive results such as "discriminatory" with "to" highlighted, or "however" with "how" highlighted.

Here's my initializer:

PgSearch.multisearch_options = { 
 :using => { 
   :trigram => {
    :threshold => 0.5
   },
   :dmetaphone => {
    :any_word => true, 
    :sort_only => true
   },
   :tsearch => { 
    :prefix => true,
    :any_word => true,
    :dictionary => "english",
    :normalization => 2 
   }
 }
}

How does one modify their pg_search to search whole words?

*Forgot to mention, I am using multisearchable :against => [:title, :body] in my model.


Solution

  • Based on my reading from the github repo, you need to remove the line :prefix => true,

    but in general, maybe remove all of the options that you don't understand and layer them on one by one and see how they affect the results.