Commit 1d311b08 authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[search] include search in abstract for documents

parent eed1436a
......@@ -39,8 +39,7 @@ import Data.Profunctor.Product (p4)
import qualified Opaleye as O hiding (Order)
------------------------------------------------------------------------
searchDocInDatabase :: HasDBid NodeType
=> ParentId
searchDocInDatabase :: ParentId
-> Text
-> Cmd err [(NodeId, HyperdataDocument)]
searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t)
......@@ -55,8 +54,7 @@ searchDocInDatabase p t = runOpaQuery (queryDocInDatabase p t)
------------------------------------------------------------------------
-- | todo add limit and offset and order
searchInCorpus :: HasDBid NodeType
=> CorpusId
searchInCorpus :: CorpusId
-> IsTrash
-> [Text]
-> Maybe Offset
......@@ -69,8 +67,7 @@ searchInCorpus cId t q o l order = runOpaQuery
$ intercalate " | "
$ map stemIt q
searchCountInCorpus :: HasDBid NodeType
=> CorpusId
searchCountInCorpus :: CorpusId
-> IsTrash
-> [Text]
-> Cmd err Int
......@@ -79,8 +76,7 @@ searchCountInCorpus cId t q = runCountOpaQuery
$ intercalate " | "
$ map stemIt q
queryInCorpus :: HasDBid NodeType
=> CorpusId
queryInCorpus :: CorpusId
-> IsTrash
-> Text
-> O.Query FacetDocRead
......@@ -108,8 +104,7 @@ joinInCorpus = leftJoin queryNodeSearchTable queryNodeNodeTable cond
------------------------------------------------------------------------
searchInCorpusWithContacts
:: HasDBid NodeType
=> CorpusId
:: CorpusId
-> AnnuaireId
-> [Text]
-> Maybe Offset
......@@ -125,8 +120,7 @@ searchInCorpusWithContacts cId aId q o l _order =
$ map stemIt q
selectContactViaDoc
:: HasDBid NodeType
=> CorpusId
:: CorpusId
-> AnnuaireId
-> Text
-> QueryArr ()
......@@ -148,8 +142,7 @@ selectContactViaDoc cId aId q = proc () -> do
, toNullable $ pgInt4 1
)
selectGroup :: HasDBid NodeType
=> NodeId
selectGroup :: NodeId
-> NodeId
-> Text
-> Select FacetPairedReadNull
......@@ -267,8 +260,7 @@ textSearchQuery = "SELECT n.id, n.hyperdata->'publication_year' \
-- Example:
-- textSearchTest :: ParentId -> TSQuery -> Cmd err [(Int, Value, Value, Value, Value, Maybe Int)]
-- textSearchTest pId q = textSearch q pId 5 0 Asc
textSearch :: HasDBid NodeType
=> TSQuery -> ParentId
textSearch :: TSQuery -> ParentId
-> Limit -> Offset -> Order
-> Cmd err [(Int,Value,Value,Value, Value, Maybe Int)]
textSearch q p l o ord = runPGSQuery textSearchQuery (q,p,p,typeId,ord,o,l)
......
......@@ -59,6 +59,7 @@ import qualified Opaleye.Internal.Unpackspec()
import Gargantext.Core
import Gargantext.Core.Types
import Gargantext.Core.Utils.Prefix (unPrefix, unPrefixSwagger, wellNamedSchema)
import Gargantext.Database.Admin.Config() -- HasDBid NodeType
import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Query.Filter
import Gargantext.Database.Query.Join (leftJoin5)
......@@ -67,6 +68,7 @@ import Gargantext.Database.Query.Table.NodeNode
import Gargantext.Database.Query.Table.NodeNodeNgrams
import Gargantext.Database.Prelude
import Gargantext.Database.Schema.Node
--import Gargantext.Prelude (printDebug)
------------------------------------------------------------------------
-- | DocFacet
......@@ -305,22 +307,23 @@ runViewDocuments :: HasDBid NodeType
runViewDocuments cId t o l order query = do
runOpaQuery $ filterWith o l order sqlQuery
where
ntId = toDBid NodeDocument
sqlQuery = viewDocuments cId t ntId query
sqlQuery = viewDocuments cId t query
runCountDocuments :: HasDBid NodeType => CorpusId -> IsTrash -> Maybe Text -> Cmd err Int
runCountDocuments cId t mQuery = do
--printDebug "[runViewDocuments] query" $ showSql sqlQuery
runCountOpaQuery sqlQuery
where
sqlQuery = viewDocuments cId t (toDBid NodeDocument) mQuery
sqlQuery = viewDocuments cId t mQuery
viewDocuments :: CorpusId
-> IsTrash
-> NodeTypeId
-> Maybe Text
-> Query FacetDocRead
viewDocuments cId t ntId mQuery = proc () -> do
viewDocuments cId t mQuery = proc () -> do
let ntId = toDBid NodeDocument
n <- queryNodeTable -< ()
nn <- queryNodeNodeTable -< ()
restrict -< n^.node_id .== nn^.nn_node2_id
......@@ -331,7 +334,11 @@ viewDocuments cId t ntId mQuery = proc () -> do
let query = (fromMaybe "" mQuery)
iLikeQuery = T.intercalate "" ["%", query, "%"]
restrict -< (n^.node_name) `ilike` (pgStrictText iLikeQuery)
restrict -< ((n^.node_name) `ilike` (pgStrictText iLikeQuery)) .||
((fromNullable (pgStrictText "") ((toNullable $ n^.node_hyperdata) .->> (pgStrictText "source"))) `ilike` (pgStrictText iLikeQuery))
--((n^.node_hyperdata .:? "source") `ilike` (pgStrictText iLikeQuery))
-- NOTE Title is under node_name
-- Abstract is under node_hyperdata -> source
returnA -< FacetDoc (_node_id n)
(_node_date n)
......
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