Commit 4527a30d authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Merge branch 'adinapoli/add-dictionary-to-tsquery' into 'main'

Support specifying a `Dictionary` for the `sqlToTSQuery`

See merge request !1
parents 2ca9f8a8 04b5c904
cabal-version: 3.0
name: opaleye-textsearch
version: 0.1.0.0
version: 0.2.0.0
synopsis: Text search utilities for Opaleye
description: Utility functions to work with TS vectors in Postgres via Opaleye.
license: AGPL-3.0-or-later
......
......@@ -12,17 +12,18 @@ Portability : POSIX
module Opaleye.TextSearch (
-- * How to use
-- $use
-- * Types
SqlTSQuery
, SqlTSVector
, Dictionary(..)
-- * Functions and operators
, (@@)
, pgTSVector
, pgTSQuery
, sqlTSQuery
-- * Various parsing queries
-- $parsing_queries
, sqlPlainToTSQuery
......@@ -40,7 +41,6 @@ import Opaleye.TextSearch.Internal.Types
import Opaleye.TextSearch.Operators ((@@))
import qualified Opaleye.Internal.Column as C
import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ
import GHC.RTS.Flags (TraceFlags(user))
{- $use
......@@ -112,12 +112,17 @@ sqlPlainToTSQuery :: String -> Field SqlTSQuery
sqlPlainToTSQuery = plainto_pgTSQuery
-- | Call @to_tsquery@ on the input string.
sqlToTSQuery :: String -> Field SqlTSQuery
sqlToTSQuery :: Maybe Dictionary -> String -> Field SqlTSQuery
sqlToTSQuery = to_pgTSQuery
-- | Converts a 'String' into a Postgres' tsQuery by calling @to_tsquery@ on the input string.
to_pgTSQuery :: String -> Field SqlTSQuery
to_pgTSQuery query = C.Column (HPQ.FunExpr "to_tsquery" [HPQ.ConstExpr (HPQ.StringLit query)])
to_pgTSQuery :: Maybe Dictionary -> String -> Field SqlTSQuery
to_pgTSQuery mb_dict query =
let qryParam = HPQ.ConstExpr (HPQ.StringLit query)
params = case mb_dict of
Nothing -> [qryParam]
Just dict -> [HPQ.ConstExpr (HPQ.StringLit $ show dict), qryParam]
in C.Column (HPQ.FunExpr "to_tsquery" params)
-- | Converts a 'String' into a Postgres' tsQuery by calling @plainto_tsquery@ on the input string.
plainto_pgTSQuery :: String -> Field SqlTSQuery
......
{-# LANGUAGE DerivingStrategies #-}
module Opaleye.TextSearch.Internal.Types where
import Opaleye.Internal.PGTypes (IsSqlType(..))
-- | A dictionary: https://www.postgresql.org/docs/current/textsearch-dictionaries.html
newtype Dictionary = Dictionary { getDictionary :: String }
deriving stock Eq
deriving newtype Show
data SqlTSQuery
data SqlTSVector
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment