[Checkins] SVN: Products.ZCatalog/trunk/ Extend `not` support to keyword indexes

Hano Schlichting cvs-admin at zope.org
Sun Mar 25 14:10:08 UTC 2012


Log message for revision 124725:
  Extend `not` support to keyword indexes
  

Changed:
  U   Products.ZCatalog/trunk/CHANGES.txt
  U   Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
  U   Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/tests.py
  U   Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py

-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt	2012-03-25 14:07:11 UTC (rev 124724)
+++ Products.ZCatalog/trunk/CHANGES.txt	2012-03-25 14:10:05 UTC (rev 124725)
@@ -4,9 +4,10 @@
 3.0 (unreleased)
 ----------------
 
-- Added support for `not` queries to FieldIndexes. Both restrictions of normal
-  queries and range queries are supported, as well as purely exclusive
-  queries. For example: `{'foo': {'query': ['a', 'ab'], 'not': 'a'}}`,
+- Added support for `not` queries in field and keyword indexes. Both
+  restrictions of normal queries and range queries are supported, as well as
+  purely exclusive queries. For example:
+  `{'foo': {'query': ['a', 'ab'], 'not': 'a'}}`,
   `{'query': 'a', 'range': 'min', 'not': ['a', 'e', 'f']}}` and
   `{'foo': {'not': ['a', 'b']}}`.
 

Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	2012-03-25 14:07:11 UTC (rev 124724)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py	2012-03-25 14:10:05 UTC (rev 124725)
@@ -37,7 +37,7 @@
         {'label': 'Browse', 'action': 'manage_browse'},
     )
 
-    query_options = ("query", "operator", "range")
+    query_options = ("query", "operator", "range", "not")
 
     def _index_object(self, documentId, obj, threshold=None, attr=''):
         """ index an object 'obj' with integer id 'i'

Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/tests.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/tests.py	2012-03-25 14:07:11 UTC (rev 124724)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/tests.py	2012-03-25 14:10:05 UTC (rev 124725)
@@ -62,6 +62,13 @@
         self._string_req = {'foo': 'a'}
         self._zero_req = {'foo': [0]}
 
+        self._not_1 = {'foo': {'query': 'f', 'not': 'f'}}
+        self._not_2 = {'foo': {'query': ['e', 'f'], 'not': 'f'}}
+        self._not_3 = {'foo': {'not': 0}}
+        self._not_4 = {'foo': {'not': [0, 'e']}}
+        self._not_5 = {'foo': {'not': [0, 'no-value']}}
+        self._not_6 = {'foo': 'c', 'bar': {'query': 123, 'not': 1}}
+
     def _populateIndex(self):
         for k, v in self._values:
             self._index.index_object(k, v)
@@ -137,6 +144,13 @@
         self._checkApply(self._overlap_req, values[2:7])
         self._checkApply(self._string_req, values[:-1])
 
+        self._checkApply(self._not_1, [])
+        self._checkApply(self._not_2, values[5:6])
+        self._checkApply(self._not_3, values[:7])
+        self._checkApply(self._not_4, values[:5])
+        self._checkApply(self._not_5, values[:7])
+        self._checkApply(self._not_6, values[2:7])
+
     def testZero(self):
         self._populateIndex()
         values = self._values

Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py	2012-03-25 14:07:11 UTC (rev 124724)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py	2012-03-25 14:10:05 UTC (rev 124725)
@@ -354,7 +354,6 @@
         if not record.keys and not_parm:
             # we have only a 'not' query
             record.keys = [k for k in index.keys() if k not in not_parm]
-            not_parm = None
 
         # experimental code for specifing the operator
         operator = record.get('operator',self.useOperator)



More information about the checkins mailing list