[Zope3-checkins] SVN: Zope3/branches/jim-index/src/zope/app/index/ Checking in work in progress to flush removed and moved files.

Jim Fulton jim at zope.com
Sat Jun 12 10:06:58 EDT 2004


Log message for revision 25391:
Checking in work in progress to flush removed and moved files.


-=-
Deleted: Zope3/branches/jim-index/src/zope/app/index/adapters.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/adapters.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/adapters.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -1,45 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 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.
-#
-##############################################################################
-"""Index-relevant adapters.
-
-$Id$
-"""
-from zope.index.interfaces import IQuerying, IKeywordQuerying
-from BTrees.IIBTree import IISet
-
-class SimpleQuery:
-    "Call an IQuerying search, return only the hubids"
-    __used_for__ = IQuerying
-
-    def __init__(self, index):
-        self._index = index
-
-    def query(self, term, start=0, count=None):
-        reslist, count = self._index.query(term, start, count)
-        # Not really optimal, this. May be a better way?
-        reslist = IISet([ x[0] for x in reslist ])
-        return reslist
-
-class SimpleKeywordQuery:
-    "Call an IKeywordQuerying search, return only the hubids"
-    __used_for__ = IKeywordQuerying
-
-    def __init__(self, index):
-        self._index = index
-
-    def query(self, term, start=0, count=None):
-        reslist = self._index.search(term, operator='and')
-        return reslist
-
-

Modified: Zope3/branches/jim-index/src/zope/app/index/browser/field/control.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/browser/field/control.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/browser/field/control.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -17,7 +17,6 @@
 """
 from zope.app.introspector import interfaceToName
 from zope.app.dublincore.interfaces import IZopeDublinCore
-from zope.app.index.interfaces.text import IQueryView
 from zope.app.servicenames import HubIds
 from zope.app.traversing.api import canonicalPath
 from zope.component import getService, queryAdapter
@@ -27,8 +26,6 @@
 
 class ControlView(BrowserView):
 
-    implements(IQueryView)
-
     def __init__(self, context, request):
         super(ControlView, self).__init__(context, request)
         self.hub = getService(HubIds)

Modified: Zope3/branches/jim-index/src/zope/app/index/browser/text/control.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/browser/text/control.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/browser/text/control.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -23,11 +23,8 @@
 
 from zope.app.traversing.api import canonicalPath
 from zope.app.dublincore.interfaces import IZopeDublinCore
-from zope.app.index.interfaces.text import IQueryView
 
 class ControlView(BrowserView):
-    implements(IQueryView)
-
     default_start = 0 # Don't change -- always start at first batch
     default_count = 2 # Default batch size -- tune as you please
 

Modified: Zope3/branches/jim-index/src/zope/app/index/configure.zcml
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/configure.zcml	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/configure.zcml	2004-06-12 14:06:58 UTC (rev 25391)
@@ -4,20 +4,5 @@
   <include package=".field" />
   <include package=".keyword" />
 
-<adapter
-  factory=".adapters.SimpleQuery"
-  provides="zope.index.interfaces.ISimpleQuery"
-  for="zope.index.interfaces.IQuerying"
-  permission="zope.Public"
-/>
-
-<adapter
-  factory=".adapters.SimpleKeywordQuery"
-  provides="zope.index.interfaces.ISimpleQuery"
-  for="zope.index.interfaces.IKeywordQuerying"
-  permission="zope.Public"
-/>
-
-
 </configure>
 

Modified: Zope3/branches/jim-index/src/zope/app/index/field/configure.zcml
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/field/configure.zcml	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/field/configure.zcml	2004-06-12 14:06:58 UTC (rev 25391)
@@ -7,10 +7,6 @@
       interface="zope.app.index.interfaces.field.IUIFieldIndex"
       />
 
-  <implements
-      interface="zope.app.index.interfaces.IQueryProcessable"
-      />
-
 </content>
 <content class="zope.app.index.field.index.FieldCatalogIndex">
   <require

Modified: Zope3/branches/jim-index/src/zope/app/index/field/index.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/field/index.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/field/index.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -20,22 +20,14 @@
 
 $Id$
 """
