[Zope-Checkins] SVN: Zope/trunk/ - PluggableIndexes interface: + indexSize()

Andreas Jung andreas at andreas-jung.com
Fri Feb 4 13:08:02 EST 2005


Log message for revision 29045:
  - PluggableIndexes interface: + indexSize()
  - browser for stored values for all UnIndex derived indexes
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/dtml/manageDateIndex.dtml
  U   Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/dtml/manageDateRangeIndex.dtml
  U   Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/FieldIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/dtml/manageFieldIndex.dtml
  U   Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/tests/testFieldIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/dtml/manageKeywordIndex.dtml
  U   Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py
  U   Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/dtml/managePathIndex.dtml
  U   Zope/trunk/lib/python/Products/PluginIndexes/common/PluggableIndex.py
  A   Zope/trunk/lib/python/Products/PluginIndexes/dtml/
  U   Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py
  U   Zope/trunk/lib/python/Products/ZCatalog/ZCatalog.py
  U   Zope/trunk/lib/python/Products/ZCatalog/dtml/catalogIndexes.dtml

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/doc/CHANGES.txt	2005-02-04 18:08:01 UTC (rev 29045)
@@ -30,6 +30,13 @@
 
     Features added
 
+      - PluginIndexes: the ZCatalog's "Indexes" tab now show the number of
+        distinct values indexed by each index instead of a mixture of indexed
+        objects versus number of distinct values. Indexes derived from UnIndex 
+        show both values within their own ZMI screen. In addition most indexes 
+        have now a "Browse" tab to browse through the list of indexed 
+        values and their occurrences.
+
       - FTPServer: a RNFR (rename from) request is now being responded
         with a 550 error code if the source file does not exist
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/DateIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -88,18 +88,23 @@
                   'mode':'w'},)
 
     manage = manage_main = DTMLFile( 'dtml/manageDateIndex', globals() )
+    manage_browse = DTMLFile('../dtml/browseIndex', globals())
+
     manage_main._setName( 'manage_main' )
     manage_options = ( { 'label' : 'Settings'
                        , 'action' : 'manage_main'
                        },
+                       {'label': 'Browse',
+                        'action': 'manage_browse',
+                       },
                      ) + PropertyManager.manage_options
 
     def clear( self ):
         """ Complete reset """
         self._index = IOBTree()
         self._unindex = OIBTree()
+        self._length.set(0)
 
