pg_search icon indicating copy to clipboard operation
pg_search copied to clipboard

Multisearchable rank by closest

Open elithecho opened this issue 8 years ago • 3 comments

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"

  1. Sam Ball
  2. Jason Smith
  3. Article about beach ball
  4. 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)"
}

elithecho avatar Jan 16 '17 07:01 elithecho

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.

kluzny avatar Apr 08 '17 06:04 kluzny

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.

kluzny avatar Apr 16 '17 21:04 kluzny

+1

eric-norcross avatar Jan 12 '21 20:01 eric-norcross