-from zope.component import getService
-from zope.app.servicenames import HubIds
-from zope.index.field.index import FieldIndex as FieldIndexWrapper
-from zope.interface import implements
-from zope.app.container.contained import Contained
-from zope.app.hub.interfaces import IObjectModifiedHubEvent
-from zope.app.hub.interfaces import IRegistrationHubEvent
-from zope.app.index.interfaces.field import IUIFieldIndex, IUIFieldCatalogIndex
-from zope.app.catalog.interfaces.index import ICatalogIndex
-from zope.app.index.ifaceindex import InterfaceIndexingSubscriber
+import zope.app.index.ifaceindex
+import zope.interface
 
-class FieldCatalogIndex(InterfaceIndexingSubscriber, FieldIndexWrapper,
-                        Contained):
-    implements(ICatalogIndex, IUIFieldCatalogIndex)
+class IFieldIndex(zope.app.index.ifaceindex.IInterfaceIndexer):
+    """Interface-based field index
+       """
 
-class FieldIndex(FieldCatalogIndex):
+class FieldIndex(InterfaceIndexing, BaseFieldIndex, Contained):
+    zope.interface.implements(IFieldIndex)
 
-    implements(IUIFieldIndex)
 

Modified: Zope3/branches/jim-index/src/zope/app/index/ifaceindex.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/ifaceindex.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/ifaceindex.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -14,10 +14,53 @@
 """
 $Id$
 """
-from zope.interface import implements
-from zope.app.index.interfaces import IInterfaceIndexer
 
-class InterfaceIndexingSubscriber(object):
+#############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Index Interfaces
+
+$Id$
+"""
+import zope.interface
+from zope.schema import BytesLine, Choice, Boolean
+from zope.app.i18n import ZopeMessageIDFactory as _
+
+class IInterfaceIndexer(zope.interface.Interface):
+    """I index objects by first adapting them to an interface, then
+       retrieving a field on the adapted object.
+    """
+
+    interface = Choice(
+        title=_(u"Interface"),
+        description=_(u"Objects will be adapted to this interface"),
+        vocabulary=_("Interfaces"),
+        required=False,
+        )
+
+    field_name = BytesLine(
+        title=_(u"Field Name"),
+        description=_(u"Name of the field to index"),
+        )
+
+    field_callable = Boolean(
+        title=_(u"Field Callable"),
+        description=_(u"If true, then the field should be called to get the "
+                      u"value to be indexed"),
+        )
+        
+    
+class InterfaceIndex(object):
     """Index interface-defined fields
 
        Mixin for indexing a particular field name, after first adapting the
@@ -39,7 +82,7 @@
          ...     def __init__(self, v):
          ...         self.x = v
 
-         >>> class Index(InterfaceIndexingSubscriber, BaseIndex):
+         >>> class Index(InterfaceIndex, BaseIndex):
          ...     pass
 
          >>> index = Index('x')
@@ -83,7 +126,7 @@
        When you define an index class, you can define a default
        interface and/or a default interface:
 
-         >>> class Index(InterfaceIndexingSubscriber, BaseIndex):
+         >>> class Index(InterfaceIndex, BaseIndex):
          ...     default_interface = I
          ...     default_field_name = 'y'
         
