Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
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
Christian Merten
haskell-gargantext
Commits
1c88fb91
Commit
1c88fb91
authored
May 02, 2023
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `NgramsSearchQuery` type
parent
4843c6b5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
36 deletions
+56
-36
Ngrams.hs
src/Gargantext/API/Ngrams.hs
+4
-35
Types.hs
src/Gargantext/API/Ngrams/Types.hs
+43
-1
Query.hs
src/Gargantext/Core/Types/Query.hs
+9
-0
No files found.
src/Gargantext/API/Ngrams.hs
View file @
1c88fb91
...
@@ -85,8 +85,6 @@ module Gargantext.API.Ngrams
...
@@ -85,8 +85,6 @@ module Gargantext.API.Ngrams
import
Control.Concurrent
import
Control.Concurrent
import
Control.Lens
((
.~
),
view
,
(
^.
),
(
^..
),
(
+~
),
(
%~
),
(
.~
),
msumOf
,
at
,
_Just
,
Each
(
..
),
(
%%~
),
mapped
,
ifolded
,
to
,
withIndex
)
import
Control.Lens
((
.~
),
view
,
(
^.
),
(
^..
),
(
+~
),
(
%~
),
(
.~
),
msumOf
,
at
,
_Just
,
Each
(
..
),
(
%%~
),
mapped
,
ifolded
,
to
,
withIndex
)
import
Control.Monad.Reader
import
Control.Monad.Reader
import
Data.Aeson
hiding
((
.=
))
import
Data.Either
(
Either
(
..
))
import
Data.Foldable
import
Data.Foldable
import
Data.Map.Strict
(
Map
)
import
Data.Map.Strict
(
Map
)
import
Data.Maybe
(
fromMaybe
)
import
Data.Maybe
(
fromMaybe
)
...
@@ -94,11 +92,9 @@ import Data.Monoid
...
@@ -94,11 +92,9 @@ import Data.Monoid
import
Data.Ord
(
Down
(
..
))
import
Data.Ord
(
Down
(
..
))
import
Data.Patch.Class
(
Action
(
act
),
Transformable
(
..
),
ours
)
import
Data.Patch.Class
(
Action
(
act
),
Transformable
(
..
),
ours
)
import
Data.Set
(
Set
)
import
Data.Set
(
Set
)
import
Data.Swagger
hiding
(
version
,
patch
)
import
Data.Text
(
Text
,
isInfixOf
,
toLower
,
unpack
)
import
Data.Text
(
Text
,
isInfixOf
,
toLower
,
unpack
,
pack
)
import
Data.Text.Lazy.IO
as
DTL
import
Data.Text.Lazy.IO
as
DTL
import
Formatting
(
hprint
,
int
,
(
%
))
import
Formatting
(
hprint
,
int
,
(
%
))
import
GHC.Generics
(
Generic
)
import
Gargantext.API.Admin.EnvTypes
(
Env
,
GargJob
(
..
))
import
Gargantext.API.Admin.EnvTypes
(
Env
,
GargJob
(
..
))
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
),
AsyncJobs
)
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
),
AsyncJobs
)
import
Gargantext.API.Admin.Types
(
HasSettings
)
import
Gargantext.API.Admin.Types
(
HasSettings
)
...
@@ -106,7 +102,7 @@ import Gargantext.API.Ngrams.Types
...
@@ -106,7 +102,7 @@ import Gargantext.API.Ngrams.Types
import
Gargantext.API.Prelude
import
Gargantext.API.Prelude
import
Gargantext.Core.NodeStory
import
Gargantext.Core.NodeStory
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
,
ListId
,
DocId
,
TODO
,
assertValid
,
HasInvalidError
,
ContextId
)
import
Gargantext.Core.Types
(
ListType
(
..
),
NodeId
,
ListId
,
DocId
,
TODO
,
assertValid
,
HasInvalidError
,
ContextId
)
import
Gargantext.Core.Types.Query
(
Limit
(
..
),
Offset
(
..
))
import
Gargantext.Core.Types.Query
(
Limit
(
..
),
Offset
(
..
)
,
MinSize
(
..
),
MaxSize
(
..
)
)
import
Gargantext.API.Ngrams.Tools
import
Gargantext.API.Ngrams.Tools
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Flow.Types
import
Gargantext.Database.Action.Metrics.NgramsByContext
(
getOccByNgramsOnlyFast
)
import
Gargantext.Database.Action.Metrics.NgramsByContext
(
getOccByNgramsOnlyFast
)
...
@@ -124,8 +120,6 @@ import Prelude (error)
...
@@ -124,8 +120,6 @@ import Prelude (error)
import
Servant
hiding
(
Patch
)
import
Servant
hiding
(
Patch
)
import
Gargantext.Utils.Jobs
(
serveJobsAPI
,
MonadJobStatus
(
..
))
import
Gargantext.Utils.Jobs
(
serveJobsAPI
,
MonadJobStatus
(
..
))
import
System.IO
(
stderr
)
import
System.IO
(
stderr
)
import
Test.QuickCheck
(
elements
)
import
Test.QuickCheck.Arbitrary
(
Arbitrary
,
arbitrary
)
import
qualified
Data.Aeson.Text
as
DAT
import
qualified
Data.Aeson.Text
as
DAT
import
qualified
Data.List
as
List
import
qualified
Data.List
as
List
import
qualified
Data.Map.Strict
as
Map
import
qualified
Data.Map.Strict
as
Map
...
@@ -521,9 +515,6 @@ dumpJsonTableMap fpath nodeId ngramsType = do
...
@@ -521,9 +515,6 @@ dumpJsonTableMap fpath nodeId ngramsType = do
pure
()
pure
()
type
MinSize
=
Int
type
MaxSize
=
Int
-- | TODO Errors management
-- | TODO Errors management
-- TODO: polymorphic for Annuaire or Corpus or ...
-- TODO: polymorphic for Annuaire or Corpus or ...
-- | Table of Ngrams is a ListNgrams formatted (sorted and/or cut).
-- | Table of Ngrams is a ListNgrams formatted (sorted and/or cut).
...
@@ -548,8 +539,8 @@ getTableNgrams _nType nId tabType listId limit_ offset
...
@@ -548,8 +539,8 @@ getTableNgrams _nType nId tabType listId limit_ offset
ngramsType
=
ngramsTypeFromTabType
tabType
ngramsType
=
ngramsTypeFromTabType
tabType
offset'
=
getOffset
$
maybe
0
identity
offset
offset'
=
getOffset
$
maybe
0
identity
offset
listType'
=
maybe
(
const
True
)
(
==
)
listType
listType'
=
maybe
(
const
True
)
(
==
)
listType
minSize'
=
maybe
(
const
True
)
(
<=
)
minSize
minSize'
=
maybe
(
const
True
)
(
<=
)
(
getMinSize
<$>
minSize
)
maxSize'
=
maybe
(
const
True
)
(
>=
)
maxSize
maxSize'
=
maybe
(
const
True
)
(
>=
)
(
getMaxSize
<$>
maxSize
)
rootOf
tableMap
ne
=
maybe
ne
(
\
r
->
fromMaybe
(
panic
"getTableNgrams: invalid root"
)
rootOf
tableMap
ne
=
maybe
ne
(
\
r
->
fromMaybe
(
panic
"getTableNgrams: invalid root"
)
(
tableMap
^.
at
r
)
(
tableMap
^.
at
r
)
...
@@ -694,28 +685,6 @@ scoresRecomputeTableNgrams nId tabType listId = do
...
@@ -694,28 +685,6 @@ scoresRecomputeTableNgrams nId tabType listId = do
-- TODO: find a better place for the code above, All APIs stay here
-- TODO: find a better place for the code above, All APIs stay here
data
OrderBy
=
TermAsc
|
TermDesc
|
ScoreAsc
|
ScoreDesc
deriving
(
Generic
,
Enum
,
Bounded
,
Read
,
Show
)
instance
FromHttpApiData
OrderBy
where
parseUrlPiece
"TermAsc"
=
pure
TermAsc
parseUrlPiece
"TermDesc"
=
pure
TermDesc
parseUrlPiece
"ScoreAsc"
=
pure
ScoreAsc
parseUrlPiece
"ScoreDesc"
=
pure
ScoreDesc
parseUrlPiece
_
=
Left
"Unexpected value of OrderBy"
instance
ToHttpApiData
OrderBy
where
toUrlPiece
=
pack
.
show
instance
ToParamSchema
OrderBy
instance
FromJSON
OrderBy
instance
ToJSON
OrderBy
instance
ToSchema
OrderBy
instance
Arbitrary
OrderBy
where
arbitrary
=
elements
[
minBound
..
maxBound
]
needsScores
::
Maybe
OrderBy
->
Bool
needsScores
::
Maybe
OrderBy
->
Bool
needsScores
(
Just
ScoreAsc
)
=
True
needsScores
(
Just
ScoreAsc
)
=
True
needsScores
(
Just
ScoreDesc
)
=
True
needsScores
(
Just
ScoreDesc
)
=
True
...
...
src/Gargantext/API/Ngrams/Types.hs
View file @
1c88fb91
...
@@ -40,7 +40,8 @@ import Database.PostgreSQL.Simple.FromField (FromField, fromField, fromJSONField
...
@@ -40,7 +40,8 @@ import Database.PostgreSQL.Simple.FromField (FromField, fromField, fromJSONField
import
Database.PostgreSQL.Simple.ToField
(
ToField
,
toJSONField
,
toField
)
import
Database.PostgreSQL.Simple.ToField
(
ToField
,
toJSONField
,
toField
)
import
GHC.Generics
(
Generic
)
import
GHC.Generics
(
Generic
)
import
Gargantext.Core.Text
(
size
)
import
Gargantext.Core.Text
(
size
)
import
Gargantext.Core.Types
(
ListType
(
..
),
ListId
,
NodeId
,
TODO
)
import
Gargantext.Core.Types
(
ListType
(
..
),
ListId
,
NodeId
,
NodeType
,
TODO
)
import
Gargantext.Core.Types.Query
(
Limit
,
Offset
,
MaxSize
,
MinSize
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixUntagged
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Core.Utils.Prefix
(
unPrefix
,
unPrefixUntagged
,
unPrefixSwagger
,
wellNamedSchema
)
import
Gargantext.Database.Admin.Types.Node
(
ContextId
)
import
Gargantext.Database.Admin.Types.Node
(
ContextId
)
import
Gargantext.Database.Prelude
(
fromField'
,
HasConnectionPool
,
HasConfig
,
CmdM
'
)
import
Gargantext.Database.Prelude
(
fromField'
,
HasConnectionPool
,
HasConfig
,
CmdM
'
)
...
@@ -268,6 +269,47 @@ instance Arbitrary NgramsTable where
...
@@ -268,6 +269,47 @@ instance Arbitrary NgramsTable where
instance
ToSchema
NgramsTable
instance
ToSchema
NgramsTable
------------------------------------------------------------------------
-- Searching in a Ngram Table
data
OrderBy
=
TermAsc
|
TermDesc
|
ScoreAsc
|
ScoreDesc
deriving
(
Generic
,
Enum
,
Bounded
,
Read
,
Show
)
instance
FromHttpApiData
OrderBy
where
parseUrlPiece
"TermAsc"
=
pure
TermAsc
parseUrlPiece
"TermDesc"
=
pure
TermDesc
parseUrlPiece
"ScoreAsc"
=
pure
ScoreAsc
parseUrlPiece
"ScoreDesc"
=
pure
ScoreDesc
parseUrlPiece
_
=
Left
"Unexpected value of OrderBy"
instance
ToHttpApiData
OrderBy
where
toUrlPiece
=
pack
.
show
instance
ToParamSchema
OrderBy
instance
FromJSON
OrderBy
instance
ToJSON
OrderBy
instance
ToSchema
OrderBy
instance
Arbitrary
OrderBy
where
arbitrary
=
elements
[
minBound
..
maxBound
]
-- | A query on a 'NgramsTable'.
data
NgramsSearchQuery
=
NgramsSearchQuery
{
_nsq_nodeType
::
!
NodeType
,
_nsq_nodeId
::
!
NodeId
,
_nsq_tabType
::
!
TabType
,
_nsq_listId
::
!
ListId
,
_nsq_limit
::
!
Limit
,
_nsq_offset
::
!
(
Maybe
Offset
)
,
_nsq_listType
::
!
(
Maybe
ListType
)
,
_nsq_minSize
::
!
(
Maybe
MinSize
)
,
_nsq_maxSize
::
!
(
Maybe
MaxSize
)
,
_nsq_orderBy
::
!
(
Maybe
OrderBy
)
,
_nsq_searchQuery
::
!
(
NgramsTerm
->
Bool
)
}
------------------------------------------------------------------------
------------------------------------------------------------------------
type
NgramsTableMap
=
Map
NgramsTerm
NgramsRepoElement
type
NgramsTableMap
=
Map
NgramsTerm
NgramsRepoElement
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Core/Types/Query.hs
View file @
1c88fb91
...
@@ -28,3 +28,12 @@ newtype Offset = Offset { getOffset :: Int }
...
@@ -28,3 +28,12 @@ newtype Offset = Offset { getOffset :: Int }
,
Servant
.
FromHttpApiData
,
Servant
.
ToHttpApiData
,
Servant
.
FromHttpApiData
,
Servant
.
ToHttpApiData
,
Swagger
.
ToParamSchema
,
Swagger
.
ToSchema
)
,
Swagger
.
ToParamSchema
,
Swagger
.
ToSchema
)
type
IsTrash
=
Bool
type
IsTrash
=
Bool
newtype
MinSize
=
MinSize
{
getMinSize
::
Int
}
deriving
newtype
(
Show
,
Eq
,
Num
,
Servant
.
FromHttpApiData
,
Servant
.
ToHttpApiData
,
Swagger
.
ToParamSchema
,
Swagger
.
ToSchema
)
newtype
MaxSize
=
MaxSize
{
getMaxSize
::
Int
}
deriving
newtype
(
Show
,
Eq
,
Num
,
Servant
.
FromHttpApiData
,
Servant
.
ToHttpApiData
,
Swagger
.
ToParamSchema
,
Swagger
.
ToSchema
)
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