[Zope3-checkins] CVS: Zope3/src/zope/app/index/text - __init__.py:1.2 configure.zcml:1.2 index.py:1.2 processors.py:1.2 queries.py:1.2

Jim Fulton jim@zope.com
Wed, 25 Dec 2002 09:13:56 -0500


Update of /cvs-repository/Zope3/src/zope/app/index/text
In directory cvs.zope.org:/tmp/cvs-serv15352/src/zope/app/index/text

Added Files:
	__init__.py configure.zcml index.py processors.py queries.py 
Log Message:
Grand renaming:

- Renamed most files (especially python modules) to lower case.

- Moved views and interfaces into separate hierarchies within each
  project, where each top-level directory under the zope package
  is a separate project.

- Moved everything to src from lib/python.

  lib/python will eventually go away. I need access to the cvs
  repository to make this happen, however.

There are probably some bits that are broken. All tests pass
and zope runs, but I haven't tried everything. There are a number
of cleanups I'll work on tomorrow.



=== Zope3/src/zope/app/index/text/__init__.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/index/text/__init__.py	Wed Dec 25 09:12:55 2002
@@ -0,0 +1,2 @@
+#
+# This file is necessary to make this directory a package.


=== Zope3/src/zope/app/index/text/configure.zcml 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/index/text/configure.zcml	Wed Dec 25 09:12:55 2002
@@ -0,0 +1,18 @@
+<zopeConfigure xmlns="http://namespaces.zope.org/zope">
+
+  <content class="zope.app.index.text.index.TextIndex">
+
+    <require
+      permission="zope.ManageServices"
+      interface="zope.app.interfaces.index.text.interfaces.IUITextIndex"
+      attributes="query"
+      />
+
+    <factory
+      id="zope.app.index.text.factory"
+      permission="zope.ManageServices"
+      />
+
+    </content>
+
+</zopeConfigure>


