Change phrase/plain full text search syntax

This commit is contained in:
steve-chavez
2017-11-27 11:38:54 -05:00
committed by Steve Chávez
parent 678b855614
commit be630aa680
9 changed files with 48 additions and 87 deletions
+4 -10
View File
@@ -40,7 +40,7 @@ import PostgREST.Types ( QualifiedIdentifier (..)
, ApiRequestError(..)
, toMime
, operators
, FtsMode(..))
, ftsOperators)
import Data.Ranged.Ranges (Range(..), rangeIntersection, emptyRange)
import qualified Data.CaseInsensitive as CI
import Web.Cookie (parseCookiesText)
@@ -142,16 +142,10 @@ 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 = any (`T.isPrefixOf` val) $
((<> ".") <$> "not":M.keys operators) ++
((<> "(") <$> M.keys ftsOperators)
isEmbedPath = T.isInfixOf "."
-- handle "?tsv=english.fts.possible" case
hasLanguageFts val = case T.splitOn "." val of
[_, "fts", _] -> True
[_, "fts"] -> True
[_, "@@", _] -> True -- TODO: '@@' deprecated
[_, "@@"] -> True
_ -> False
isTargetingProc = fromMaybe False $ (== "rpc") <$> listToMaybe path
payload =
case decodeContentType . fromMaybe "application/json" $ lookupHeader "content-type" of