[Zope-CVS] CVS: Products/PathIndexNG - LICENSE:1.1
PathIndexNG.py:1.1 README:1.1 __init__.py:1.1 version.txt:1.1
Andreas Jung
andreas at andreas-jung.com
Sat Jan 24 11:48:51 EST 2004
Update of /cvs-repository/Products/PathIndexNG
In directory cvs.zope.org:/tmp/cvs-serv2882
Added Files:
LICENSE PathIndexNG.py README __init__.py version.txt
Log Message:
added
=== Added File Products/PathIndexNG/LICENSE ===
PathIndexNG is written by Andreas Jung and published
under the Zope Public License V2.
=== Added File Products/PathIndexNG/PathIndexNG.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
__version__ = '$Id: PathIndexNG.py,v 1.1 2004/01/24 16:48:50 andreasjung Exp $'
from types import StringType, ListType, TupleType
import ZODB
from Globals import Persistent, DTMLFile
from OFS.SimpleItem import SimpleItem
from BTrees.IOBTree import IOBTree
from BTrees.OOBTree import OOBTree
from BTrees.IIBTree import IITreeSet, intersection, union
from BTrees.Length import Length
from zLOG import LOG, ERROR
from Products.PluginIndexes import PluggableIndex
from Products.PluginIndexes.common.util import parseIndexRequest
from Products.PluginIndexes.common import safe_callable
_marker = []
class PathIndexNG(Persistent, SimpleItem):
""" An efficient ZCatalog index to store path components
of persistent objects.
"""
__implements__ = (PluggableIndex.UniqueValueIndex,)
meta_type="PathIndexNG"
manage_options= (
{'label': 'Settings',
'action': 'manage_main',
'help': ('PathIndexNG', 'PathIndexNG_Settings.stx')},
)
query_options = ('query', 'operator')
use_operator = 'or'
def __init__(self,id, caller=None):
self.id = id
self.clear()
def clear(self):
self._length = Length(0)
self._index = OOBTree() # path -> Set(docids)
self._unindex = IOBTree() # docid -> path
def index_object(self, docid, obj ,threshold=100):
""" hook for (Z)Catalog """
f = getattr(obj, self.id, None)
if f is not None:
if safe_callable(f):
try:
path = f()
except AttributeError:
return 0
else:
path = f
if not isinstance(path, (StringType, TupleType)):
raise TypeError('path value must be string or tuple of strings')
else:
try:
path = obj.getPhysicalPath()
except AttributeError:
return 0
if isinstance(path, (ListType, TupleType)):
path = '/'+ '/'.join(path[1:])
if not self._unindex.has_key(docid):
self._length.change(1)
if not self._index.has_key(path):
self._index[path] = IITreeSet()
self._index[path].insert(docid)
self._unindex[docid] = path
return 1
def unindex_object(self, docid):
""" hook for (Z)Catalog """
if not self._unindex.has_key(docid):
LOG(self.__class__.__name__, ERROR,
'Attempt to unindex nonexistent document'
' with id %s' % docid)
return
try:
path = self._unindex[docid]
except KeyError:
# ignore broken references silently
return
try:
self._index[path].remove(docid)
except KeyError:
return
if len(self._index[path]) == 0:
del self._index[path]
del self._unindex[docid]
self._length.change(-1)
def numObjects(self):
""" return the number of indexed objects"""
return self._length()
def hasUniqueValuesFor(self, name):
"""has unique values for column name"""
return name == self.id
def uniqueValues(self, name=None, withLength=0):
""" needed to be consistent with the interface """
return self._index.keys()
def getIndexSourceNames(self):
""" return names of indexed attributes """
return ('getPhysicalPath', )
def getEntryForObject(self, docid, default=None):
""" Takes a document ID and returns all the information
we have on that specific object.
"""
try:
return self._unindex[docid]
except:
return default
index_html = DTMLFile('dtml/index', globals())
manage_workspace = DTMLFile('dtml/managePathIndexNG', globals())
manage_addPathIndexNGForm = DTMLFile('dtml/addPathNGIndex', globals())
def manage_addPathIndexNG(self, id, REQUEST=None, RESPONSE=None, URL3=None):
"""Add a path index"""
return self.manage_addIndex(id, 'PathIndexNG', extra=None, \
REQUEST=REQUEST, RESPONSE=RESPONSE, URL1=URL3)
=== Added File Products/PathIndexNG/README ===
PathIndexNG -- an efficient index for path informations
PathIndexNG is a replacement for the PathIndex. The old PathIndex is slow and
implements some functionality that is need in most use-cases. PathIndexNG
neither supports 'or' nor 'and' operations - you query the index for one
specific path at a time. Path queries will always be matched as prefix (no
'level' parameter).
Written by Andreas Jung (andreas at andreas-jung.com)
=== Added File Products/PathIndexNG/__init__.py ===
###########################################################################
#
# PathIndexNG The next generation TextIndex for Zope
#
# This software is governed by a license. See
# LICENSE.txt for the terms of this license.
#
###########################################################################
import os, sys
def initialize(context):
from Products.PathIndexNG import PathIndexNG
manage_addPathIndexNGForm = PathIndexNG.manage_addPathIndexNGForm
manage_addPathIndexNG = PathIndexNG.manage_addPathIndexNG
context.registerClass(
PathIndexNG.PathIndexNG,
permission='Add Pluggable Index',
constructors=(manage_addPathIndexNGForm,
manage_addPathIndexNG),
icon='www/index.gif',
visibility=None
)
context.registerHelp()
context.registerHelpTitle("Zope Help")
=== Added File Products/PathIndexNG/version.txt ===
unreleased
More information about the Zope-CVS
mailing list