-
     def index_object( self, documentId, obj, threshold=None ):
         """index an object, normalizing the indexed value to an integer
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/dtml/manageDateIndex.dtml
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/dtml/manageDateIndex.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateIndex/dtml/manageDateIndex.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -2,7 +2,9 @@
 <dtml-var manage_tabs>
 
 <p class="form-help">
-Nothing to manage at this time.
+Objects indexed: <dtml-var numObjects>
+<br>
+Distinct values: <dtml-var indexSize>
 </p>
 
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/DateRangeIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -25,6 +25,7 @@
 
 from BTrees.IOBTree import IOBTree
 from BTrees.IIBTree import IISet, IITreeSet, union, intersection, multiunion
+import BTrees.Length
 
 from Globals import package_home, DTMLFile, InitializeClass
 from AccessControl import ClassSecurityInfo
@@ -136,6 +137,7 @@
         self._since         = IOBTree()
         self._until         = IOBTree()
         self._unindex       = IOBTree() # 'datum' will be a tuple of date ints
+        self._length        = BTrees.Length.Length()
 
     #
     #   PluggableIndexInterface implementation (XXX inherit assertions?)
@@ -310,10 +312,13 @@
     #
     security.declareProtected( VIEW_PERMISSION , 'numObjects' )
     def numObjects( self ):
-        """
-        """
+        """ """
         return len( self._unindex )
 
+    def indexSize(self):
+        """ """
+        return len(self)
+
     #
     #   Helper functions.
     #

Modified: Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/dtml/manageDateRangeIndex.dtml
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/dtml/manageDateRangeIndex.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/DateRangeIndex/dtml/manageDateRangeIndex.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -6,6 +6,12 @@
 <emUpdate</em>.
 </p>
 
+<p>
+Objects indexed: <dtml-var numObjects>
+<br>
+Distinct values: <dtml-var indexSize>
+</p>
+
 <form action="&dtml-URL1;/manage_edit" method="POST">
 <table cellpadding="2" cellspacing="0" border="0">
 <tr>

Modified: Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/FieldIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/FieldIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/FieldIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -32,6 +32,9 @@
         {'label': 'Settings',
          'action': 'manage_main',
          'help': ('FieldIndex','FieldIndex_Settings.stx')},
+        {'label': 'Browse',
+         'action': 'manage_browse',
+         'help': ('FieldIndex','FieldIndex_Settings.stx')},
     )
 
     query_options = ["query","range"]
@@ -39,6 +42,7 @@
     index_html = DTMLFile('dtml/index', globals())
 
     manage_workspace = DTMLFile('dtml/manageFieldIndex', globals())
+    manage_browse = DTMLFile('../dtml/browseIndex', globals())
 
 
 manage_addFieldIndexForm = DTMLFile('dtml/addFieldIndex', globals())

Modified: Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/dtml/manageFieldIndex.dtml
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/dtml/manageFieldIndex.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/dtml/manageFieldIndex.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -2,7 +2,9 @@
 <dtml-var manage_tabs>
 
 <p class="form-help">
-Nothing to manage at this time.
+Objects indexed: <dtml-var numObjects>
+<br>
+Distinct values: <dtml-var indexSize>
 </p>
 
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/tests/testFieldIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/tests/testFieldIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/FieldIndex/tests/testFieldIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -116,7 +116,7 @@
 
         assert len( self._index ) == len( values )-1 #'abce' is duplicate
         assert len( self._index.referencedObjects() ) == len( values )
-        self.assertEqual(self._index.numObjects(), len( values )-1)
+        self.assertEqual(self._index.indexSize(), len( values )-1)
 
         assert self._index.getEntryForObject( 1234 ) is None
         assert ( self._index.getEntryForObject( 1234, self._marker )

Modified: Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -34,6 +34,9 @@
         {'label': 'Settings',
          'action': 'manage_main',
          'help': ('KeywordIndex','KeywordIndex_Settings.stx')},
+        {'label': 'Browse',
+         'action': 'manage_browse',
+         'help': ('FieldIndex','FieldIndex_Settings.stx')},
     )
 
     query_options = ("query","operator", "range")
@@ -128,6 +131,7 @@
 
     index_html = DTMLFile('dtml/index', globals())
     manage_workspace = DTMLFile('dtml/manageKeywordIndex', globals())
+    manage_browse = DTMLFile('../dtml/browseIndex', globals())
 
 
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/dtml/manageKeywordIndex.dtml
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/dtml/manageKeywordIndex.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/dtml/manageKeywordIndex.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -2,7 +2,9 @@
 <dtml-var manage_tabs>
 
 <p class="form-help">
-Nothing to manage at this time.
+Objects indexed: <dtml-var numObjects>
+<br>
+Distinct values: <dtml-var indexSize>
 </p>
 
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/KeywordIndex/tests/testKeywordIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -142,7 +142,7 @@
         assert ( self._index.getEntryForObject( 1234, self._marker )
                   is self._marker )
         self._index.unindex_object( 1234 ) # nothrow
-        self.assertEqual(self._index.numObjects(), len( values )-1)
+        self.assertEqual(self._index.indexSize(), len( values )-1)
 
         for k, v in values:
             entry = self._index.getEntryForObject( k )

Modified: Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/PathIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -113,7 +113,6 @@
         comps = filter(None, path.split('/'))
        
         if not self._unindex.has_key(docid):
-            self._migrate_length()
             self._length.change(1)
 
         for i in range(len(comps)):
@@ -146,7 +145,6 @@
                 LOG.error('Attempt to unindex document with id %s failed'
                           % docid)
 
-        self._migrate_length()
         self._length.change(-1)
         del self._unindex[docid]
 
@@ -200,15 +198,16 @@
             return results
 
     def numObjects(self):
+        """ return the number distinct values """
+        return len(self._unindex)
+
+    def indexSize(self):
         """ return the number of indexed objects"""
-        self._migrate_length()
+        return len(self)
+
+    def __len__(self):
         return self._length()
 
-    def _migrate_length(self):
-        """ migrate index to use new _length attribute """
-        if not hasattr(self, '_length'):
-            self._length = Length(len(self._unindex))
-
     def _apply_index(self, request, cid=''):
         """ hook for (Z)Catalog
             'request' --  mapping type (usually {"path": "..." }

Modified: Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/dtml/managePathIndex.dtml
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/dtml/managePathIndex.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/PathIndex/dtml/managePathIndex.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -2,7 +2,9 @@
 <dtml-var manage_tabs>
 
 <p class="form-help">
-Nothing to manage at this time.
+Objects indexed: <dtml-var numObjects>
+<br>
+Distinct values: <dtml-var indexSize>
 </p>
 
 

Modified: Zope/trunk/lib/python/Products/PluginIndexes/common/PluggableIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/PluginIndexes/common/PluggableIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/PluginIndexes/common/PluggableIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -67,6 +67,9 @@
     
     def numObjects():
         """Return the number of indexed objects"""
+
+    def indexSize():
+        """Return the size of the index in terms of distinct values"""
     
     def clear():
         """Empty the index"""

Copied: Zope/trunk/lib/python/Products/PluginIndexes/dtml (from rev 29042, Zope/branches/ajung-indexes-desuxing-branch/lib/python/Products/PluginIndexes/dtml)

Modified: Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/ZCTextIndex/ZCTextIndex.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -217,6 +217,10 @@
         """Return number of unique words in the index"""
         return self.index.length()
 
+    def indexSize(self):
+        """Return the number of indexes objects """
+        return self.index.document_count()
+
     def clear(self):
         """reinitialize the index (but not the lexicon)"""
         try:

Modified: Zope/trunk/lib/python/Products/ZCatalog/ZCatalog.py
===================================================================
--- Zope/trunk/lib/python/Products/ZCatalog/ZCatalog.py	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/ZCatalog/ZCatalog.py	2005-02-04 18:08:01 UTC (rev 29045)
@@ -908,7 +908,8 @@
            __len__ changed in Zope 2.8. Pre-Zope 2.7 installation used to implement
            __len__ as persistent attribute of the index instance which is totally
            incompatible with the new extension class implementation based on new-style
-           classes.
+           classes. CMF indexes on date fields will be converted to DateIndex and 
+           DateRangeIndex.
         """
 
         LOG.info('Start migration of indexes for %s' % self.absolute_url(1))
@@ -925,6 +926,10 @@
                 idx_type = idx.meta_type
                 idx_id = idx.getId()
                 LOG.info('processing index %s' % idx_id)
+                if idx_type == 'FieldIndex' and idx_id in ('start', 'modified', 'end', 'created'):
+                    idx_type = 'DateIndex'
+                if idx_type == 'FieldIndex' and idx_id in ('effective', 'expires'):
+                    idx_type = 'DateRangeIndex'
                 indexed_attrs = getattr(idx, 'indexed_attrs', None)
                 self.delIndex(idx.getId())
                 self.addIndex(idx_id, idx_type)

Modified: Zope/trunk/lib/python/Products/ZCatalog/dtml/catalogIndexes.dtml
===================================================================
--- Zope/trunk/lib/python/Products/ZCatalog/dtml/catalogIndexes.dtml	2005-02-04 18:02:30 UTC (rev 29044)
+++ Zope/trunk/lib/python/Products/ZCatalog/dtml/catalogIndexes.dtml	2005-02-04 18:08:01 UTC (rev 29045)
@@ -104,13 +104,13 @@
   </td>
 
   <td width="20%" align="left"><div class="list-item"><a 
-   href="./manage_catalogIndexes?skey=numObjects<dtml-if 
-   "rkey == ''">&rkey=numObjects</dtml-if
+   href="./manage_catalogIndexes?skey=indexSize<dtml-if 
+   "rkey == ''">&rkey=indexSize</dtml-if
    >"
-   onMouseOver="window.status='Sort objects by number of indexed objects'; return true"
+   onMouseOver="window.status='Sort objects by number of distinct values indexed'; return true"
    onMouseOut="window.status=''; return true"><dtml-if 
-   "skey == 'numObjects' or rkey == 'numObjects'"
-   ><strong># objects</strong><dtml-else># objects</dtml-if></a></div>
+   "skey == 'indexSize' or rkey == 'indexSize'"
+   ><strong># distinct values</strong><dtml-else># distinct values</dtml-if></a></div>
   </td>
 
   <td width="20%" align="left"><div class="list-item"><a 
@@ -169,7 +169,7 @@
 
     <td>
       <div class="list-item">
-        <dtml-var numObjects missing="n/a">
+        <dtml-var indexSize missing="n/a">
       </div>
     </td>
 
@@ -183,6 +183,7 @@
 
 </tr>
 </dtml-in>
+
 </table>
 
 <table cellspacing="0" cellpadding="2" border="0">



More information about the Zope-Checkins mailing list