=== Zope3/src/zope/app/index/text/index.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/index/text/index.py	Wed Dec 25 09:12:55 2002
@@ -0,0 +1,101 @@
+##############################################################################
+#
+# 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.
+
+In addition, this implements TTW subscription management.
+
+$Id$
+"""
+
+from zope.component import getService, queryAdapter
+from zope.proxy.context import ContextMethod
+from zope.interfaces.event import ISubscriber
+from zope.exceptions import NotFoundError
+from zope.textindex.textindexwrapper import TextIndexWrapper
+
+from zope.app.interfaces.dublincore import IZopeDublinCore
+from zope.app.interfaces.services.hub import \
+     IRegistrationHubEvent, \
+     IObjectRegisteredHubEvent, \
+     IObjectUnregisteredHubEvent, \
+     IObjectModifiedHubEvent
+from zope.app.traversing import locationAsUnicode
+from zope.app.interfaces.index.text.interfaces import ISearchableText, IUITextIndex
+
+class TextIndex(TextIndexWrapper):
+
+    __implements__ = (TextIndexWrapper.__implements__,
+                      ISubscriber, IUITextIndex)
+
+    def notify(wrapped_self, event):
+        """An event occurred.  Index or unindex the object in response."""
+        if (IObjectRegisteredHubEvent.isImplementedBy(event) or
+            IObjectModifiedHubEvent.isImplementedBy(event)):
+            texts = wrapped_self._getTexts(event.object)
+            if texts is not None:
+                wrapped_self.index_doc(event.hubid, texts)
+        elif IObjectUnregisteredHubEvent.isImplementedBy(event):
+            try:
+                wrapped_self.unindex_doc(event.hubid)
+            except KeyError:
+                pass
+    notify = ContextMethod(notify)
+
+    def _getTexts(wrapped_self, object):
+        adapted = queryAdapter(object, ISearchableText, context=wrapped_self)
+        if adapted is None:
+            return None
+        return adapted.getSearchableText()
+    _getTexts = ContextMethod(_getTexts)
+
+    currentlySubscribed = False # Default subscription state
+
+    def subscribe(wrapped_self, channel=None, update=True):
+        if wrapped_self.currentlySubscribed:
+            raise RuntimeError, "already subscribed; please unsubscribe first"
+        channel = wrapped_self._getChannel(channel)
+        channel.subscribe(wrapped_self, IRegistrationHubEvent)
+        channel.subscribe(wrapped_self, IObjectModifiedHubEvent)
+        if update:
+            wrapped_self._update(channel.iterObjectRegistrations())
+        wrapped_self.currentlySubscribed = True
+    subscribe = ContextMethod(subscribe)
+
+    def unsubscribe(wrapped_self, channel=None):
+        if not wrapped_self.currentlySubscribed:
+            raise RuntimeError, "not subscribed; please subscribe first"
+        channel = wrapped_self._getChannel(channel)
+        channel.unsubscribe(wrapped_self, IObjectModifiedHubEvent)
+        channel.unsubscribe(wrapped_self, IRegistrationHubEvent)
+        wrapped_self.currentlySubscribed = False
+    unsubscribe = ContextMethod(unsubscribe)
+
+    def isSubscribed(self):
+        return self.currentlySubscribed
+
+    def _getChannel(wrapped_self, channel):
+        if channel is None:
+            channel = getService(wrapped_self, "ObjectHub")
+        return channel
+    _getChannel = ContextMethod(_getChannel)
+
+    def _update(wrapped_self, registrations):
+        for location, hubid, wrapped_object in registrations:
+            texts = wrapped_self._getTexts(wrapped_object)
+            if texts is not None:
+                wrapped_self.index_doc(hubid, texts)
+    _update = ContextMethod(_update)


=== Zope3/src/zope/app/index/text/processors.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/index/text/processors.py	Wed Dec 25 09:12:55 2002
@@ -0,0 +1,53 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""A query processor to the TextIndex that supports batching and ranking.
+
+$Id$
+"""
+
+from zope.component import getAdapter
+
+from zope.textindex.textindexinterfaces import IQuerying
+from zope.app.interfaces.index.interfaces import \
+    IBatchedResult, IRankedHubIdList, IBatchedTextIndexQuery
+from zope.app.interfaces.services.query import \
+    IQueryProcessor
+from zope.app.index.text.queries import BatchedTextIndexQuery
+from zope.app.index.queries import BatchedRankedResult
+
+class IBatchedRankedProcessor(IQueryProcessor):
+    # XXX until named adapters are there
+    pass
+
+class BatchedRankedProcessor:
+
+    __implements__ = IBatchedRankedProcessor
+    __used_for__ = IQuerying
+
+    input_interface = IBatchedTextIndexQuery
+    output_interface = (IRankedHubIdList, IBatchedResult)
+
+    def __init__(self, textindex):
+        self.__textindex = textindex
+
+    def __call__(self, query):
+        query = getAdapter(query, IBatchedTextIndexQuery)
+        resultlist, totalresults = self.__textindex.query(query.textIndexQuery, \
+                    query.startPosition, query.batchSize)
+
+        # XXX do we need some wrapping here?
+        result = BatchedRankedResult(resultlist, query.startPosition, \
+                    query.batchSize, totalresults)
+
+        return result


=== Zope3/src/zope/app/index/text/queries.py 1.1 => 1.2 ===
--- /dev/null	Wed Dec 25 09:13:56 2002
+++ Zope3/src/zope/app/index/text/queries.py	Wed Dec 25 09:12:55 2002
@@ -0,0 +1,30 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+
+from zope.app.interfaces.index.interfaces import \
+    IBatchedTextIndexQuery, IBatchedResult, IRankedHubIdList
+
+class BatchedTextIndexQuery:
+
+    __implements__ = IBatchedTextIndexQuery
+
+    def __init__(self, query, startposition, batchsize):
+
+        self.textIndexQuery = query
+        self.startPosition = startposition
+        self.batchSize = batchsize