opaleye-textsearch-0.1.0.0: Text search utilities for Opaleye
Copyright(c) Gargantext 2024-
LicenseAGPL-3.0-or-later
Maintainergargantext@iscpif.fr
Stability0.1.0.0
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Opaleye.TextSearch

Description

 
Synopsis

How to use

Example:

data MyEntity id text search =
  MyEntity { _id      :: id
           , _text    :: text
           , _search  :: search }
  deriving (Show, Generic)

$(makeAdaptorAndInstance "pMyEntity" ''MyEntity)

type MyEntityRead =
  MyEntity
    (Field SqlInt4     )
    (Field SqlText     )
    (Field SqlTSVector )

type MyEntityWrite =
  MyEntity
    (Maybe (Field SqlInt4 ))
    (Field SqlText          )
    (Field SqlTSVector      )

myEntityTable :: Table MyEntityWrite MyEntityRead
myEntityTable = Table "my_entity" ( pMyEntity
                                   MyEntity { _id           = optionalTableField "id"
                                            , _text         = requiredTableField "text"
                                            , _search       = optionalTableField "search_vector"
                                            }
                                   )

myQuery :: Text -> Select (Column SqlInt4, Column SqlText)
myQuery q = proc () -> do
    row <- myEntityTable -< ()
    restrict -< (_search row)    @@ (sqlPlainToTSQuery (unpack q))
    returnA  -< (_id row, _text row)
	
	
runSelect conn (myQuery "hello world")

Types

data SqlTSQuery Source #

Instances

Instances details
IsSqlType SqlTSQuery Source # 
Instance details

Defined in Opaleye.TextSearch.Internal.Types

Methods

showSqlType :: proxy SqlTSQuery -> String #

Functions and operators

(@@) :: Field SqlTSVector -> Field SqlTSQuery -> Field SqlBool infix 4 Source #

PostgreSQL match operator (checks if tsvector matches given tsquery).

pgTSVector :: Field SqlText -> Field SqlTSVector Source #

PostgreSQL tsvector coercion from text.

pgTSQuery :: Field SqlText -> Field SqlTSQuery Source #

PostgreSQL tsquery coercion from text.

sqlTSQuery :: String -> Field SqlTSQuery Source #

Coerce given String to tsquery.

Various parsing queries

For to_tsquery, plainto_tsquery, etc. functions, see "Parsing queries" section in PostgreSQL docs

sqlPlainToTSQuery :: String -> Field SqlTSQuery Source #

Call plainto_tsquery.

sqlToTSQuery :: String -> Field SqlTSQuery Source #

Call to_tsquery on the input string.

Internals (mostly)

to_pgTSQuery :: String -> Field SqlTSQuery Source #

Converts a String into a Postgres' tsQuery by calling to_tsquery on the input string.

plainto_pgTSQuery :: String -> Field SqlTSQuery Source #

Converts a String into a Postgres' tsQuery by calling plainto_tsquery on the input string.