Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
33715661
Commit
33715661
authored
Jul 24, 2010
by
Hanno Schlichting
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change the determine_value_indexes function to actually do what it promises
parent
966de0cd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
19 deletions
+16
-19
src/Products/ZCatalog/CatalogReport.py
src/Products/ZCatalog/CatalogReport.py
+7
-6
src/Products/ZCatalog/tests/testCatalog.py
src/Products/ZCatalog/tests/testCatalog.py
+9
-13
No files found.
src/Products/ZCatalog/CatalogReport.py
View file @
33715661
...
...
@@ -20,25 +20,26 @@ from Products.PluginIndexes.interfaces import IUniqueValueIndex
writelock
=
allocate_lock
()
reports
=
{}
MAX_DISTINCT_VALUES
=
2
0
MAX_DISTINCT_VALUES
=
1
0
LOG
=
logging
.
getLogger
(
'CatalogReport'
)
def
determine_value_indexes
(
catalog
):
# This function determines all indexes whose values should be respected
# in the prioritymap key. A index type needs to be registered in the
# VALUETYPES module global and the number of unique values needs to be
# in the report key. The number of unique values for the index needs to be
# lower than the MAX_DISTINCT_VALUES watermark.
valueindexes
=
[]
for
name
,
index
in
catalog
.
indexes
.
items
():
if
IUniqueValueIndex
.
providedBy
(
index
):
if
len
(
index
)
<
MAX_DISTINCT_VALUES
:
# Checking for len of an index should be fast. It's a stored
# BTrees.Length value and requires no calculation.
values
=
index
.
uniqueValues
()
if
values
and
len
(
values
)
<
MAX_DISTINCT_VALUES
:
# Only consider indexes which actually return a number
# greater than zero
valueindexes
.
append
(
name
)
return
frozenset
(
valueindexes
)
def
make_key
(
catalog
,
request
):
valueindexes
=
determine_value_indexes
(
catalog
)
...
...
src/Products/ZCatalog/tests/testCatalog.py
View file @
33715661
...
...
@@ -870,11 +870,10 @@ class TestCatalogReport(unittest.TestCase):
self
.
zcat
.
addIndex
(
'title'
,
'TextIndex'
)
self
.
zcat
.
_catalog
.
vocabulary
=
vocabulary
for
i
in
range
(
10
):
for
i
in
range
(
9
):
obj
=
zdummy
(
i
)
obj
.
big
=
i
>
5
self
.
zcat
.
catalog_object
(
obj
,
str
(
i
))
def
test_ReportLength
(
self
):
""" tests the report aggregation """
...
...
@@ -912,7 +911,7 @@ class TestCatalogReport(unittest.TestCase):
def
test_ReportKey
(
self
):
""" tests the query keys for uniqueness """
# query key 1
key
=
(
'sort_on'
,
(
'big'
,
'True'
))
self
.
zcat
.
manage_resetCatalogReport
()
...
...
@@ -933,21 +932,18 @@ class TestCatalogReport(unittest.TestCase):
self
.
assertEqual
(
r
[
'query'
],
key
)
self
.
assertEqual
(
r
[
'counter'
],
1
)
# query key 3
key
=
(
'sort_on'
,
(
'num'
,
'[3, 4, 5]'
))
self
.
zcat
.
manage_resetCatalogReport
()
self
.
zcat
.
searchResults
(
num
=
[
5
,
4
,
3
],
sort_on
=
'num'
)
self
.
zcat
.
searchResults
(
num
=
(
3
,
4
,
5
),
sort_on
=
'num'
)
self
.
zcat
.
searchResults
(
num
=
[
5
,
4
,
3
],
sort_on
=
'num'
)
self
.
zcat
.
searchResults
(
num
=
(
3
,
4
,
5
),
sort_on
=
'num'
)
r
=
self
.
zcat
.
getCatalogReport
()[
0
]
#print 'hits: %(counter)s, mean duration: %(duration)3.2fms, key: %(query)s' % r
self
.
assertEqual
(
r
[
'query'
],
key
)
self
.
assertEqual
(
r
[
'counter'
],
2
)
self
.
assertEqual
(
r
[
'query'
],
key
)
self
.
assertEqual
(
r
[
'counter'
],
2
)
def
test_suite
():
suite
=
unittest
.
TestSuite
()
...
...
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