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
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Romain Courteaud
erp5
Commits
ce77af41
Commit
ce77af41
authored
Oct 04, 2015
by
Kazuhiko Shiozaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include table name in fulltext search score's alias.
parent
4b37cb22
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
14 deletions
+17
-14
product/ERP5/tests/testI18NSearch.py
product/ERP5/tests/testI18NSearch.py
+4
-4
product/ZSQLCatalog/ColumnMap.py
product/ZSQLCatalog/ColumnMap.py
+8
-2
product/ZSQLCatalog/Operator/ComparisonOperator.py
product/ZSQLCatalog/Operator/ComparisonOperator.py
+2
-3
product/ZSQLCatalog/SQLExpression.py
product/ZSQLCatalog/SQLExpression.py
+0
-2
product/ZSQLCatalog/tests/testSQLCatalog.py
product/ZSQLCatalog/tests/testSQLCatalog.py
+3
-3
No files found.
product/ERP5/tests/testI18NSearch.py
View file @
ce77af41
...
...
@@ -83,7 +83,7 @@ class TestI18NSearch(ERP5TypeTestCase):
self
.
assertTrue
(
'ORDER BY
\
n
`full_text`.`SearchableText` ASC'
in
self
.
portal
.
portal_catalog
(
SearchableText
=
'Faure'
,
sort_on
=
((
'SearchableText'
,
'ascending'
),),
src__
=
1
))
# check sort on fulltext search score
self
.
assertTrue
(
'ORDER BY
\
n
SearchableText__score__ ASC'
in
self
.
portal
.
portal_catalog
(
SearchableText
=
'Faure'
,
sort_on
=
((
'SearchableText__score__'
,
'ascending'
),),
src__
=
1
))
self
.
assertTrue
(
'ORDER BY
\
n
full_text_
SearchableText__score__ ASC'
in
self
.
portal
.
portal_catalog
(
SearchableText
=
'Faure'
,
sort_on
=
((
'SearchableText__score__'
,
'ascending'
),),
src__
=
1
))
def
test_catalog_full_text_title
(
self
):
# check if 'é' == 'e' collation works
...
...
@@ -115,12 +115,12 @@ class TestI18NSearch(ERP5TypeTestCase):
}))
# check sort on fulltext search score
self
.
assert
False
(
'ORDER BY
\
n
title__score__'
in
self
.
portal
.
portal_catalog
(
**
{
self
.
assert
True
(
'ORDER BY
\
n
catalog_full_text_
title__score__'
in
self
.
portal
.
portal_catalog
(
**
{
'catalog_full_text.title'
:
'Faure'
,
'sort_on'
:((
'catalog_full_text.title__score__'
,
'ascending'
),),
'src__'
:
1
}))
self
.
assertTrue
(
'ORDER BY
\
n
title__score__'
in
self
.
portal
.
portal_catalog
(
**
{
self
.
assertTrue
(
'ORDER BY
\
n
catalog_full_text_
title__score__'
in
self
.
portal
.
portal_catalog
(
**
{
'catalog_full_text.title'
:
'Faure'
,
'sort_on'
:((
'title__score__'
,
'ascending'
),),
'src__'
:
1
...
...
@@ -156,7 +156,7 @@ class TestI18NSearch(ERP5TypeTestCase):
self
.
assertTrue
(
'ORDER BY
\
n
`catalog`.`title` ASC'
in
self
.
portal
.
portal_catalog
(
title
=
'Faure'
,
sort_on
=
((
'title'
,
'ascending'
),),
src__
=
1
))
# check sort on fulltext search score
self
.
assertTrue
(
'ORDER BY
\
n
title__score__'
in
self
.
portal
.
portal_catalog
(
title
=
'Faure'
,
sort_on
=
((
'title__score__'
,
'ascending'
),),
src__
=
1
))
self
.
assertTrue
(
'ORDER BY
\
n
catalog_full_text_
title__score__'
in
self
.
portal
.
portal_catalog
(
title
=
'Faure'
,
sort_on
=
((
'title__score__'
,
'ascending'
),),
src__
=
1
))
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
product/ZSQLCatalog/ColumnMap.py
View file @
ce77af41
...
...
@@ -453,6 +453,9 @@ class ColumnMap(object):
def
asSQLColumn
(
self
,
raw_column
,
group
=
DEFAULT_GROUP_ID
):
if
self
.
catalog_table_name
is
None
or
raw_column
in
self
.
column_ignore_set
or
\
'.'
in
raw_column
or
'*'
in
raw_column
:
if
raw_column
.
endswith
(
'__score__'
):
result
=
raw_column
.
replace
(
'.'
,
'_'
)
else
:
result
=
raw_column
else
:
if
raw_column
.
endswith
(
'__score__'
):
...
...
@@ -464,7 +467,10 @@ class ColumnMap(object):
if
group
is
DEFAULT_GROUP_ID
:
group
,
column
=
self
.
related_key_dict
.
get
(
column
,
(
group
,
raw_column
))
alias
=
self
.
table_alias_dict
[(
group
,
self
.
column_map
[(
group
,
column
)])]
result
=
'`%s`.`%s%s`'
%
(
alias
,
column
,
column_suffix
)
if
column_suffix
:
result
=
'%s_%s%s'
%
(
alias
,
column
,
column_suffix
)
else
:
result
=
'`%s`.`%s`'
%
(
alias
,
column
)
if
function
is
not
None
:
result
=
'%s(%s)'
%
(
function
,
result
)
return
result
...
...
product/ZSQLCatalog/Operator/ComparisonOperator.py
View file @
ce77af41
...
...
@@ -116,10 +116,9 @@ class MatchComparisonOperator(MonovaluedComparisonOperator):
}
select_dict
=
{}
if
not
only_group_columns
:
select_dict
[
'%s__score__'
%
column
.
replace
(
'`'
,
''
).
rsplit
(
'.'
,
1
)[
-
1
]]
=
match_string
# Support sort on the relevance by using (column)__score__ key.
select_dict
[
'%s__score__'
%
column
.
replace
(
'`'
,
''
).
replace
(
'.'
,
'_'
)]
=
match_string
order_by_dict
=
{
'
`%s__score__`'
%
'`.`'
.
join
([
x
.
strip
(
'`'
)
for
x
in
column
.
split
(
'.'
)]
):
match_string
,
'
%s__score__'
%
column
.
replace
(
'`'
,
''
).
replace
(
'.'
,
'_'
):
match_string
,
}
return
SQLExpression
(
self
,
...
...
product/ZSQLCatalog/SQLExpression.py
View file @
ce77af41
...
...
@@ -238,8 +238,6 @@ class SQLExpression(object):
append
=
result
.
append
order_by_dict
=
self
.
_getOrderByDict
()
for
(
column
,
direction
,
cast
)
in
self
.
getOrderByList
():
if
column
.
endswith
(
'__score__'
)
and
column
not
in
order_by_dict
:
continue
expression
=
conflictSafeGet
(
order_by_dict
,
column
,
str
(
column
))
expression
=
self
.
_reversed_select_dict
.
get
(
expression
,
expression
)
if
cast
not
in
(
None
,
''
):
...
...
product/ZSQLCatalog/tests/testSQLCatalog.py
View file @
ce77af41
...
...
@@ -735,20 +735,20 @@ class TestSQLCatalog(ERP5TypeTestCase):
order_by_expression
=
sql_expression
.
getOrderByExpression
()
self
.
assertNotEqual
(
order_by_expression
,
''
)
# ... and must sort by relevance
self
.
assertEqual
(
'fulltext__score__'
,
order_by_expression
)
self
.
assertEqual
(
'f
oo_f
ulltext__score__'
,
order_by_expression
)
# ordering on fulltext column with sort order specified must preserve
# sorting by relevance.
for
direction
in
(
'ASC'
,
'DESC'
):
sql_expression
=
self
.
asSQLExpression
({
'fulltext'
:
'foo'
,
'order_by_list'
:
[(
'fulltext__score__'
,
direction
),
]})
order_by_expression
=
sql_expression
.
getOrderByExpression
()
self
.
assertEqual
(
'fulltext__score__ %s'
%
direction
,
order_by_expression
)
self
.
assertEqual
(
'f
oo_f
ulltext__score__ %s'
%
direction
,
order_by_expression
)
# Providing a None cast should work too
for
direction
in
(
'ASC'
,
'DESC'
):
sql_expression
=
self
.
asSQLExpression
({
'fulltext'
:
'foo'
,
'order_by_list'
:
[(
'fulltext__score__'
,
direction
,
None
),
]})
order_by_expression
=
sql_expression
.
getOrderByExpression
()
self
.
assertEqual
(
'fulltext__score__ %s'
%
direction
,
order_by_expression
)
self
.
assertEqual
(
'f
oo_f
ulltext__score__ %s'
%
direction
,
order_by_expression
)
def
test_logicalOperators
(
self
):
self
.
catalog
(
ReferenceQuery
(
ReferenceQuery
(
operator
=
'='
,
default
=
'AN ORB'
),
...
...
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