pg_search gem and fulltext search rank setting pg_search gem and fulltext search rank setting postgresql postgresql

pg_search gem and fulltext search rank setting


I had a very similar situation in Django and I solved summing up the trigram similarity and tsearch rank.

Similarity with word with exact match is higher than a partial match, as you can check on PostgresSQL:

SELECT similarity('gro', 'gro') AS exact, similarity('gro', 'group') AS partial; exact | partial  -------+----------     1 | 0.428571

I'm not a ruby expert but I've read the pg_search documentation and I think the solution for your question should by similar to this:

pg_search_scope :fulltext,                against: [:firstname, :lastname, :middlename],                using: {                  tsearch: { prefix: true },                  trigram: {                      :threshold => 0.2                  }                },                :ranked_by => ":tsearch + :trigram"