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
e3241819
Commit
e3241819
authored
Aug 19, 2024
by
Alfredo Di Napoli
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow more results from partial match search
parent
d6c03dc3
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
12 deletions
+30
-12
cabal.project
cabal.project
+1
-1
cabal.project.freeze
cabal.project.freeze
+1
-1
gargantext.cabal
gargantext.cabal
+1
-1
Search.hs
src/Gargantext/Database/Action/Search.hs
+27
-9
No files found.
cabal.project
View file @
e3241819
...
...
@@ -29,7 +29,7 @@ source-repository-package
source
-
repository
-
package
type
:
git
location
:
https
://
gitlab
.
iscpif
.
fr
/
gargantext
/
opaleye
-
textsearch
.
git
tag
:
cb07b604bfb7a22aa21dd8918de5cb65c8a4bdf1
tag
:
04
b5c9044fef44393b66bffa258ca0b0f59c1087
source
-
repository
-
package
type
:
git
...
...
cabal.project.freeze
View file @
e3241819
...
...
@@ -387,7 +387,7 @@ constraints: any.Cabal ==3.8.1.0,
any.old-locale ==1.0.0.7,
any.old-time ==1.1.0.3,
any.opaleye ==0.9.6.1,
any.opaleye-textsearch ==0.
1
.0.0,
any.opaleye-textsearch ==0.
2
.0.0,
any.openalex ==0.1.0.0,
any.optics-core ==0.4.1.1,
optics-core -explicit-generic-labels,
...
...
gargantext.cabal
View file @
e3241819
...
...
@@ -605,7 +605,7 @@ library
, network >= 3.1.4.0
, network-uri ^>= 2.6.4.1
, opaleye ^>= 0.9.6.1
, opaleye-textsearch >= 0.
1
.0.0
, opaleye-textsearch >= 0.
2
.0.0
, openalex
, pandoc ^>= 2.14.0.3
, parallel ^>= 3.2.2.0
...
...
src/Gargantext/Database/Action/Search.hs
View file @
e3241819
...
...
@@ -61,7 +61,9 @@ import Opaleye.TextSearch
--
queryToTsSearch
::
API
.
Query
->
Field
SqlTSQuery
queryToTsSearch
q
=
sqlToTSQuery
$
T
.
unpack
$
API
.
interpretQuery
q
transformAST
queryToTsSearch
q
=
let
(
dictionary
,
transformed
)
=
API
.
interpretQuery
q
transformAST
in
sqlToTSQuery
dictionary
(
T
.
unpack
transformed
)
where
-- It's important to understand how things work under the hood: When we perform
...
...
@@ -97,29 +99,45 @@ queryToTsSearch q = sqlToTSQuery $ T.unpack $ API.interpretQuery q transformAST
API
.
QT_partial_match
(
Term
term
)
->
stem
EN
GargPorterAlgorithm
term
<>
":*"
transformAST
::
BoolExpr
[
API
.
QueryTerm
]
->
T
.
Text
-- Transforms the input query terms and returns the full SQL query to feed Postgres AND
-- the dictionary to use, see: https://www.postgresql.org/docs/current/textsearch-dictionaries.html
-- In a nutshell, if we have a partial match operator in our query, we use the \"simple\" dictionary
-- under the hood, which won't filter stop words, which are sometimes useful, see issue #265.
transformAST
::
BoolExpr
[
API
.
QueryTerm
]
->
(
Maybe
Dictionary
,
T
.
Text
)
transformAST
ast
=
case
ast
of
BAnd
sub1
sub2
->
" ("
<>
transformAST
sub1
<>
" & "
<>
transformAST
sub2
<>
") "
->
let
(
d1
,
sub1Expr
)
=
transformAST
sub1
(
d2
,
sub2Expr
)
=
transformAST
sub2
in
(
d1
<|>
d2
,
" ("
<>
sub1Expr
<>
" & "
<>
sub2Expr
<>
") "
)
BOr
sub1
sub2
->
" ("
<>
transformAST
sub1
<>
" | "
<>
transformAST
sub2
<>
") "
->
let
(
d1
,
sub1Expr
)
=
transformAST
sub1
(
d2
,
sub2Expr
)
=
transformAST
sub2
in
(
d1
<|>
d2
,
" ("
<>
sub1Expr
<>
" | "
<>
sub2Expr
<>
") "
)
BNot
(
BConst
(
Negative
term
))
->
transformAST
(
BConst
(
Positive
term
))
-- double negation
BNot
sub
->
"!"
<>
transformAST
sub
->
second
(
\
e
->
"!"
<>
e
)
$
transformAST
sub
-- BTrue cannot happen is the query parser doesn't support parsing 'TRUE' alone.
BTrue
->
T
.
empty
->
(
Nothing
,
T
.
empty
)
-- BTrue cannot happen is the query parser doesn't support parsing 'FALSE' alone.
BFalse
->
T
.
empty
->
(
Nothing
,
T
.
empty
)
BConst
(
Positive
queryTerms
)
->
renderQueryTerms
queryTerms
->
(
pickDictionary
queryTerms
,
renderQueryTerms
queryTerms
)
-- We can handle negatives via `ANDNOT` with itself.
BConst
(
Negative
queryTerms
)
->
"!"
<>
renderQueryTerms
queryTerms
->
(
pickDictionary
queryTerms
,
"!"
<>
renderQueryTerms
queryTerms
)
pickDictionary
::
[
API
.
QueryTerm
]
->
Maybe
Dictionary
pickDictionary
qs
=
if
any
isPartialMatch
qs
then
Just
(
Dictionary
"simple"
)
else
Nothing
where
isPartialMatch
::
API
.
QueryTerm
->
Bool
isPartialMatch
=
\
case
API
.
QT_partial_match
{}
->
True
_
->
False
------------------------------------------------------------------------
searchDocInDatabase
::
HasDBid
NodeType
=>
ParentId
...
...
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