-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Change FTS operators to explicitly call to_tsvector() #2255
Comments
@dsyrstad Hm, if the above is true, then I believe just doing a Like: GET /contacts?select=jsonb_field&jsonb_field_1->>field=fts.jsonvalue |
Or do you want to search across all the postgres=# \df to_tsvector
List of functions
Schema | Name | Result data type | Argument data types | Type
------------+-------------+------------------+---------------------+------
pg_catalog | to_tsvector | tsvector | json | func
pg_catalog | to_tsvector | tsvector | jsonb | func
pg_catalog | to_tsvector | tsvector | regconfig, json | func
pg_catalog | to_tsvector | tsvector | regconfig, jsonb | func
pg_catalog | to_tsvector | tsvector | regconfig, text | func
pg_catalog | to_tsvector | tsvector | text | func |
We've discusssed adding modifiers to operators in #1943 (comment). So perhaps we can have: GET /contacts?jsonb_field_1=to_tsvector.fts.jsonvalue |
@steve-chavez Yes, I want to search across all jsonb values. It's pretty convenient. Having a Curious - could we also get casts with modifiers? You can currently cast in |
Ah, I see. So just call Would you like to give it a shot? Relevant file is https://github.com/PostgREST/postgrest/blob/main/src/PostgREST/Query/SqlFragment.hs#L99
Hm, we frown upon doing that because any client could invalidate indexes and generate slow queries. |
@steve-chavez Normally I would raise a PR, but in this case I don't have Haskell skills, nor an environment set up to build it on. |
Kind of similar to what we did in #2145 - making the calls explicit, opens up new possibilities. |
I tested adding postgrest/src/PostgREST/Query/SqlFragment.hs Line 258 in 115dae7
Result: pgFmtFieldFts op = "to_tsvector(" <> pgFmtField table fld <> ")" <> " " <> SQL.sql (ftsOperator op) This breaks all the WHERE to_tsvector("api"."tsearch"."text_search_vector") @@ to_tsquery($1) Can't find a way to determine the type of the column, maybe the schema cache needs to be used here, or perhaps adding the |
Now that tableColumns is easier to get (already inside our Table in the internal cache) I think we could do that. Only need to be careful to not search for the column for every other filter - we could also use a load test to see if noticeable perf is lost for |
Is this planned or tracked? |
It is tracked in this very issue. If you want to work on it, feel free.
Did anyone try creating the missing @@ operator for jsonb with a function that does this to_tsvector call explicitly? Then it should work out of the box, I guess. |
Environment
Description of issue
I cannot perform a full-text search on json or jsonb column types.
Steps to reproduce
GET /contacts?select=jsonb_field&jsonb_field_1=fts.jsonvalue
Actual result
The query produced contains the SQL:
Expected Result
I'm able to perform a full-text search on a json/jsonb column. There is no workaround with PostgREST at present.
Possible solution
Instead of generating:
...generate:
I believe this is to be exactly equivalent. According to the doc,
to_tsvector()
is implicitly called with text:By explicitly calling
to_tsvector()
, json/jsonb columns would also be handled.The text was updated successfully, but these errors were encountered: