2 Module : Gargantext.Database.TextSearch
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
14 --{-# LANGUAGE NoImplicitPrelude #-}
15 --{-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Database.TextSearch where
19 import Prelude (print)
20 import Gargantext (connectGargandb)
22 import Database.PostgreSQL.Simple
23 import Control.Applicative
25 import Data.Text (Text)
26 import Gargantext.Prelude
34 data Order = Asc | Desc
36 toQuery :: Order -> Query
44 textSearchQuery :: Order -> Query
45 textSearchQuery o = "SELECT n.id, n.hyperdata -> 'publication_date' \
46 \ , n.hyperdata -> 'title' \
47 \ , n.hyperdata -> 'source' \
48 \ , COALESCE(nn.score,null) \
50 \ LEFT JOIN nodes_nodes nn ON nn.node2_id = n.id \
52 \ n.title_abstract @@ to_tsquery(?) \
53 \ AND n.parent_id = ? AND n.typename = 4 \
54 \ ORDER BY n.hyperdata -> 'publication_date' "
55 <> toQuery o <> " offset ? limit ?;"
58 textSearch :: Connection
59 -> TextQuery -> ParentId
60 -> Limit -> Offset -> Order
61 -> IO [(Int,Value,Value,Value, Maybe Int)]
62 textSearch conn q p l o ord = query conn (textSearchQuery ord) (q,p,o,l)
64 textSearchTest :: TextQuery -> IO ()
65 textSearchTest q = connectGargandb "gargantext.ini"
66 >>= \conn -> textSearch conn q 421968 10 0 Asc