Commit d53349b4 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[Query] Search in Corpus To FacetDoc.

parent 905ef6b1
...@@ -17,7 +17,7 @@ module Gargantext.Database.TextSearch where ...@@ -17,7 +17,7 @@ module Gargantext.Database.TextSearch where
import Data.Aeson import Data.Aeson
import Data.List (intersperse) import Data.List (intersperse)
import Data.String (IsString(..)) import Data.String (IsString(..))
import Data.Text (Text, words, unpack) import Data.Text (Text, words, unpack, intercalate)
import Data.Time (UTCTime) import Data.Time (UTCTime)
import Database.PostgreSQL.Simple -- (Query, Connection) import Database.PostgreSQL.Simple -- (Query, Connection)
import Database.PostgreSQL.Simple.ToField import Database.PostgreSQL.Simple.ToField
...@@ -52,20 +52,18 @@ queryInDatabase _ q = proc () -> do ...@@ -52,20 +52,18 @@ queryInDatabase _ q = proc () -> do
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- | todo add limit and offset and order -- | todo add limit and offset and order
searchInCorpus :: Connection -> CorpusId -> Text -> IO [FacetDoc] searchInCorpus :: Connection -> CorpusId -> [Text] -> Maybe Offset -> Maybe Limit -> Maybe OrderBy -> IO [FacetDoc]
searchInCorpus c cId q = map toFacet <$> runQuery' searchInCorpus c cId q o l order = runQuery c (filterWith o l order $ queryInCorpus cId q')
where where
toFacet (nId, d, h) = FacetDoc nId d (maybe "Empty Title" identity $_hyperdataDocument_title h) h True 0 q' = intercalate " || " $ map stemIt q
runQuery' :: IO [(Int, UTCTime, HyperdataDocument)]
runQuery' = runQuery c (queryInCorpus cId q)
queryInCorpus :: CorpusId -> Text -> O.Query (Column PGInt4, Column PGTimestamptz, Column PGJsonb) queryInCorpus :: CorpusId -> Text -> O.Query FacetDocRead
queryInCorpus cId q = proc () -> do queryInCorpus cId q = proc () -> do
(n, nn) <- joinInCorpus -< () (n, nn) <- joinInCorpus -< ()
restrict -< ( nodeNode_node1_id nn) .== (toNullable $ pgInt4 cId) restrict -< ( nodeNode_node1_id nn) .== (toNullable $ pgInt4 cId)
restrict -< (_ns_search n) @@ (pgTSQuery (unpack q)) restrict -< (_ns_search n) @@ (pgTSQuery (unpack q))
restrict -< (_ns_typename n) .== (pgInt4 $ nodeTypeId NodeDocument) restrict -< (_ns_typename n) .== (pgInt4 $ nodeTypeId NodeDocument)
returnA -< (_ns_id n, _ns_date n, _ns_hyperdata n) returnA -< FacetDoc (_ns_id n) (_ns_date n) (_ns_name n) (_ns_hyperdata n) (pgBool True) (pgInt4 1)
joinInCorpus :: O.Query (NodeSearchRead, NodeNodeReadNull) joinInCorpus :: O.Query (NodeSearchRead, NodeNodeReadNull)
joinInCorpus = leftJoin queryNodeSearchTable queryNodeNodeTable cond joinInCorpus = leftJoin queryNodeSearchTable queryNodeNodeTable cond
......
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