@@ -94,33 +137,32 @@
          [(11, 9), (22, 4)]
 
        """
-    implements(IInterfaceIndexer)
+
+    zope.interface.implements(IInterfaceIndexer)
+    
     default_field_name = None
     default_interface = None
 
     def __init__(self, field_name=None, interface=None):
-        super(InterfaceIndexingSubscriber, self).__init__()
+        super(InterfaceIndex, self).__init__()
         if field_name is None and self.default_field_name is None:
             raise ValueError, "Must pass a field_name"
         if field_name is None:
-            self._field_name = self.default_field_name
+            self.field_name = self.default_field_name
         else:
-            self._field_name = field_name
+            self.field_name = field_name
         if interface is None:
-            self._interface = self.default_interface
+            self.interface = self.default_interface
         else:
-            self._interface = interface
+            self.interface = interface
 
-    field_name = property(lambda self: self._field_name)
-    interface = property(lambda self: self._interface)
-
-    def _getValue(self, object):
-        if self._interface is not None:
-            object = self._interface(object, None)
+    def index_doc(self, docid, object):
+        if self.interface is not None:
+            object = self.interface(object, None)
             if object is None:
                 return None
 
-        value = getattr(object, self._field_name, None)
+        value = getattr(object, self.field_name, None)
         if value is None:
             return None
 
@@ -130,8 +172,4 @@
             except:
                 return None
 
-        return value
-        
-    def index_doc(self, docid, object):
-        value = self._getValue(object)
-        return super(InterfaceIndexingSubscriber, self).index_doc(docid, value)
+        return super(InterfaceIndex, self).index_doc(docid, value)

Modified: Zope3/branches/jim-index/src/zope/app/index/keyword/configure.zcml
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/keyword/configure.zcml	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/keyword/configure.zcml	2004-06-12 14:06:58 UTC (rev 25391)
@@ -11,18 +11,6 @@
       set_schema="zope.app.index.interfaces.keyword.IUIKeywordCatalogIndex"
       />
 
-  <implements
-      interface="zope.app.index.interfaces.IQueryProcessable"
-      />
-
 </content>
 
-<!--
-<adapter
-    factory="zope.app.index.text.processors.BatchedRankedProcessor"
-    provides="zope.app.index.interfaces.IQueryProcessor"
-    for="zope.index.interfaces.IQuerying"
-    />
--->
-
 </configure>

Modified: Zope3/branches/jim-index/src/zope/app/index/keyword/index.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/keyword/index.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/keyword/index.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -22,6 +22,6 @@
 from zope.app.catalog.interfaces.index import ICatalogIndex
 from zope.app.index import InterfaceIndexingSubscriber
 
-class KeywordCatalogIndex(InterfaceIndexingSubscriber, KeywordIndex):
+class KeywordCatalogIndex(InterfaceIndexing, KeywordIndex):
     implements(ICatalogIndex, IUIKeywordCatalogIndex)
 

Deleted: Zope3/branches/jim-index/src/zope/app/index/processors.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/processors.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/processors.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -1,85 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Generic query processors for use with multiple indexes..
-
-$Id$
-"""
-from zope.app.index.interfaces.interfaces import \
-    IRankedObjectIterator, IRankedObjectRecord, \
-    IRankedHubIdList, IBatchedResult
-from zope.app.index.interfaces import IQueryProcessor
-
-from zope.component import getService
-from zope.app.servicenames import HubIds
-from zope.app.container.contained import Contained
-from zope.interface import implements
-
-class ObjectRetrievingProcessor(Contained):
-    """Converts a RankedHubIdList into an iteratable
-       list of ranked objects by retrieving the objects
-       from the ObjectHub.
-    """
-
-    implements(IQueryProcessor)
-
-    inputInterfaces = (IRankedHubIdList, IBatchedResult)
-    outputInterfaces = (IRankedObjectIterator,)
-
-    def __call__(self, query):
-        list = IRankedHubIdList(query)
-        batch = IBatchedResult(query)
-
-        objectHub = getService(HubIds)
-
-        # XXX do we need wrapping for the objects returned by the hub?
-        iterator = RankedObjectIterator(
-                        list,objectHub.getObject, batch.startPosition,
-                        batch.batchSize, batch.totalSize
-                        )
-
-        return iterator
-
-class RankedObjectIterator:
-    """Iterates over a given list of IRankedObjectRecord."""
-
-    implements(IRankedObjectIterator, IBatchedResult)
-
-    def __init__(self, recordlist, objectfetcher, startposition,
-                 batchsize, totalsize):
-        self._records = recordlist
-        self.startPosition = startposition
-        self.batchSize = batchsize
-        self.totalSize = totalsize
-        self.__objectfetcher = objectfetcher
-
-    def __iter__(self):
-        objectfetcher = self.__objectfetcher
-
-        for hubid, rank in self._records:
-            # XXX maybe we should catch some exceptions like security related
-            # ones or NotFoundError, to avoid breaking the iteration. Think
-            # about yielding an NotFound-Indicator in such a case.
-            yield RankedObjectRecord(objectfetcher(hubid), rank)
-        raise StopIteration
-
-class RankedObjectRecord(object):
-    """Contains a reference to a ranked object."""
-
-    __slots__ = ["rank", "object"]
-
-    implements(IRankedObjectRecord)
-
-    def __init__(self, object, rank):
-        self.rank = rank
-        self.object = object

