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
160
Issues
160
List
Board
Labels
Milestones
Merge Requests
14
Merge Requests
14
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
gargantext
haskell-gargantext
Commits
729e004f
Commit
729e004f
authored
Dec 07, 2021
by
Przemyslaw Kaminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[searx] some more searx parsing work
parent
fc1084bf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
24 deletions
+49
-24
New.hs
src/Gargantext/API/Node/Corpus/New.hs
+1
-1
Searx.hs
src/Gargantext/API/Node/Corpus/Searx.hs
+48
-23
No files found.
src/Gargantext/API/Node/Corpus/New.hs
View file @
729e004f
...
...
@@ -200,7 +200,7 @@ addToCorpusWithQuery user cid (WithQuery { _wq_query = q
Just
Web
->
do
printDebug
"[addToCorpusWithQuery] processing web request"
datafield
_
<-
triggerSearxSearch
cid
q
l
_
<-
triggerSearxSearch
user
cid
q
l
logStatus
pure
JobLog
{
_scst_succeeded
=
Just
3
,
_scst_failed
=
Just
0
...
...
src/Gargantext/API/Node/Corpus/Searx.hs
View file @
729e004f
...
...
@@ -17,19 +17,25 @@ import Network.HTTP.Client
import
Network.HTTP.Client.TLS
import
qualified
Prelude
as
Prelude
import
Protolude
(
encodeUtf8
,
Text
)
import
Protolude
(
catMaybes
,
encodeUtf8
,
rightToMaybe
,
Text
)
import
Gargantext.Prelude
import
Gargantext.Prelude.Config
import
Gargantext.API.Admin.Orchestrator.Types
(
JobLog
(
..
))
--import Gargantext.API.Admin.Types (HasSettings)
import
Gargantext.API.Job
(
jobLogSuccess
,
jobLogFailTotalWithMessage
)
import
Gargantext.Core
(
Lang
(
..
))
import
qualified
Gargantext.Core.Text.Corpus.API
as
API
import
Gargantext.Core.Text.Terms
(
TermType
(
..
))
import
Gargantext.Core.Types.Individu
(
User
(
..
))
import
Gargantext.Core.Utils.Prefix
(
unPrefix
)
import
Gargantext.Database.Action.Flow
(
flowDataText
,
DataText
(
..
))
import
Gargantext.Database.Action.Flow.Types
(
FlowCmdM
)
import
Gargantext.Database.Admin.Config
()
import
Gargantext.Database.Admin.Types.Hyperdata.Document
(
HyperdataDocument
(
..
))
import
Gargantext.Database.Admin.Types.Node
(
CorpusId
)
import
Gargantext.Database.Prelude
(
hasConfig
)
import
Gargantext.Database.Query.Table.Node
(
defaultList
)
import
Gargantext.Database.Query.Table.Node
(
defaultList
Maybe
)
langToSearx
::
Lang
->
Text
...
...
@@ -100,36 +106,55 @@ fetchSearxPage (FetchSearxParams { _fsp_language
-- TODO Make an async task out of this?
triggerSearxSearch
::
(
MonadBase
IO
m
,
FlowCmdM
env
err
m
)
=>
CorpusId
=>
User
->
CorpusId
->
API
.
Query
->
Lang
->
m
()
triggerSearxSearch
cId
q
l
=
do
->
(
JobLog
->
m
()
)
->
m
JobLog
triggerSearxSearch
user
cId
q
l
logStatus
=
do
let
jobLog
=
JobLog
{
_scst_succeeded
=
Just
1
,
_scst_failed
=
Just
0
,
_scst_remaining
=
Just
1
,
_scst_events
=
Just
[]
}
logStatus
jobLog
printDebug
"[triggerSearxSearch] cId"
cId
printDebug
"[triggerSearxSearch] q"
q
printDebug
"[triggerSearxSearch] l"
l
cfg
<-
view
hasConfig
let
surl
=
_gc_frame_searx_url
cfg
printDebug
"[triggerSearxSearch] surl"
surl
listId
<-
defaultList
cId
printDebug
"[triggerSearxSearch] listId"
listId
manager
<-
liftBase
$
newManager
tlsManagerSettings
res
<-
liftBase
$
fetchSearxPage
$
FetchSearxParams
{
_fsp_language
=
l
,
_fsp_manager
=
manager
,
_fsp_pageno
=
1
,
_fsp_query
=
q
,
_fsp_url
=
surl
}
mListId
<-
defaultListMaybe
cId
case
mListId
of
Nothing
->
do
let
failedJobLog
=
jobLogFailTotalWithMessage
"[triggerSearxSearch] no list id"
jobLog
logStatus
failedJobLog
pure
failedJobLog
Just
listId
->
do
printDebug
"[triggerSearxSearch] listId"
listId
manager
<-
liftBase
$
newManager
tlsManagerSettings
res
<-
liftBase
$
fetchSearxPage
$
FetchSearxParams
{
_fsp_language
=
l
,
_fsp_manager
=
manager
,
_fsp_pageno
=
1
,
_fsp_query
=
q
,
_fsp_url
=
surl
}
printDebug
"[triggerSearxSearch] res"
res
_
<-
case
res
of
Left
_
->
pure
()
Right
(
SearxResponse
{
_srs_results
})
->
do
let
docs
=
hyperdataDocumentFromSearxResult
<$>
_srs_results
printDebug
"[triggerSearxSearch] docs"
docs
pure
()
printDebug
"[triggerSearxSearch] res"
res
case
res
of
Left
_
->
pure
()
Right
(
SearxResponse
{
_srs_results
})
->
do
let
docs
=
hyperdataDocumentFromSearxResult
<$>
_srs_results
printDebug
"[triggerSearxSearch] docs"
docs
-- docs :: [Either Text HyperdataDocument]
let
docs'
=
catMaybes
$
rightToMaybe
<$>
docs
_
<-
flowDataText
user
(
DataNew
[
docs'
])
(
Multi
EN
)
cId
Nothing
logStatus
pure
()
pure
$
jobLogSuccess
jobLog
hyperdataDocumentFromSearxResult
::
SearxResult
->
Either
T
.
Text
HyperdataDocument
hyperdataDocumentFromSearxResult
(
SearxResult
{
_sr_content
,
_sr_engine
,
_sr_pubdate
,
_sr_title
})
=
do
...
...
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