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
157
Issues
157
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
e033a808
Commit
e033a808
authored
Apr 19, 2018
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FEAT] query search to && bool (thx
@np
).
parent
d6aae281
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
20 deletions
+41
-20
TextSearch.hs
src/Gargantext/Database/TextSearch.hs
+41
-20
No files found.
src/Gargantext/Database/TextSearch.hs
View file @
e033a808
...
...
@@ -17,51 +17,72 @@ commentary with @some markup@.
module
Gargantext.Database.TextSearch
where
import
Prelude
(
print
)
import
Gargantext
(
connectGargandb
)
import
Control.Monad
import
Data.Aeson
import
Data.List
(
intersperse
)
import
Data.String
(
IsString
(
..
))
import
Data.Text
(
Text
,
words
)
import
Database.PostgreSQL.Simple
import
Control.Applicative
import
Control.Monad
import
Data.Text
(
Text
)
import
Database.PostgreSQL.Simple.ToField
import
Gargantext
(
connectGargandb
)
import
Gargantext.Prelude
newtype
TSQuery
=
UnsafeTSQuery
[
Text
]
instance
IsString
TSQuery
where
fromString
=
UnsafeTSQuery
.
words
.
cs
instance
ToField
TSQuery
where
toField
(
UnsafeTSQuery
xs
)
=
Many
$
intersperse
(
Plain
" && "
)
$
map
(
\
q
->
Many
[
Plain
"plainto_tsquery("
,
Escape
(
cs
q
)
,
Plain
")"
]
)
xs
type
TextQuery
=
Text
type
ParentId
=
Int
type
Limit
=
Int
type
Offset
=
Int
data
Order
=
Asc
|
Desc
data
Order
=
Asc
|
Desc
toQuery
::
Order
->
Query
toQuery
Asc
=
"ASC"
toQuery
Desc
=
"DESC"
instance
ToField
Order
where
toField
Asc
=
Plain
"ASC"
toField
Desc
=
Plain
"DESC"
-- TODO
-- FIX fav
-- ADD ngrams count
-- TESTS
textSearchQuery
::
Order
->
Query
textSearchQuery
o
=
"SELECT n.id, n.hyperdata ->
'publication_date'
\
\
, n.hyperdata
->
'title'
\
\
, n.hyperdata
->
'source'
\
textSearchQuery
::
Query
textSearchQuery
=
"SELECT n.id, n.hyperdata->
'publication_date'
\
\
, n.hyperdata
->
'title'
\
\
, n.hyperdata
->
'source'
\
\
, COALESCE(nn.score,null)
\
\
FROM nodes n
\
\
LEFT JOIN nodes_nodes nn ON nn.node2_id = n.id
\
\
WHERE
\
\
n.title_abstract @@
to_tsquery(?
)
\
\
n.title_abstract @@
(?::tsquery
)
\
\
AND n.parent_id = ? AND n.typename = 4
\
\
ORDER BY n.hyperdata -> 'publication_date'
"
<>
toQuery
o
<>
"
offset ? limit ?;"
\
ORDER BY n.hyperdata -> 'publication_date'
?
\
\
offset ? limit ?;"
textSearch
::
Connection
->
T
ext
Query
->
ParentId
->
T
S
Query
->
ParentId
->
Limit
->
Offset
->
Order
->
IO
[(
Int
,
Value
,
Value
,
Value
,
Maybe
Int
)]
textSearch
conn
q
p
l
o
ord
=
query
conn
(
textSearchQuery
ord
)
(
q
,
p
,
o
,
l
)
textSearch
conn
q
p
l
o
ord
=
query
conn
textSearchQuery
(
q
,
p
,
ord
,
o
,
l
)
textSearchTest
::
T
ext
Query
->
IO
()
textSearchTest
::
T
S
Query
->
IO
()
textSearchTest
q
=
connectGargandb
"gargantext.ini"
>>=
\
conn
->
textSearch
conn
q
421968
10
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