[Checkins] SVN: Products.ZCatalog/trunk/ Unify Unindex and DateIndex search logic (`_apply_index`) adding `not` support to DateIndexes.
Hano Schlichting
cvs-admin at zope.org
Sat Jun 2 14:58:38 UTC 2012
Log message for revision 126554:
Unify Unindex and DateIndex search logic (`_apply_index`) adding `not` support to DateIndexes.
Changed:
U Products.ZCatalog/trunk/CHANGES.txt
U Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/DateIndex.py
U Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/tests.py
U Products.ZCatalog/trunk/src/Products/PluginIndexes/FieldIndex/FieldIndex.py
U Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
U Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py
-=-
Modified: Products.ZCatalog/trunk/CHANGES.txt
===================================================================
--- Products.ZCatalog/trunk/CHANGES.txt 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/CHANGES.txt 2012-06-02 14:58:34 UTC (rev 126554)
@@ -4,6 +4,8 @@
3.0a3 (unreleased)
------------------
+- Unify Unindex and DateIndex search logic (`_apply_index`) adding `not`
+ support to DateIndexes.
3.0a2 (2012-04-26)
------------------
Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/DateIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/DateIndex.py 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/DateIndex.py 2012-06-02 14:58:34 UTC (rev 126554)
@@ -87,7 +87,7 @@
implements(IDateIndex)
meta_type = 'DateIndex'
- query_options = ('query', 'range')
+ query_options = ('query', 'range', 'not')
index_naive_time_as_local = True # False means index as UTC
_properties = ({'id': 'index_naive_time_as_local',
@@ -150,83 +150,6 @@
return returnStatus
- def _apply_index(self, request, resultset=None):
- """Apply the index to query parameters given in the argument
-
- Normalize the 'query' arguments into integer values at minute
- precision before querying.
- """
- record = parseIndexRequest(request, self.id, self.query_options)
- if record.keys is None:
- return None
-
- keys = map(self._convert, record.keys)
- index = self._index
- r = None
- opr = None
-
- # experimental code for specifying the operator
- operator = record.get('operator', self.useOperator)
- if not operator in self.operators:
- raise RuntimeError("operator not valid: %s" % operator)
-
- # depending on the operator we use intersection or union
- if operator == "or":
- set_func = union
- else:
- set_func = intersection
-
- # range parameter
- range_arg = record.get('range', None)
- if range_arg:
- opr = "range"
- opr_args = []
- if range_arg.find("min") > -1:
- opr_args.append("min")
- if range_arg.find("max") > -1:
- opr_args.append("max")
-
- if record.get('usage', None):
- # see if any usage params are sent to field
- opr = record.usage.lower().split(':')
- opr, opr_args = opr[0], opr[1:]
-
- if opr == "range": # range search
- if 'min' in opr_args:
- lo = min(keys)
- else:
- lo = None
-
- if 'max' in opr_args:
- hi = max(keys)
- else:
- hi = None
-
- if hi:
- setlist = index.values(lo, hi)
- else:
- setlist = index.values(lo)
-
- r = multiunion(setlist)
-
- else: # not a range search
- for key in keys:
- set = index.get(key, None)
- if set is not None:
- if isinstance(set, int):
- set = IISet((set,))
- else:
- # set can't be bigger than resultset
- set = intersection(set, resultset)
- r = set_func(r, set)
-
- if isinstance(r, int):
- r = IISet((r,))
-
- if r is None:
- return IISet(), (self.id, )
- return r, (self.id, )
-
def _convert(self, value, default=None):
"""Convert Date/Time value to our internal representation"""
if isinstance(value, DateTime):
Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/tests.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/tests.py 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/DateIndex/tests.py 2012-06-02 14:58:34 UTC (rev 126554)
@@ -10,8 +10,6 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""DateIndex unit tests.
-"""
import unittest
@@ -205,7 +203,7 @@
'range': 'min:max'}},
[])
- def test_retrieval( self ):
+ def test_retrieval(self):
from DateTime import DateTime
index = self._makeOne()
self._populateIndex(index)
@@ -248,6 +246,18 @@
self._checkApply(index,
{'date': 1072742900}, [values[7]])
+
+ def test_not(self):
+ from DateTime import DateTime
+ index = self._makeOne()
+ self._populateIndex(index)
+ values = self._getValues()
+ # all but the None value
+ self._checkApply(index, {'date': {'not': 123}}, values[1:])
+ self._checkApply(index, {'date': {'not': DateTime(0)}}, values[2:])
+ self._checkApply(index, {'date': {'not':
+ [DateTime(0), DateTime('2002-05-08 15:16:17')]}}, values[3:])
+
def test_naive_convert_to_utc(self):
index = self._makeOne()
values = self._getValues()
Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/FieldIndex/FieldIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/FieldIndex/FieldIndex.py 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/FieldIndex/FieldIndex.py 2012-06-02 14:58:34 UTC (rev 126554)
@@ -20,14 +20,13 @@
"""Index for simple fields.
"""
meta_type = "FieldIndex"
+ query_options = ('query', 'range', 'not')
manage_options = (
{'label': 'Settings', 'action': 'manage_main'},
{'label': 'Browse', 'action': 'manage_browse'},
)
- query_options = ["query", "range", "not"]
-
manage = manage_main = DTMLFile('dtml/manageFieldIndex', globals())
manage_main._setName('manage_main')
manage_browse = DTMLFile('../dtml/browseIndex', globals())
Modified: Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py 2012-06-02 14:58:34 UTC (rev 126554)
@@ -31,14 +31,13 @@
This should have an _apply_index that returns a relevance score
"""
meta_type = "KeywordIndex"
+ query_options = ('query', 'range', 'not', 'operator')
manage_options = (
{'label': 'Settings', 'action': 'manage_main'},
{'label': 'Browse', 'action': 'manage_browse'},
)
- 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/common/UnIndex.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py 2012-06-01 17:28:46 UTC (rev 126553)
+++ Products.ZCatalog/trunk/src/Products/PluginIndexes/common/UnIndex.py 2012-06-02 14:58:34 UTC (rev 126554)
@@ -295,6 +295,9 @@
setlist.append(s)
return multiunion(setlist)
+ def _convert(self, value, default=None):
+ return value
+
def _apply_index(self, request, resultset=None):
"""Apply the index to query parameters given in the request arg.
@@ -341,8 +344,13 @@
# not / exclude parameter
not_parm = record.get('not', None)
if not record.keys and not_parm:
+ # convert into indexed format
+ not_parm = map(self._convert, not_parm)
# we have only a 'not' query
record.keys = [k for k in index.keys() if k not in not_parm]
+ else:
+ # convert query arguments into indexed format
+ record.keys = map(self._convert, record.keys)
# experimental code for specifing the operator
operator = record.get('operator', self.useOperator)
More information about the checkins
mailing list