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
bac86db1
Commit
bac86db1
authored
Sep 08, 1997
by
Jim Fulton
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*** empty log message ***
parent
c1a6ff90
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
146 additions
and
0 deletions
+146
-0
lib/python/SearchIndex/Index.py
lib/python/SearchIndex/Index.py
+146
-0
No files found.
lib/python/SearchIndex/Index.py
0 → 100644
View file @
bac86db1
##############################################################################
#
# Copyright
#
# Copyright 1996 Digital Creations, L.C., 910 Princess Anne
# Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All
# rights reserved.
#
##############################################################################
__doc__
=
'''Simple column indexes
$Id: Index.py,v 1.1 1997/09/08 18:52:04 jim Exp $'''
__version__
=
'$Revision: 1.1 $'
[
11
:
-
2
]
from
oiTree
import
BTree
from
intSet
import
intSet
import
operator
ListType
=
type
([])
class
Index
:
"""Index object interface"""
def
_init
(
self
,
data
,
schema
,
id
):
"""Create an index
The arguments are:
'data' -- a mapping from integer object ids to objects or records,
'schema' -- a mapping from item name to index into data records.
If 'data' is a mapping to objects, then schema should ne 'None'.
'id' -- the name of the item attribute to index. This is either
an attribute name or a record key.
"""
self
.
_data
=
data
self
.
_schema
=
schema
self
.
id
=
id
self
.
_index
=
BTree
()
self
.
_reindex
()
def
clear
(
self
):
self
.
_init
()
def
_reindex
(
self
,
start
=
0
):
"""Recompute index data for data with ids >= start."""
index
=
self
.
_index
if
not
start
:
index
.
clear
()
id
=
self
.
id
if
self
.
_schema
is
None
:
f
=
getattr
else
:
f
=
operator
.
__getitem__
id
=
self
.
_schema
[
id
]
for
i
,
row
in
self
.
_data
.
items
(
start
):
k
=
f
(
row
,
id
)
try
:
set
=
index
[
k
]
except
KeyError
:
set
=
intSet
()
index
[
k
]
=
set
set
.
insert
(
i
)
def
index_item
(
self
,
i
):
"""Recompute index data for data with ids >= start."""
index
=
self
.
_index
id
=
self
.
id
if
self
.
_schema
is
None
:
f
=
getattr
else
:
f
=
operator
.
__getitem__
id
=
self
.
_schema
[
id
]
row
=
self
.
_data
[
i
]
k
=
f
(
row
,
id
)
try
:
set
=
index
[
k
]
except
KeyError
:
set
=
intSet
()
index
[
k
]
=
set
set
.
insert
(
i
)
def
unindex_item
(
self
,
i
):
"""Recompute index data for data with ids >= start."""
index
=
self
.
_index
id
=
self
.
id
if
self
.
_schema
is
None
:
f
=
getattr
else
:
f
=
operator
.
__getitem__
id
=
self
.
_schema
[
id
]
row
=
self
.
_data
[
i
]
k
=
f
(
row
,
id
)
try
:
set
=
index
[
k
]
set
.
remove
(
k
)
except
KeyError
:
pass
def
_apply_index
(
self
,
request
):
"""Apply the index to query parameters given in the argument, request
The argument should be a mapping object.
If the request does not contain the needed parameters, then None is
returned.
Otherwise two objects are returned. The first object is a
ResultSet containing the record numbers of the matching
records. The second object is a tuple containing the names of
all data fields used.
"""
id
=
self
.
id
try
:
keys
=
request
[
id
]
except
:
return
None
if
type
(
keys
)
is
not
ListType
:
keys
=
[
keys
]
index
=
self
.
_index
r
=
None
for
key
in
keys
:
try
:
set
=
index
[
key
]
if
r
is
None
:
r
=
set
else
:
r
=
r
.
union
(
set
)
except
KeyError
:
pass
if
r
is
not
None
:
return
r
,
(
id
,)
##############################################################################
#
# $Log: Index.py,v $
# Revision 1.1 1997/09/08 18:52:04 jim
# *** empty log message ***
#
#
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