Commit 279c466f authored by Evan Simpson's avatar Evan Simpson

Merge bugfix from Zope-2_4-branch

parent f2d64fb7
...@@ -87,7 +87,7 @@ ...@@ -87,7 +87,7 @@
""" """
__version__ = '$Revision: 1.13 $'[11:-2] __version__ = '$Revision: 1.14 $'[11:-2]
import string, re import string, re
...@@ -202,6 +202,8 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -202,6 +202,8 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
self._lexicon = None self._lexicon = None
if lexicon is not None: if lexicon is not None:
...@@ -700,7 +702,6 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent, ...@@ -700,7 +702,6 @@ class TextIndex(PluggableIndex.PluggableIndex, Persistent,
else: i = i + 1 else: i = i + 1
if (len(query) != 1): if (len(query) != 1):
import pdb; pdb.set_trace()
raise QueryError, "Malformed query" raise QueryError, "Malformed query"
return query[0] return query[0]
...@@ -748,13 +749,14 @@ def parse(s): ...@@ -748,13 +749,14 @@ def parse(s):
def parse2(q, default_operator, operator_dict=operator_dict): def parse2(q, default_operator, operator_dict=operator_dict):
"""Find operators and operands""" """Find operators and operands"""
isop = operator_dict.has_key isop = operator_dict.has_key
i = len(q) - 1 i = 0
while i >= 0: while i < len(q):
e = q[i] e = q[i]
if isinstance(e, ListType): if isinstance(e, ListType):
q[i] = parse2(e, default_operator) q[i] = parse2(e, default_operator)
if i % 2: if i % 2:
q.insert(i, default_operator) q.insert(i, default_operator)
i = i + 1
elif i % 2: elif i % 2:
# This element should be an operator # This element should be an operator
if isop(e): if isop(e):
...@@ -763,7 +765,8 @@ def parse2(q, default_operator, operator_dict=operator_dict): ...@@ -763,7 +765,8 @@ def parse2(q, default_operator, operator_dict=operator_dict):
else: else:
# Insert the default operator. # Insert the default operator.
q.insert(i, default_operator) q.insert(i, default_operator)
i = i - 1 i = i + 1
i = i + 1
return q return q
......
...@@ -233,6 +233,7 @@ class Tests(unittest.TestCase): ...@@ -233,6 +233,7 @@ class Tests(unittest.TestCase):
def testDefOrQuery(self): def testDefOrQuery(self):
"Test a default OR query" "Test a default OR query"
self.globTest({'text':'time country'}, [0,1,6]) self.globTest({'text':'time country'}, [0,1,6])
self.globTest({'text':'time good country'}, [0,1,6])
def testNearQuery(self): def testNearQuery(self):
"""Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)""" """Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)"""
......
...@@ -91,7 +91,7 @@ undo information so that objects can be unindexed when the old value ...@@ -91,7 +91,7 @@ undo information so that objects can be unindexed when the old value
is no longer known. is no longer known.
""" """
__version__ = '$Revision: 1.50 $'[11:-2] __version__ = '$Revision: 1.51 $'[11:-2]
import string, re import string, re
...@@ -684,13 +684,14 @@ def parse2(q, default_operator, ...@@ -684,13 +684,14 @@ def parse2(q, default_operator,
operator_dict={AndNot: AndNot, And: And, Or: Or, Near: Near}): operator_dict={AndNot: AndNot, And: And, Or: Or, Near: Near}):
"""Find operators and operands""" """Find operators and operands"""
isop = operator_dict.has_key isop = operator_dict.has_key
i = len(q) - 1 i = 0
while i >= 0: while i < len(q):
e = q[i] e = q[i]
if isinstance(e, ListType): if isinstance(e, ListType):
q[i] = parse2(e, default_operator) q[i] = parse2(e, default_operator)
if i % 2: if i % 2:
q.insert(i, default_operator) q.insert(i, default_operator)
i = i + 1
elif i % 2: elif i % 2:
# This element should be an operator # This element should be an operator
if isop(e): if isop(e):
...@@ -699,7 +700,8 @@ def parse2(q, default_operator, ...@@ -699,7 +700,8 @@ def parse2(q, default_operator,
else: else:
# Insert the default operator. # Insert the default operator.
q.insert(i, default_operator) q.insert(i, default_operator)
i = i - 1 i = i + 1
i = i + 1
return q return q
......
...@@ -235,6 +235,7 @@ class Tests(unittest.TestCase): ...@@ -235,6 +235,7 @@ class Tests(unittest.TestCase):
def testDefOrQuery(self): def testDefOrQuery(self):
"Test a default OR query" "Test a default OR query"
self.globTest({'text':'time country'}, [0,1,6]) self.globTest({'text':'time country'}, [0,1,6])
self.globTest({'text':'time good country'}, [0,1,6])
def testNearQuery(self): def testNearQuery(self):
"""Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)""" """Test a NEAR query.. (NOTE:ACTUALLY AN 'AND' TEST!!)"""
......
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