pg_search
pg_search copied to clipboard
Multisearchable rank by closest
I have a multisearchable columns for many users and posts and I'd like to rank them by closest match.
currently it ranks as so
Eg search term, "Jason Ball"
- Sam Ball
- Jason Smith
- Article about beach ball
- Jason Ball
I would like to rank Jason Ball higher than the first two ranking.
Tried fiddling around PgSearch.multisearch_options{ ranked_by: }
to no avail, could use a bit of guidance here
PgSearch.multisearch_options = {
using: {
tsearch: { any_word: true },
trigram: { threshold: 0.4 }
},
ranked_by: "(:tsearch * 1.5) + (:trigram * 1.0)"
}
I have a similar issue: https://github.com/Casecommons/pg_search/issues/354
I think I might end up just using the raw sql, but it would seem that you also want to rank by exact matches, where the tsearch or trigram rank is not the most similar result.
I made a ruby class you might find useful @choonggg: https://gist.github.com/kluzny/498e3a3bace43b0e44ce07add44a99fa
Not as feature rich as the gem, but will likely solve your use case.
+1