esqueleto-textsearch-1.1.4: PostgreSQL full text search for Esqueleto
Safe HaskellSafe-Inferred
LanguageHaskell2010

Database.Esqueleto.TextSearch.Language

Synopsis

Documentation

(@@.) Source #

Arguments

:: SqlExpr (Value TsVector)

the document to search in

-> SqlExpr (Value (TsQuery Lexemes))

the query made by prefixAndQuery

-> SqlExpr (Value Bool) 

Apply some query to a tsvector document for example:

searchCompany :: SqlExpr (Entity CompanySearchIndex) -> SearchTerm -> SqlQuery ()
searchCompany company term = do
  let query = prefixAndQuery term
      norm = val []
  where_ $ (company ^. CompanySearchIndexDocument) @@. query

prefixAndQuery :: SearchTerm -> SqlExpr (Value (TsQuery Lexemes)) Source #

format the query into lexemes the result can be used in @@. for example:

searchCompany :: SqlExpr (Entity CompanySearchIndex) -> SearchTerm -> SqlQuery ()
searchCompany company term = do
  let query = prefixAndQuery term
      norm = val []
  where_ $ (company ^. CompanySearchIndexDocument) @@. query

toSearchTerm :: Text -> Maybe SearchTerm Source #

Constructs a valid search query, removes a bunch of illegal characters and splits the terms for better results. Also checks if there is anything in the search term.

using a search term is optional, but it's probably what you want. all underlying primitives are exposed.

data SearchTerm Source #

A valid search term. created with toSearchTerm.

Instances

Instances details
Show SearchTerm Source # 
Instance details

Defined in Database.Esqueleto.TextSearch.Language

ts_rank Source #

Arguments

:: SqlExpr (Value Weights)

relative weighting of a b c and d, see defaultWeights

-> SqlExpr (Value TsVector)

the document to search in

-> SqlExpr (Value (TsQuery Lexemes))

the query made by prefixAndQuery

-> SqlExpr (Value [NormalizationOption])

normalization option to indicate how to deal with document length

-> SqlExpr (Value Double) 

Organize search result by weights. This allows you to put better matching results higher. for example:

searchCompany :: SqlExpr (Entity CompanySearchIndex) -> SearchTerm -> SqlQuery ()
searchCompany company term = do
  let query = prefixAndQuery term
      norm = val []
  where_ $ (company ^. CompanySearchIndexDocument) @@. query
  orderBy [desc (ts_rank (val defaultWeights)
                 (company ^. CompanySearchIndexDocument)
                 query norm)]