Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Przemyslaw Kaminski
haskell-gargantext
Commits
ec633d46
Commit
ec633d46
authored
Jun 26, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] TEXT SEARCH API done (can be adapted for annuaire).
parent
13fab086
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
9 deletions
+122
-9
API.hs
src/Gargantext/API.hs
+7
-2
Count.hs
src/Gargantext/API/Count.hs
+0
-2
Search.hs
src/Gargantext/API/Search.hs
+107
-0
TextSearch.hs
src/Gargantext/Database/TextSearch.hs
+8
-5
No files found.
src/Gargantext/API.hs
View file @
ec633d46
...
...
@@ -68,7 +68,8 @@ import Gargantext.API.Node ( Roots , roots
,
NodeAPI
,
nodeAPI
,
NodesAPI
,
nodesAPI
)
import
Gargantext.API.Count
(
CountAPI
,
count
,
Query
)
import
Gargantext.API.Count
(
CountAPI
,
count
,
Query
)
import
Gargantext.API.Search
(
SearchAPI
,
search
,
SearchQuery
)
import
Gargantext.API.Orchestrator
import
Gargantext.API.Orchestrator.Types
...
...
@@ -199,7 +200,10 @@ type GargAPI = "user" :> Summary "First user endpoint"
-- :<|> "counts" :> Stream GET NewLineFraming '[JSON] Count :> CountAPI
:<|>
"count"
:>
Summary
"Count endpoint"
:>
ReqBody
'[
J
SON
]
Query
:>
CountAPI
:>
ReqBody
'[
J
SON
]
Query
:>
CountAPI
:<|>
"search"
:>
Summary
"Search endpoint"
:>
ReqBody
'[
J
SON
]
SearchQuery
:>
SearchAPI
-- :<|> "scraper" :> WithCallbacks ScraperAPI
...
...
@@ -226,6 +230,7 @@ server env = do
:<|>
nodeAPI
conn
:<|>
nodesAPI
conn
:<|>
count
:<|>
search
conn
-- :<|> orchestrator
where
conn
=
env
^.
env_conn
...
...
src/Gargantext/API/Count.hs
View file @
ec633d46
...
...
@@ -63,7 +63,6 @@ instance Arbitrary Scraper where
instance
ToSchema
Scraper
-----------------------------------------------------------------------
data
QueryBool
=
QueryBool
Text
deriving
(
Eq
,
Show
,
Generic
)
...
...
@@ -135,7 +134,6 @@ instance Arbitrary Counts where
instance
ToSchema
Counts
-----------------------------------------------------------------------
data
Count
=
Count
{
count_name
::
Scraper
,
count_count
::
Maybe
Int
...
...
src/Gargantext/API/Search.hs
0 → 100644
View file @
ec633d46
{-|
Module : Gargantext.API.Count
Description : Server API
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
Count API part of Gargantext.
-}
{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
module
Gargantext.API.Search
where
import
GHC.Generics
(
Generic
)
import
Control.Monad.IO.Class
(
liftIO
)
import
Prelude
(
Bounded
,
Enum
,
minBound
,
maxBound
)
import
Data.Aeson
hiding
(
Error
,
fieldLabelModifier
)
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Eq
(
Eq
())
import
Data.Either
import
Data.List
(
repeat
,
permutations
)
import
Data.Swagger
import
Data.Swagger.SchemaOptions
import
Data.Text
(
Text
,
pack
)
import
Database.PostgreSQL.Simple
(
Connection
)
import
Servant
import
Test.QuickCheck.Arbitrary
import
Test.QuickCheck
(
elements
)
-- import Control.Applicative ((<*>))
import
Gargantext.Prelude
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Gargantext.Database.TextSearch
-----------------------------------------------------------------------
data
SearchQuery
=
SearchQuery
{
sq_query
::
[
Text
]
,
sq_parent_id
::
Int
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"sq_"
)
''
S
earchQuery
)
instance
ToSchema
SearchQuery
where
declareNamedSchema
=
genericDeclareNamedSchema
defaultSchemaOptions
{
fieldLabelModifier
=
\
fieldLabel
->
drop
3
fieldLabel
}
instance
Arbitrary
SearchQuery
where
arbitrary
=
elements
[
SearchQuery
[
"query"
]
1
]
-----------------------------------------------------------------------
data
SearchResult
=
SearchResult
{
sr_id
::
Int
,
sr_name
::
Text
}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"sr_"
)
''
S
earchResult
)
instance
Arbitrary
SearchResult
where
arbitrary
=
elements
[
SearchResult
1
"name"
]
instance
ToSchema
SearchResult
where
declareNamedSchema
=
genericDeclareNamedSchema
defaultSchemaOptions
{
fieldLabelModifier
=
\
fieldLabel
->
drop
3
fieldLabel
}
-----------------------------------------------------------------------
data
SearchResults
=
SearchResults
{
srs_results
::
[
SearchResult
]}
deriving
(
Generic
)
$
(
deriveJSON
(
unPrefix
"srs_"
)
''
S
earchResults
)
instance
Arbitrary
SearchResults
where
arbitrary
=
SearchResults
<$>
arbitrary
instance
ToSchema
SearchResults
where
declareNamedSchema
=
genericDeclareNamedSchema
defaultSchemaOptions
{
fieldLabelModifier
=
\
fieldLabel
->
drop
4
fieldLabel
}
-----------------------------------------------------------------------
type
SearchAPI
=
Post
'[
J
SON
]
SearchResults
-----------------------------------------------------------------------
search
::
Connection
->
SearchQuery
->
Handler
SearchResults
search
c
(
SearchQuery
q
pId
)
=
liftIO
$
SearchResults
<$>
map
(
\
(
i
,
y
,
t
,
s
,
_
)
->
SearchResult
i
(
cs
$
encode
t
))
<$>
textSearch
c
(
toTSQuery
q
)
pId
5
0
Desc
src/Gargantext/Database/TextSearch.hs
View file @
ec633d46
...
...
@@ -33,6 +33,9 @@ import Gargantext.Prelude
newtype
TSQuery
=
UnsafeTSQuery
[
Text
]
toTSQuery
::
[
Text
]
->
TSQuery
toTSQuery
txt
=
UnsafeTSQuery
txt
instance
IsString
TSQuery
where
fromString
=
UnsafeTSQuery
.
words
.
cs
...
...
@@ -63,7 +66,7 @@ instance ToField Order
-- ADD ngrams count
-- TESTS
textSearchQuery
::
Query
textSearchQuery
=
"SELECT n.id, n.hyperdata->'publication_
date
'
\
textSearchQuery
=
"SELECT n.id, n.hyperdata->'publication_
year
'
\
\
, n.hyperdata->'title'
\
\
, n.hyperdata->'source'
\
\
, COALESCE(nn.score,null)
\
...
...
@@ -71,7 +74,7 @@ textSearchQuery = "SELECT n.id, n.hyperdata->'publication_date' \
\
LEFT JOIN nodes_nodes nn ON nn.node2_id = n.id
\
\
WHERE
\
\
n.title_abstract @@ (?::tsquery)
\
\
AND n.parent_id = ? AND n.typename = 4
\
\
AND n.parent_id = ? AND n.typename = 4
0
\
\
ORDER BY n.hyperdata -> 'publication_date' ?
\
\
offset ? limit ?;"
...
...
@@ -82,7 +85,7 @@ textSearch :: Connection
->
IO
[(
Int
,
Value
,
Value
,
Value
,
Maybe
Int
)]
textSearch
conn
q
p
l
o
ord
=
query
conn
textSearchQuery
(
q
,
p
,
ord
,
o
,
l
)
textSearchTest
::
TSQuery
->
IO
()
textSearchTest
q
=
connectGargandb
"gargantext.ini"
>>=
\
conn
->
textSearch
conn
q
421968
10
0
Asc
textSearchTest
::
ParentId
->
TSQuery
->
IO
()
textSearchTest
pId
q
=
connectGargandb
"gargantext.ini"
>>=
\
conn
->
textSearch
conn
q
pId
5
0
Asc
>>=
mapM_
print
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment