Commit 8f521836 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[TSVector] added for full text queries.

parent 53e751d3
...@@ -27,6 +27,7 @@ git clone ssh://git@gitlab.iscpif.fr:20022/gargantext/clustering-louvain.git ...@@ -27,6 +27,7 @@ git clone ssh://git@gitlab.iscpif.fr:20022/gargantext/clustering-louvain.git
git clone https://github.com/np/servant-job.git git clone https://github.com/np/servant-job.git
git clone https://github.com/np/patches-map git clone https://github.com/np/patches-map
git clone https://gitlab.com/npouillard/patches-class.git git clone https://gitlab.com/npouillard/patches-class.git
git clone https://github.com:delanoe/haskell-opaleye.git
cd .. cd ..
~/.local/bin/stack docker pull ~/.local/bin/stack docker pull
......
name: gargantext name: gargantext
version: '4.0.0.2' version: '4.0.0.3'
synopsis: Search, map, share synopsis: Search, map, share
description: Please see README.md description: Please see README.md
category: Data category: Data
......
...@@ -50,7 +50,7 @@ import Gargantext.Database.NodeNgram ...@@ -50,7 +50,7 @@ import Gargantext.Database.NodeNgram
import Gargantext.Database.NodeNode import Gargantext.Database.NodeNode
import Gargantext.Database.Queries import Gargantext.Database.Queries
import Opaleye import Opaleye
import Opaleye.Internal.Join (NullMaker) import Opaleye.Internal.Join (NullMaker(..))
import Prelude (Enum, Bounded, minBound, maxBound) import Prelude (Enum, Bounded, minBound, maxBound)
import Prelude hiding (null, id, map, sum, not, read) import Prelude hiding (null, id, map, sum, not, read)
import Servant.API import Servant.API
...@@ -193,8 +193,6 @@ queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNgramTable queryNgramsTable ...@@ -193,8 +193,6 @@ queryAuthorsDoc = leftJoin5 queryNodeTable queryNodeNgramTable queryNgramsTable
cond45 (contact, (nodeNgram2, (_, (_,_)))) = _node_id contact .== nodeNgram_NodeNgramNodeId nodeNgram2 cond45 (contact, (nodeNgram2, (_, (_,_)))) = _node_id contact .== nodeNgram_NodeNgramNodeId nodeNgram2
------------------------------------------------------------------------ ------------------------------------------------------------------------
runViewDocuments :: CorpusId -> Trash -> Maybe Offset -> Maybe Limit -> Maybe OrderBy -> Cmd [FacetDoc] runViewDocuments :: CorpusId -> Trash -> Maybe Offset -> Maybe Limit -> Maybe OrderBy -> Cmd [FacetDoc]
......
...@@ -26,7 +26,7 @@ import Gargantext.Database.NodeNgram ...@@ -26,7 +26,7 @@ import Gargantext.Database.NodeNgram
toMaps :: Hyperdata a => (a -> Map (NgramsT Ngrams) Int) -> [Node a] -> Map (NgramsT Ngrams) (Map NodeId Int) toMaps :: Hyperdata a => (a -> Map (NgramsT Ngrams) Int) -> [Node a] -> Map (NgramsT Ngrams) (Map NodeId Int)
toMaps fun ns = mapNodeIdNgrams $ documentIdWithNgrams fun ns' toMaps fun ns = mapNodeIdNgrams $ documentIdWithNgrams fun ns'
where where
ns' = map (\(Node nId _ _ _ _ _ json) -> DocumentWithId nId json) ns ns' = map (\(Node nId _ _ _ _ _ json _) -> DocumentWithId nId json) ns
mapNodeIdNgrams :: Hyperdata a => [DocumentIdWithNgrams a] -> Map (NgramsT Ngrams) (Map NodeId Int) mapNodeIdNgrams :: Hyperdata a => [DocumentIdWithNgrams a] -> Map (NgramsT Ngrams) (Map NodeId Int)
mapNodeIdNgrams ds = DM.map (DM.fromListWith (+)) $ DM.fromListWith (<>) xs mapNodeIdNgrams ds = DM.map (DM.fromListWith (+)) $ DM.fromListWith (<>) xs
......
This diff is collapsed.
...@@ -40,7 +40,7 @@ getChildren c pId _ maybeNodeType maybeOffset maybeLimit = runQuery c ...@@ -40,7 +40,7 @@ getChildren c pId _ maybeNodeType maybeOffset maybeLimit = runQuery c
selectChildren :: ParentId -> Maybe NodeType -> Query NodeRead selectChildren :: ParentId -> Maybe NodeType -> Query NodeRead
selectChildren parentId maybeNodeType = proc () -> do selectChildren parentId maybeNodeType = proc () -> do
row@(Node nId typeName _ parent_id _ _ _) <- queryNodeTable -< () row@(Node nId typeName _ parent_id _ _ _ _) <- queryNodeTable -< ()
(NodeNode n1id n2id _ _ _) <- queryNodeNodeTable -< () (NodeNode n1id n2id _ _ _) <- queryNodeNodeTable -< ()
let nodeType = maybe 0 nodeTypeId maybeNodeType let nodeType = maybe 0 nodeTypeId maybeNodeType
......
...@@ -37,7 +37,7 @@ type NodeWrite = NodePoly (Maybe (Column PGInt4 )) ...@@ -37,7 +37,7 @@ type NodeWrite = NodePoly (Maybe (Column PGInt4 ))
(Column (PGText )) (Column (PGText ))
(Maybe (Column PGTimestamptz)) (Maybe (Column PGTimestamptz))
(Column PGJsonb ) (Column PGJsonb )
-- (Maybe (Column PGTSVector)) (Maybe (Column PGTSVector))
type NodeRead = NodePoly (Column PGInt4 ) type NodeRead = NodePoly (Column PGInt4 )
(Column PGInt4 ) (Column PGInt4 )
...@@ -46,8 +46,7 @@ type NodeRead = NodePoly (Column PGInt4 ) ...@@ -46,8 +46,7 @@ type NodeRead = NodePoly (Column PGInt4 )
(Column (PGText )) (Column (PGText ))
(Column PGTimestamptz ) (Column PGTimestamptz )
(Column PGJsonb) (Column PGJsonb)
-- (Column PGTSVector) (Column PGTSVector)
type NodeReadNull = NodePoly (Column (Nullable PGInt4 )) type NodeReadNull = NodePoly (Column (Nullable PGInt4 ))
...@@ -57,8 +56,7 @@ type NodeReadNull = NodePoly (Column (Nullable PGInt4 )) ...@@ -57,8 +56,7 @@ type NodeReadNull = NodePoly (Column (Nullable PGInt4 ))
(Column (Nullable PGText )) (Column (Nullable PGText ))
(Column (Nullable PGTimestamptz )) (Column (Nullable PGTimestamptz ))
(Column (Nullable PGJsonb)) (Column (Nullable PGJsonb))
(Column (Nullable PGTSVector))
join3 :: Query columnsA -> Query columnsB -> Query columnsC join3 :: Query columnsA -> Query columnsB -> Query columnsC
......
...@@ -10,6 +10,7 @@ Portability : POSIX ...@@ -10,6 +10,7 @@ Portability : POSIX
-} -}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE NoImplicitPrelude #-} {-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
...@@ -26,13 +27,30 @@ import Database.PostgreSQL.Simple.ToField ...@@ -26,13 +27,30 @@ import Database.PostgreSQL.Simple.ToField
import Gargantext.Database.Config (nodeTypeId) import Gargantext.Database.Config (nodeTypeId)
import Gargantext.Database.Types.Node (NodeType(..)) import Gargantext.Database.Types.Node (NodeType(..))
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Node
import Gargantext.Database.Queries
import Gargantext.Core.Types
import Control.Arrow (returnA)
import qualified Opaleye as O hiding (Order)
import Opaleye hiding (Query, Order)
newtype TSQuery = UnsafeTSQuery [Text] newtype TSQuery = UnsafeTSQuery [Text]
searchQuery :: O.Query NodeRead
searchQuery = proc () -> do
row <- queryNodeTable -< ()
restrict -< (_node_search row) @@ (pgTSQuery "test")
returnA -< row
-- | TODO [""] -> panic "error" -- | TODO [""] -> panic "error"
toTSQuery :: [Text] -> TSQuery toTSQuery :: [Text] -> TSQuery
toTSQuery txt = UnsafeTSQuery txt toTSQuery txt = UnsafeTSQuery txt
instance IsString TSQuery instance IsString TSQuery
where where
fromString = UnsafeTSQuery . words . cs fromString = UnsafeTSQuery . words . cs
...@@ -48,9 +66,6 @@ instance ToField TSQuery ...@@ -48,9 +66,6 @@ instance ToField TSQuery
] ]
) xs ) xs
type ParentId = Int
type Limit = Int
type Offset = Int
data Order = Asc | Desc data Order = Asc | Desc
instance ToField Order instance ToField Order
......
...@@ -63,8 +63,6 @@ type UTCTime' = UTCTime ...@@ -63,8 +63,6 @@ type UTCTime' = UTCTime
instance Arbitrary UTCTime' where instance Arbitrary UTCTime' where
arbitrary = elements $ timesAfter 100 D (jour 2000 01 01) arbitrary = elements $ timesAfter 100 D (jour 2000 01 01)
------------------------------------------------------------------------ ------------------------------------------------------------------------
data Status = Status { status_failed :: Int data Status = Status { status_failed :: Int
, status_succeeded :: Int , status_succeeded :: Int
...@@ -324,18 +322,15 @@ instance Hyperdata HyperdataNotebook ...@@ -324,18 +322,15 @@ instance Hyperdata HyperdataNotebook
-- | NodePoly indicates that Node has a Polymorphism Type -- | NodePoly indicates that Node has a Polymorphism Type
type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json (Maybe TSVector)
-- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
type NodeTypeId = Int type NodeTypeId = Int
type NodeParentId = Int type NodeParentId = Int
type NodeUserId = Int type NodeUserId = Int
type NodeName = Text type NodeName = Text
--type NodeVector = Vector type TSVector = Text
--type NodeUser = Node HyperdataUser
type NodeAny = Node HyperdataAny
-- | Then a Node can be either a Folder or a Corpus or a Document -- | Then a Node can be either a Folder or a Corpus or a Document
type NodeUser = Node HyperdataUser type NodeUser = Node HyperdataUser
...@@ -347,6 +342,9 @@ type NodeDocument = Node HyperdataDocument ...@@ -347,6 +342,9 @@ type NodeDocument = Node HyperdataDocument
type NodeAnnuaire = Node HyperdataAnnuaire type NodeAnnuaire = Node HyperdataAnnuaire
-- | Any others nodes
type NodeAny = Node HyperdataAny
---- | Then a Node can be either a Graph or a Phylo or a Notebook ---- | Then a Node can be either a Graph or a Phylo or a Notebook
type NodeList = Node HyperdataList type NodeList = Node HyperdataList
type NodeGraph = Node HyperdataGraph type NodeGraph = Node HyperdataGraph
...@@ -379,24 +377,30 @@ instance ToParamSchema NodeType ...@@ -379,24 +377,30 @@ instance ToParamSchema NodeType
instance ToSchema NodeType instance ToSchema NodeType
------------------------------------------------------------------------ ------------------------------------------------------------------------
data NodePoly id typename userId parentId name date hyperdata = Node { _node_id :: id data NodePoly id typename userId
, _node_typename :: typename parentId name date
, _node_userId :: userId hyperdata search = Node { _node_id :: id
, _node_typename :: typename
, _node_userId :: userId
-- , nodeUniqId :: hashId -- , nodeUniqId :: hashId
, _node_parentId :: parentId , _node_parentId :: parentId
, _node_name :: name , _node_name :: name
, _node_date :: date , _node_date :: date
, _node_hyperdata :: hyperdata
} deriving (Show, Generic) , _node_hyperdata :: hyperdata
, _node_search :: search
} deriving (Show, Generic)
$(deriveJSON (unPrefix "_node_") ''NodePoly) $(deriveJSON (unPrefix "_node_") ''NodePoly)
$(makeLenses ''NodePoly) $(makeLenses ''NodePoly)
instance Arbitrary hyperdata => Arbitrary (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime hyperdata) where
arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) <$> arbitrary
instance Arbitrary hyperdata => Arbitrary (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime hyperdata) where
arbitrary = Node 1 1 1 (Just 1) "name" (jour 2018 01 01) <$> arbitrary
instance Arbitrary hyperdata => Arbitrary (NodePoly NodeId NodeTypeId
(Maybe NodeUserId) NodeParentId NodeName
UTCTime hyperdata (Maybe TSVector)) where
--arbitrary = Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (arbitrary) (Just "")
arbitrary = Node <$> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary <*> arbitrary
<*> arbitrary <*> arbitrary
------------------------------------------------------------------------ ------------------------------------------------------------------------
hyperdataDocument :: HyperdataDocument hyperdataDocument :: HyperdataDocument
hyperdataDocument = case decode docExample of hyperdataDocument = case decode docExample of
...@@ -438,18 +442,17 @@ instance ToSchema hyperdata => ...@@ -438,18 +442,17 @@ instance ToSchema hyperdata =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId NodeTypeId
(Maybe NodeUserId) (Maybe NodeUserId)
NodeParentId NodeName NodeParentId NodeName
UTCTime hyperdata UTCTime hyperdata TSVector
) )
instance ToSchema hyperdata => instance ToSchema hyperdata =>
ToSchema (NodePoly NodeId NodeTypeId ToSchema (NodePoly NodeId NodeTypeId
NodeUserId NodeUserId
(Maybe NodeParentId) NodeName (Maybe NodeParentId) NodeName
UTCTime hyperdata UTCTime hyperdata TSVector
) )
instance ToSchema Status instance ToSchema Status
...@@ -7,6 +7,7 @@ packages: ...@@ -7,6 +7,7 @@ packages:
- 'deps/clustering-louvain' - 'deps/clustering-louvain'
- 'deps/patches-map' - 'deps/patches-map'
- 'deps/patches-class' - 'deps/patches-class'
- 'deps/haskell-opaleye'
allow-newer: true allow-newer: true
extra-deps: extra-deps:
...@@ -17,7 +18,7 @@ extra-deps: ...@@ -17,7 +18,7 @@ extra-deps:
- git: https://github.com/delanoe/servant-static-th.git - git: https://github.com/delanoe/servant-static-th.git
commit: ba5347e7d8a13ce5275af8470c15b2305fbb23af commit: ba5347e7d8a13ce5275af8470c15b2305fbb23af
- accelerate-1.2.0.0 - accelerate-1.2.0.0
- opaleye-0.6.7002.0 #- opaleye-0.6.7002.0
- aeson-lens-0.5.0.0 - aeson-lens-0.5.0.0
- duckling-0.1.3.0 - duckling-0.1.3.0
- full-text-search-0.2.1.4 - full-text-search-0.2.1.4
......
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