Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: apply to_tsvector to the filtered columns when a fts operator is used #3845

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

laurenceisla
Copy link
Member

@laurenceisla laurenceisla commented Jan 14, 2025

Closes #2255

When an fts operator is used, then it applies to_tsvector to the filtered column. For example:

/table?column=fts(simple).test

is equivalent to this in SQL:

SELECT *
FROM table
WHERE to_tsvector('simple', column) = to_tsquery('simple', 'test')
If the `totsv` modifier (short for `to_tsvector`) is used for `fts` operators then it applies `to_tsvector` to the filtered column. For example:
/table?column=totsv.fts(simple).test

Is equivalent to this in SQL:

SELECT *
FROM table
WHERE to_tsvector('simple', column) = to_tsquery('simple', 'test')

@laurenceisla laurenceisla force-pushed the feat-totsv branch 2 times, most recently from b9cee18 to b8f8db2 Compare January 14, 2025 16:14
@laurenceisla laurenceisla marked this pull request as ready for review January 14, 2025 16:16
CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines 289 to +290
res = fromMaybe (unknownField fn jp) $ HM.lookup qi tables >>=
Just . flip resolveTableFieldName fn
Just . (\t -> resolveTableFieldName t fn toTsV)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a performance concern here: #2255 (comment)

I don't think there will be a difference in performance since it's using this lookup that is already applied for all filters before this PR.

@laurenceisla laurenceisla changed the title feat: add "totsv" modifier to the "fts" operator feat: apply to_tsvector to the filtered columns when a fts operator is used Jan 21, 2025
@@ -20,6 +21,7 @@ import PostgREST.SchemaCache.Identifiers (FieldName)
import Protolude

type TransformerProc = Text
type ToTsVector = Maybe (Maybe Text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is confusing at first glance, why a double Maybe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I created a new type to make it make sense.

@@ -193,7 +193,7 @@ The :code:`fts` filter mentioned above has a number of options to support flexib

curl "http://localhost:3000/tsearch?my_tsv=not.wfts(french).amusant"

Using `websearch_to_tsquery` requires PostgreSQL of version at least 11.0 and will raise an error in earlier versions of the database.
This also works with columns of text and JSON types, converting them to ``tsvector`` accordingly.
Copy link
Member

@steve-chavez steve-chavez Jan 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A subsection would be better for this. This way we can also highlight the feature on the release notes.

Maybe "automatic tsvector casting"`, "automatic to_tsvector??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Change FTS operators to explicitly call to_tsvector()
3 participants