Question

Do I put it in each model, right before, multisearchable :against => [ ... ] or should this be in a separate file? Thanks.

Was it helpful?

Solution 2

Okay found the answer, so I'll post it below.

I created a file called config/initializers/pg_search.rb which looks like:

PgSearch.multisearch_options = { :using => { :tsearch => { :prefix => true },
                                             :trigram => {},
                                             :dmetaphone => {} },
                                 :ignoring => :accents }

I don't fully understand why :trigram => {} works rather than just :trigram, but I guess that should be in another post.

OTHER TIPS

I had similar questions about how to implement PgSearch.multisearch_options.

This is what worked for me. Hopefully it will help someone else out.

I created the Initializer config/initializers/pg_search.rb

PgSearch.multisearch_options = {
  :using => {
    :tsearch => {
      :dictionary => "english"
    }
  }
}

In my application.rb file I uncommented this line: config.active_record.schema_format = :sql

Then created a migration called rails g migration add_trigram_extension adding the below to the migration file

def up
    execute "create extension pg_trgm"
end

def down
    execute "drop extension pg_trgm"
end

Then run bundle exec rake db:migrate

Restart the server

Now full text search with Stemming is working.

p.s. this worked using (PostgreSQL) 9.1.4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top