Deleted: Zope3/branches/jim-index/src/zope/app/index/queries.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/queries.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/queries.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -1,34 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""Generic queries for indexes.
-
-$Id$
-"""
-
-from zope.app.index.interfaces.interfaces import IBatchedResult
-from zope.app.index.interfaces.interfaces import IRankedHubIdList
-from zope.interface import implements
-
-class BatchedRankedResult:
-
-    implements(IBatchedResult, IRankedHubIdList)
-
-    def __init__(self, hubidlist, startposition, batchsize, totalsize):
-        self.__hubidlist = hubidlist
-        self.startPosition = startposition
-        self.batchSize = batchsize
-        self.totalSize = totalsize
-
-    def __getitem__(self, index):
-        return self.__hubidlist[index]

Copied: Zope3/branches/jim-index/src/zope/app/index/tests.py (from rev 25354, Zope3/branches/jim-index/src/zope/app/index/tests/test_ifaceindex.py)

Modified: Zope3/branches/jim-index/src/zope/app/index/text/configure.zcml
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/text/configure.zcml	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/text/configure.zcml	2004-06-12 14:06:58 UTC (rev 25391)
@@ -9,9 +9,6 @@
       interface="zope.app.index.interfaces.text.IUITextIndex"
       attributes="query"
       />
-  <implements
-      interface="zope.app.index.interfaces.IQueryProcessable"
-      />
 </content>
 
 
@@ -28,16 +25,6 @@
       permission="zope.ManageContent"
       set_schema="zope.app.index.interfaces.text.IUITextCatalogIndex"
       />
-  <implements
-      interface="zope.app.index.interfaces.IQueryProcessable"
-      />
 </content>
 
-
-<adapter
-    factory="zope.app.index.text.processors.BatchedRankedProcessor"
-    provides="zope.app.index.interfaces.IQueryProcessor"
-    for="zope.index.interfaces.IQuerying"
-    />
-
 </configure>

Modified: Zope3/branches/jim-index/src/zope/app/index/text/index.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/text/index.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/text/index.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -34,8 +34,7 @@
 from zope.app.catalog.interfaces.index import ICatalogIndex
 
 
-class TextCatalogIndex(InterfaceIndexingSubscriber, TextIndexWrapper,
-                       Contained):
+class TextCatalogIndex(InterfaceIndexing, TextIndexWrapper, Contained):
     implements(ICatalogIndex, IUITextCatalogIndex)
 
     default_interface = ISearchableText
@@ -45,34 +44,7 @@
 
     implements(IUITextIndex)
 
-    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
-
-    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
-
-    def isSubscribed(self):
-        return self.currentlySubscribed
-
-    def _getChannel(wrapped_self, channel):
-        if channel is None:
-            channel = getService(wrapped_self, HubIds)
-        return channel
-
     def _update(wrapped_self, registrations):
         for location, hubid, wrapped_object in registrations:
             texts = wrapped_self._getValue(wrapped_object)

Deleted: Zope3/branches/jim-index/src/zope/app/index/text/processors.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/text/processors.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/text/processors.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -1,48 +0,0 @@
-##############################################################################
-#
-# 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.index.interfaces import IQuerying
-from zope.app.index.interfaces.interfaces import IBatchedResult
-from zope.app.index.interfaces.interfaces import IRankedHubIdList
-from zope.app.index.interfaces.interfaces import IBatchedTextIndexQuery
-from zope.app.index.interfaces import IQueryProcessor
-from zope.app.index.queries import BatchedRankedResult
-from zope.interface import implements
-
-class BatchedRankedProcessor:
-
-    implements(IQueryProcessor)
-    __used_for__ = IQuerying
-
-    inputInterfaces = (IBatchedTextIndexQuery,)
-    outputInterfaces = (IRankedHubIdList, IBatchedResult)
-
-    def __init__(self, textindex):
-        self.textindex = textindex
-
-    def __call__(self, query):
-        query = IBatchedTextIndexQuery(query)
-        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

Deleted: Zope3/branches/jim-index/src/zope/app/index/text/queries.py
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/text/queries.py	2004-06-12 13:36:06 UTC (rev 25390)
+++ Zope3/branches/jim-index/src/zope/app/index/text/queries.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -1,30 +0,0 @@
-##############################################################################
-#
-# 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.index.interfaces.interfaces import IBatchedTextIndexQuery
-from zope.interface import implements
-
-class BatchedTextIndexQuery:
-
-    implements(IBatchedTextIndexQuery)
-
-    def __init__(self, query, startposition, batchsize):
-
-        self.textIndexQuery = query
-        self.startPosition = startposition
-        self.batchSize = batchsize

Copied: Zope3/branches/jim-index/src/zope/app/index/text/tests.py (from rev 25353, Zope3/branches/jim-index/src/zope/app/index/text/tests/test_index.py)
===================================================================
--- Zope3/branches/jim-index/src/zope/app/index/text/tests/test_index.py	2004-06-11 15:22:11 UTC (rev 25353)
+++ Zope3/branches/jim-index/src/zope/app/index/text/tests.py	2004-06-12 14:06:58 UTC (rev 25391)
@@ -0,0 +1,126 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Tests for text index.
+
+$Id$
+"""
+
+import unittest
+
+from zope.app.event.objectevent import ObjectModifiedEvent
+from zope.app.site.tests.placefulsetup import PlacefulSetup
+from zope.app.traversing.api import traverse
+from zope.component import getService
+from zope.app.servicenames import HubIds
+from zope.app.hub.interfaces import \
+     IRegistrationHubEvent, IObjectModifiedHubEvent
+from zope.app.hub import \
+     ObjectRegisteredHubEvent, ObjectUnregisteredHubEvent, \
+     ObjectModifiedHubEvent
+
+from zope.app.index.interfaces.text import ISearchableText
+from zope.app.index.text.index import TextIndex
+from zope.interface import implements
+
+
+class FakeSearchableObject:
+    implements(ISearchableText)
+    def __init__(self):
+        self.texts = [u"Bruce"]
+    def getSearchableText(self):
+        return self.texts
+
+Bruce = u"Bruce"
+Sheila = u"Sheila"
+
+class Test(PlacefulSetup, unittest.TestCase):
+
+    def setUp(self):
+        PlacefulSetup.setUp(self, site=True)
+        self.index = TextIndex()
+        self.rootFolder['myIndex'] = self.index
+        self.rootFolder['bruce'] = FakeSearchableObject()
+        self.object = self.rootFolder['bruce']
+
+    def assertPresent(self, word, docid):
+        results, total = self.index.query(word)
+        self.assertEqual(total, 1)
+        self.assertEqual(results[0][0], docid)
+
+    def assertAbsent(self, word):
+        self.assertEqual(self.index.query(word), ([], 0))
+
+
+    def testNotIndexing(self):
+        docid = 1000
+        self.object.texts = None
+        event = ObjectRegisteredHubEvent(None, docid, object=self.object)
+        self.index.notify(event)
+        self.assertEqual(self.index.documentCount(), 0)
+
+    def testHubMachinery(self):
+        # Technically this is a functional test
+        self.createStandardServices()
+        index = traverse(self.rootFolder, '/myIndex')
+        hub = getService(self.rootFolder, HubIds)
+        
+        hub.subscribe(index, IRegistrationHubEvent)
+        hub.subscribe(index, IObjectModifiedHubEvent)
+        location = "/bruce"
+
+        hubid = hub.register(location)
+        self.assertPresent(Bruce, hubid)
+
+        self.object.texts = [Sheila]
+        event = ObjectModifiedEvent(self.object)
+        hub.notify(event)
+        self.assertPresent(Sheila, hubid)
+        self.assertAbsent(Bruce)
+
+        hub.unregister(location)
+        self.assertAbsent(Bruce)
+        self.assertAbsent(Sheila)
+
+    def testBootstrap(self):
+        # Need to set up a HubIds service because the standard subscription
+        # mix-ins expect to see one.
+        self.createStandardServices()
+    
+        index = traverse(self.rootFolder, '/myIndex')
+        self.assertEqual(index.isSubscribed(), False)
+        self.assertAbsent(Bruce)
+        self.assertAbsent(Sheila)
+        location = '/bruce'
+        hub = getService(self.rootFolder, HubIds)
+        hubid = hub.register(location)
+        index.subscribe(hub)
+        self.assertEqual(index.isSubscribed(), True)
+        self.assertPresent(Bruce, hubid)
+
+        index.unsubscribe(hub)
+        self.assertEqual(index.isSubscribed(), False)
+        self.assertPresent(Bruce, hubid)
+
+        self.object.texts = [Sheila]
+        event = ObjectModifiedEvent(self.object)
+        hub.notify(event)
+        self.assertPresent(Bruce, hubid)
+        self.assertAbsent(Sheila)
+
+
+def test_suite():
+    return unittest.makeSuite(Test)
+
+if __name__=='__main__':
+    unittest.main(defaultTest='test_suite')




More information about the Zope3-Checkins mailing list