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

Change phrase/plain full text search syntax #1007

Merged
merged 1 commit into from
Nov 27, 2017

Conversation

steve-chavez
Copy link
Member

@steve-chavez steve-chavez commented Nov 2, 2017

Changes the syntax for phrase/plain introduced in #964.

Previous syntax:

GET /tsearch?tsv=french.fts.amusant
GET /tsearch?tsv=plain.german.fts.Art%20Spass
GET /tsearch?tsv=phrase.english.fts.The%20Fat%20Cats

New syntax:

GET /tsearch?tsv=fts(french).amusant
GET /tsearch?tsv=plfts(german).Art%20Spass
GET /tsearch?tsv=phfts(english).The%20Fat%20Cats

New syntax is a bit shorter, it's more alike to the pg {plain/phrase}to_tsquery functions in that the first arg is the language(previous one has the language between plain/phrase and fts) and also it's more consistent because dots . are currently used like separators and the (language) fits better as an optional argument.

Also have to mention that having not.english.. was kinda confusing inside and/or operations, I think overall this new syntax is better and in addition it makes the code simpler.

@begriffs
Copy link
Member

begriffs commented Nov 5, 2017

I like the new syntax too, it looks clean.

Because this is a breaking change it should go in postgrest 5. (The parameterized callProc pull request should as well because it changes the postgresql minimum version requirement.)

Maybe we should get the other PRs merged first and make a 4.4 release with the new features, then follow it closely with a 5.0 release that contains these two breaking changes?

@steve-chavez
Copy link
Member Author

I don't see the breaking change, the plain/phrase full text search hasn't been released yet and fts still maintains the v0.4.3.0 syntax(the lang in fts(lang) is optional).

My idea was to avoid having a breaking change in v0.5 by having v0.4.4 with this PR merged and also after merging this to release v0.4.4 leaving my other PR's for v0.5 or V0.5-RC since they change core sql queries of PostgREST.

@begriffs
Copy link
Member

begriffs commented Nov 5, 2017

Good point. I forgot the plain/phrase full text search selection is not yet part of an actual release.

@@ -142,16 +142,8 @@ userApiRequest schema req reqBody
ActionInvoke{isReadOnly=True} -> partition (liftM2 (||) (isEmbedPath . fst) (hasOperator . snd)) flts
_ -> (flts, [])
flts = [ (toS k, toS $ fromJust v) | (k,v) <- qParams, isJust v, k /= "select", not (endingIn ["order", "limit", "offset", "and", "or"] k) ]
hasOperator val = foldr ((||) . flip T.isPrefixOf val) False ((<> ".") <$> (M.keys operators ++ ["not", show Plain, show Phrase]))
|| hasLanguageFts val
hasOperator val = foldr ((||) . flip T.isPrefixOf val) False $ ((<> ".") <$> "not":M.keys operators) ++ ((<> "(") <$> M.keys ftsOperators)
Copy link
Member

Choose a reason for hiding this comment

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

This code is kind of gnarly, would the any function help simplify it?

Copy link
Member

Choose a reason for hiding this comment

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

Like how about this:

hasOperator val =
  any (`T.isPrefixOf` val)
    $  map (`snoc` '.') ("not" : M.keys operators)
    ++ map (`snoc` '(') (M.keys ftsOperators)

Copy link
Member Author

@steve-chavez steve-chavez Nov 27, 2017

Choose a reason for hiding this comment

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

The any function makes the function clearer, though the snoc/map instead of <>/<$> makes the function harder to read for me.

Phrase -> "phraseto_tsquery("
<> maybe "" (flip (<>) ", " . pgFmtLit) lang <> unknownLiteral val <> ") "
Fts op lang val ->
pgFmtFieldOp op <> "(" <> maybe "" (flip (<>) ", " . pgFmtLit) lang <> unknownLiteral val <> ") "
Copy link
Member

Choose a reason for hiding this comment

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

How about a little whitespace and a section rather than flip?

pgFmtFieldOp op <> "("
  <> maybe "" ((<> ", ") . pgFmtLit) lang
  <> unknownLiteral val <> ") "

@begriffs
Copy link
Member

A couple minor style suggestions, then I'd say it's good to merge!

@steve-chavez steve-chavez merged commit be630aa into PostgREST:master Nov 27, 2017
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.

2 participants