Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
erp5
Commits
3b9b48b9
Commit
3b9b48b9
authored
Nov 19, 2014
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fulltext: escape some characters in Mroonga boolean search queries.
parent
10e171cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
2 deletions
+18
-2
product/ERP5/tests/testI18NSearch.py
product/ERP5/tests/testI18NSearch.py
+11
-0
product/ZSQLCatalog/Operator/ComparisonOperator.py
product/ZSQLCatalog/Operator/ComparisonOperator.py
+7
-2
No files found.
product/ERP5/tests/testI18NSearch.py
View file @
3b9b48b9
...
...
@@ -51,6 +51,11 @@ class TestI18NSearch(ERP5TypeTestCase):
last_name
=
'実篤'
,
description
=
'Slow white fox jumps over the diligent dog.'
,
)
person3
=
person_module
.
newContent
(
portal_type
=
'Person'
,
first_name
=
'( - + )'
,
last_name
=
''
,
)
self
.
tic
()
# check if 'é' == 'e' collation works
...
...
@@ -77,6 +82,12 @@ class TestI18NSearch(ERP5TypeTestCase):
self
.
assertEqual
(
len
(
result
),
1
)
self
.
assertEqual
(
result
[
0
].
getPath
(),
person1
.
getPath
())
# check search with a special character
for
query
in
(
'('
,
')'
,
):
result
=
person_module
.
searchFolder
(
title
=
query
)
self
.
assertEqual
(
len
(
result
),
1
)
self
.
assertEqual
(
result
[
0
].
getPath
(),
person3
.
getPath
())
# check fulltext search for automatically generated related keys.
self
.
assertTrue
(
'MATCH'
in
self
.
portal
.
portal_catalog
(
destination_title
=
'Faure'
,
src__
=
1
))
...
...
product/ZSQLCatalog/Operator/ComparisonOperator.py
View file @
3b9b48b9
...
...
@@ -139,6 +139,11 @@ class MroongaComparisonOperator(MatchComparisonOperator):
MatchComparisonOperator
.
__init__
(
self
,
operator
,
' IN BOOLEAN MODE'
)
self
.
force_boolean
=
force_boolean
def
_escape
(
self
,
query_string
):
# TODO : We need to escape more invalid boolean operator usage
# like '+' or '-' without any letter.
return
re
.
compile
(
r'([()])'
).
sub
(
r'\\\
g<
1>'
,
query_string
)
def
renderValue
(
self
,
value_list
):
"""
Special Query renderer for MroongaFullText queries:
...
...
@@ -153,7 +158,7 @@ class MroongaComparisonOperator(MatchComparisonOperator):
if
self
.
force_boolean
:
fulltext_query
=
'*D+ %s'
%
value_list
return
self
.
_renderValue
(
fulltext_query
)
return
self
.
_renderValue
(
self
.
_escape
(
fulltext_query
)
)
else
:
match_query_list
=
[]
match_boolean_query_list
=
[]
...
...
@@ -170,7 +175,7 @@ class MroongaComparisonOperator(MatchComparisonOperator):
if
match_query_list
:
fulltext_query
+=
' *S"%s"'
%
' '
.
join
(
match_query_list
)
if
match_boolean_query_list
:
fulltext_query
+=
' %s'
%
' '
.
join
(
match_boolean_query_list
)
fulltext_query
+=
' %s'
%
self
.
_escape
(
' '
.
join
(
match_boolean_query_list
)
)
return
self
.
_renderValue
(
fulltext_query
)
verifyClass
(
IOperator
,
MroongaComparisonOperator
)
...
...
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