1 From a5693a2010e6d13f51cdc576fa1dc9985e79ee0e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Przemys=C5=82aw=20Kaminski?= <pk@intrepidus.pl>
3 Date: Mon, 27 Feb 2023 06:17:12 +0100
4 Subject: [PATCH] [FTS] full text search implementation
7 src/Opaleye/Internal/HaskellDB/PrimQuery.hs | 1 +
8 src/Opaleye/Internal/HaskellDB/Sql/Default.hs | 1 +
9 src/Opaleye/Internal/PGTypesExternal.hs | 14 ++++++++++++++
10 src/Opaleye/Operators.hs | 7 +++++++
11 src/Opaleye/SqlTypes.hs | 7 +++++++
12 5 files changed, 30 insertions(+)
14 diff --git a/src/Opaleye/Internal/HaskellDB/PrimQuery.hs b/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
15 index e9d5c71c..2e85e2ba 100644
16 --- a/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
17 +++ b/src/Opaleye/Internal/HaskellDB/PrimQuery.hs
18 @@ -64,6 +64,7 @@ data BinOp = (:==) | (:<) | (:<=) | (:>) | (:>=) | (:<>)
19 | (:->) | (:->>) | (:#>) | (:#>>)
20 | (:@>) | (:<@) | (:?) | (:?|) | (:?&)
21 | (:&&) | (:<<) | (:>>) | (:&<) | (:&>) | (:-|-)
26 diff --git a/src/Opaleye/Internal/HaskellDB/Sql/Default.hs b/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
27 index 4fb964fd..9258d2db 100644
28 --- a/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
29 +++ b/src/Opaleye/Internal/HaskellDB/Sql/Default.hs
30 @@ -205,6 +205,7 @@ showBinOp (:>>) = ">>"
31 showBinOp (:&<) = "&<"
32 showBinOp (:&>) = "&>"
33 showBinOp (:-|-) = "-|-"
34 +showBinOp (:@@) = "@@"
36 data UnOpType = UnOpFun | UnOpPrefix | UnOpPostfix
38 diff --git a/src/Opaleye/Internal/PGTypesExternal.hs b/src/Opaleye/Internal/PGTypesExternal.hs
39 index c8f18760..632980cc 100644
40 --- a/src/Opaleye/Internal/PGTypesExternal.hs
41 +++ b/src/Opaleye/Internal/PGTypesExternal.hs
42 @@ -182,6 +182,15 @@ pgRange pgEl start end =
43 oneEl R.NegInfinity = HPQ.NegInfinity
44 oneEl R.PosInfinity = HPQ.PosInfinity
48 +pgTSVector :: Field SqlText -> Field SqlTSVector
49 +pgTSVector (C.Column e) = C.Column (HPQ.FunExpr "tsvector" [e])
51 +pgTSQuery :: Field SqlText -> Field SqlTSQuery
52 +pgTSQuery (C.Column e) = C.Column (HPQ.FunExpr "tsquery" [e])
55 instance IsSqlType SqlBool where
56 showSqlType _ = "boolean"
57 instance IsSqlType SqlDate where
58 @@ -246,6 +255,9 @@ instance IsRangeType SqlTimestamptz where
59 instance IsRangeType SqlDate where
60 showRangeType _ = "daterange"
62 +instance IsSqlType SqlTSQuery where
63 + showSqlType _ = "tsquery"
68 @@ -287,6 +299,8 @@ data SqlBytea
77 diff --git a/src/Opaleye/Operators.hs b/src/Opaleye/Operators.hs
78 index cee26942..892b2b18 100644
79 --- a/src/Opaleye/Operators.hs
80 +++ b/src/Opaleye/Operators.hs
81 @@ -39,6 +39,7 @@ module Opaleye.Operators
86 -- * Numerical operators
89 @@ -212,6 +213,12 @@ infix 4 .>=
90 (.>=) :: Ord.SqlOrd a => Field a -> Field a -> F.Field T.SqlBool
91 (.>=) = C.binOp (HPQ.:>=)
94 +(@@) :: Field T.SqlTSVector -> Field T.SqlTSQuery -> F.Field T.SqlBool
95 +(@@) = C.binOp (HPQ.:@@)
97 +-- * Numerical operators
99 -- | Integral division, named after 'Prelude.quot'. It maps to the
100 -- @/@ operator in Postgres.
101 quot_ :: C.SqlIntegral a => Field a -> Field a -> Field a
102 diff --git a/src/Opaleye/SqlTypes.hs b/src/Opaleye/SqlTypes.hs
103 index 1dc86ee2..196b12e5 100644
104 --- a/src/Opaleye/SqlTypes.hs
105 +++ b/src/Opaleye/SqlTypes.hs
106 @@ -90,6 +90,10 @@ module Opaleye.SqlTypes (
109 P.IsSqlType(P.showSqlType),
116 import qualified Opaleye.Field as F
117 @@ -207,6 +211,9 @@ sqlLazyJSON = P.pgLazyJSON
118 sqlValueJSON :: Ae.ToJSON a => a -> F.Field SqlJson
119 sqlValueJSON = P.pgValueJSON
121 +sqlTSQuery :: String -> F.Field P.SqlTSQuery
122 +sqlTSQuery = P.pgTSQuery . sqlString
124 -- The jsonb data type was introduced in PostgreSQL version 9.4
125 -- JSONB values must be SQL string quoted