postgrest icon indicating copy to clipboard operation
postgrest copied to clipboard

How to use ts_rank_cd on full text search?

Open jonasstenberg opened this issue 4 years ago • 7 comments

Environment

  • PostgreSQL version: 13.1 & 12.x
  • PostgREST version: 7.0.1 (d6050c8)
  • Operating system: OSX Catalina & Ubuntu 20.04

Description of issue

When using full text search that's documented here: https://postgrest.org/en/stable/api.html?highlight=order#full-text-search, how do you use ts_rank_cd (https://www.postgresql.org/docs/13/textsearch-controls.html#TEXTSEARCH-RANKING) to rank the results? If you provide me with a good example I can perhaps put together a PR with documentation for it.

Thanks!

jonasstenberg avatar Feb 12 '21 12:02 jonasstenberg

Hey @jonasstenberg,

You'll need to create a stored procedure for that: https://postgrest.org/en/stable/api.html#stored-procedures

steve-chavez avatar Feb 13 '21 00:02 steve-chavez

Alright, thanks!

Don't know Haskell myself but is this a feature planned to be included or is it meant to be implemented in an RPC in the future too?

jonasstenberg avatar Feb 15 '21 13:02 jonasstenberg

Don't know Haskell myself but is this a feature planned to be included or is it meant to be implemented in an RPC in the future too?

At this point this is more of a "how would we even do this?" question. Afaik, there hasn't been a suggestion how this could be included in the regular query syntax, yet. I'm failing to come up with something on the spot.

wolfgangwalther avatar Feb 15 '21 14:02 wolfgangwalther

Ok, I understand. I don't really know how such a query syntax would look either so I guess I'd have to settle with the rpc option for now.

Many thanks for the answers though!

jonasstenberg avatar Feb 15 '21 16:02 jonasstenberg

There was an idea on https://github.com/PostgREST/postgrest/issues/915#issuecomment-776060792 for calling functions on the url.

It could potentially call /apod?select=rank:ts_rank_cd(...)&order=rank, but that will take a while to get implemented. So RPC is definitely the way to go for now.

steve-chavez avatar Feb 15 '21 18:02 steve-chavez

There was an idea on #915 (comment) for calling functions on the url.

I understood this as only taking column names as function arguments...

It could potentially call /apod?select=rank:ts_rank_cd(...)&order=rank, but that will take a while to get implemented.

... and I think ts_rank_cd needs user input. And then we'd need to be able to use aliased expressions by alias in the order param, too. I don't think that's straightforward, either.

So "a while" is a very nice way to put it ;).

wolfgangwalther avatar Feb 16 '21 08:02 wolfgangwalther

Just hit this wall as well. Any chances of this getting put on the roadmap?

perelin avatar Jun 15 '24 08:06 perelin

Seeing that FTS rank is a common use case (mentioned on https://github.com/PostgREST/postgrest/issues/3820), I was thinking to have a special order_fts_rank query param that would take extra parameters.. but having the rank on the select is also a common use case, so that's a no-go.

It could potentially call /apod?select=rank:ts_rank_cd(...)&order=rank https://github.com/PostgREST/postgrest/issues/1758#issuecomment-779396997

Maybe we can do that with the idea on https://github.com/PostgREST/postgrest/issues/2578#issuecomment-1404037093

steve-chavez avatar Dec 19 '24 00:12 steve-chavez