Commit a7c52c71 authored by Tres Seaver's avatar Tres Seaver

 - Test "record-style" parameters (caught typo on 'range', which was
   the built-in, rather than the parameter).

 - Ensure that queries which mix 'range' and 'operator' for a given index
   do the Right Thing (TM) (FieldIndexes ignore 'operator'; KeywordIndexes
   ignore 'range').
parent 06eeb956
......@@ -226,9 +226,11 @@ class TestCase( unittest.TestCase ):
for i in range(100):
index.index_object(i, Dummy(i%10))
r=index._apply_index({
'foo_usage': 'range:min:max',
'foo': [-99, 3]})
record = { 'foo' : { 'query' : [-99, 3]
, 'range' : 'min:max'
}
}
r=index._apply_index( record )
assert tuple(r[1])==('foo',), r[1]
r=list(r[0].keys())
......@@ -241,5 +243,15 @@ class TestCase( unittest.TestCase ):
assert r==expect, r
#
# Make sure that range tests with incompatible paramters
# don't return empty sets.
#
record[ 'foo' ][ 'operator' ] = 'and'
r2, ignore = index._apply_index( record )
r2 = list( r2.keys() )
assert r2 == r
def test_suite():
return unittest.makeSuite( TestCase )
......@@ -255,5 +255,22 @@ class TestCase( unittest.TestCase ):
assert len(result) == 1
assert result[0] == 8
def testIntersectionWithRange(self):
"""Test an 'and' search, ensuring that 'range' doesn't mess it up."""
self._populateIndex()
record = { 'foo' : { 'query' : [ 'e', 'f' ]
, 'operator' : 'and'
}
}
self._checkApply( record, self._values[6:7] )
#
# Make sure that 'and' tests with incompatible paramters
# don't return empty sets.
#
record[ 'foo' ][ 'range' ] = 'min:max'
self._checkApply( record, self._values[6:7] )
def test_suite():
return unittest.makeSuite( TestCase )
......@@ -85,7 +85,7 @@
"""Simple column indices"""
__version__='$Revision: 1.4 $'[11:-2]
__version__='$Revision: 1.5 $'[11:-2]
from Globals import Persistent
from Acquisition import Implicit
......@@ -396,11 +396,14 @@ class UnIndex(Persistent, Implicit):
else: set_func = intersection
# Range parameter
if record.get('range',None):
range_parm = record.get('range',None)
if range_parm:
opr = "range"
opr_args = []
if range.find("min")>-1: opr_args.append("min")
if range.find("max")>-1: opr_args.append("max")
if range_parm.find("min")>-1:
opr_args.append("min")
if range_parm.find("max")>-1:
opr_args.append("max")
if record.get('usage',None):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment