[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/Indexes - ISearchableText.py:1.1 TextIndex.py:1.1
Guido van Rossum
guido@python.org
Wed, 4 Dec 2002 05:43:29 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/App/Indexes
In directory cvs.zope.org:/tmp/cvs-serv21339
Added Files:
ISearchableText.py TextIndex.py
Log Message:
Subscribable text index.
=== Added File Zope3/lib/python/Zope/App/Indexes/ISearchableText.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""Interface that text-indexable objects should implement.
$Id: ISearchableText.py,v 1.1 2002/12/04 10:43:29 gvanrossum Exp $
"""
from Interface import Interface
class ISearchableText(Interface):
def getSearchableText():
"""Return a sequence of unicode strings to be indexed.
Each unicode string in the returned sequence will be run
through the splitter pipeline; the combined stream of words
coming out of the pipeline will be indexed.
"""
=== Added File Zope3/lib/python/Zope/App/Indexes/TextIndex.py ===
##############################################################################
#
# Copyright (c) 2002 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.
#
##############################################################################
"""This is a text index which can be subscribed to an event service.
Events related to object creation and deletion are translated into
index_doc() and unindex_doc() calls.
$Id: TextIndex.py,v 1.1 2002/12/04 10:43:29 gvanrossum Exp $
"""
from Zope.Event.ISubscriber import ISubscriber
from Zope.App.OFS.Services.ObjectHub.IHubEvent import \
IObjectRegisteredHubEvent, \
IObjectUnregisteredHubEvent, \
IObjectModifiedHubEvent
from Zope.App.Indexes.ISearchableText import ISearchableText
from Zope.ComponentArchitecture import queryAdapter
from Zope.ContextWrapper import ContextMethod
from Zope.TextIndex.TextIndexWrapper import TextIndexWrapper
class TextIndex(TextIndexWrapper):
__implements__ = TextIndexWrapper.__implements__ + (ISubscriber,)
def notify(wrapped_self, event):
"""An event occurred. Index or unindex the object in response."""
if (IObjectRegisteredHubEvent.isImplementedBy(event) or
IObjectModifiedHubEvent.isImplementedBy(event)):
adapted = queryAdapter(event.object,
ISearchableText,
context=wrapped_self)
if adapted is None:
return
texts = adapted.getSearchableText()
wrapped_self.index_doc(event.hubid, texts)
elif IObjectUnregisteredHubEvent.isImplementedBy(event):
try:
wrapped_self.unindex_doc(event.hubid)
except KeyError:
pass
notify = ContextMethod(notify)