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
85a8278d
Commit
85a8278d
authored
Apr 12, 2010
by
Tres Seaver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LP #143655: allow path index to be used for sorting.
parent
721e595d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
1 deletion
+43
-1
src/Products/PluginIndexes/PathIndex/PathIndex.py
src/Products/PluginIndexes/PathIndex/PathIndex.py
+14
-1
src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py
src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py
+29
-0
No files found.
src/Products/PluginIndexes/PathIndex/PathIndex.py
View file @
85a8278d
...
...
@@ -31,6 +31,7 @@ from zope.interface import implements
from
Products.PluginIndexes.common
import
safe_callable
from
Products.PluginIndexes.common.util
import
parseIndexRequest
from
Products.PluginIndexes.interfaces
import
IPathIndex
from
Products.PluginIndexes.interfaces
import
ISortIndex
from
Products.PluginIndexes.interfaces
import
IUniqueValueIndex
LOG
=
getLogger
(
'Zope.PathIndex'
)
...
...
@@ -51,7 +52,7 @@ class PathIndex(Persistent, SimpleItem):
- the value is a mapping 'level of the path component' to
'all docids with this path component on this level'
"""
implements
(
IPathIndex
,
IUniqueValueIndex
)
implements
(
IPathIndex
,
IUniqueValueIndex
,
ISortIndex
)
meta_type
=
"PathIndex"
query_options
=
(
'query'
,
'level'
,
'operator'
)
...
...
@@ -213,6 +214,18 @@ class PathIndex(Persistent, SimpleItem):
for
key
in
self
.
_index
.
keys
():
yield
key
# ISortIndex implementation
def
keyForDocument
(
self
,
documentId
):
""" See ISortIndex.
"""
return
self
.
_unindex
.
get
(
documentId
)
def
documentToKeyMap
(
self
):
""" See ISortIndex.
"""
return
self
.
_unindex
# Helper methods
def
_insertEntry
(
self
,
comp
,
id
,
level
):
...
...
src/Products/PluginIndexes/PathIndex/tests/testPathIndex.py
View file @
85a8278d
...
...
@@ -83,6 +83,16 @@ class PathIndexTests(unittest.TestCase):
from
zope.interface.verify
import
verifyObject
verifyObject
(
IUniqueValueIndex
,
self
.
_makeOne
())
def
test_class_conforms_to_ISortIndex
(
self
):
from
Products.PluginIndexes.interfaces
import
ISortIndex
from
zope.interface.verify
import
verifyClass
verifyClass
(
ISortIndex
,
self
.
_getTargetClass
())
def
test_instance_conforms_to_ISortIndex
(
self
):
from
Products.PluginIndexes.interfaces
import
ISortIndex
from
zope.interface.verify
import
verifyObject
verifyObject
(
ISortIndex
,
self
.
_makeOne
())
def
test_class_conforms_to_IPathIndex
(
self
):
from
Products.PluginIndexes.interfaces
import
IPathIndex
from
zope.interface.verify
import
verifyClass
...
...
@@ -427,6 +437,25 @@ class PathIndexTests(unittest.TestCase):
self
.
assertEqual
(
results
[
'cc'
],
len
([
x
for
x
in
DUMMIES
.
values
()
if
'cc'
in
x
.
path
]))
def
test_keyForDocument_miss
(
self
):
index
=
self
.
_makeOne
()
self
.
assertEqual
(
index
.
keyForDocument
(
1
),
None
)
def
test_keyForDocument_hit
(
self
):
index
=
self
.
_makeOne
()
_populateIndex
(
index
)
self
.
assertEqual
(
index
.
keyForDocument
(
1
),
DUMMIES
[
1
].
path
)
def
test_documentToKeyMap_empty
(
self
):
index
=
self
.
_makeOne
()
self
.
assertEqual
(
dict
(
index
.
documentToKeyMap
()),
{})
def
test_documentToKeyMap_filled
(
self
):
index
=
self
.
_makeOne
()
_populateIndex
(
index
)
self
.
assertEqual
(
dict
(
index
.
documentToKeyMap
()),
dict
([(
k
,
v
.
path
)
for
k
,
v
in
DUMMIES
.
items
()]))
def
test__search_empty_index_string_query
(
self
):
index
=
self
.
_makeOne
()
self
.
assertEqual
(
list
(
index
.
_search
(
'/xxx'
)),
[])
...
...
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