Skip to content

Commit

Permalink
not operator should process empty lists
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Mar 21, 2018
1 parent 2a21568 commit 5662260
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/Products/PluginIndexes/DateIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def test_not(self):
{'not': [DateTime(0),
DateTime('2002-05-08 15:16:17')]}},
values[3:])
self._checkApply(index, {'date': {'not': []}}, values[0:])

def test_naive_convert_to_utc(self):
index = self._makeOne()
Expand Down
2 changes: 2 additions & 0 deletions src/Products/PluginIndexes/FieldIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def setUp(self):
self._not_4 = {'foo': {'not': ['0']}}
self._not_5 = {'foo': {'not': ['a', 'b']}}
self._not_6 = {'foo': 'a', 'bar': {'query': 123, 'not': 1}}
self._not_7 = {'foo': {'not': []}}

def _populateIndex(self):
for k, v in self._values:
Expand Down Expand Up @@ -209,6 +210,7 @@ def testPopulated(self):
self._checkApply(self._not_4, values[:7])
self._checkApply(self._not_5, values[1:])
self._checkApply(self._not_6, values[0:1])
self._checkApply(self._not_7, values[:7])

def testNone(self):
# Make sure None is ignored.
Expand Down
2 changes: 2 additions & 0 deletions src/Products/PluginIndexes/KeywordIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def setUp(self):
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}}
self._not_7 = {'foo': {'not': []}}

def _populateIndex(self):
for k, v in self._values:
Expand Down Expand Up @@ -184,6 +185,7 @@ def testPopulated(self):
self._checkApply(self._not_4, values[:5])
self._checkApply(self._not_5, values[:7])
self._checkApply(self._not_6, values[2:7])
self._checkApply(self._not_7, values[:7])

def testReindexChange(self):
self._populateIndex()
Expand Down
10 changes: 5 additions & 5 deletions src/Products/PluginIndexes/unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,14 +452,14 @@ def query_index(self, record, resultset=None):
if isinstance(cached, int):
cached = IISet((cached, ))

if not_parm:
if not_parm is not None:
not_parm = list(map(self._convert, not_parm))
exclude = self._apply_not(not_parm, resultset)
cached = difference(cached, exclude)

return cached

if not record.keys and not_parm:
if not record.keys and not_parm is not None:
# convert into indexed format
not_parm = list(map(self._convert, not_parm))
# we have only a 'not' query
Expand Down Expand Up @@ -509,7 +509,7 @@ def query_index(self, record, resultset=None):
else:
cache[cachekey] = [result]

if not_parm:
if not_parm is not None:
exclude = self._apply_not(not_parm, resultset)
result = difference(result, exclude)
return result
Expand Down Expand Up @@ -587,7 +587,7 @@ def query_index(self, record, resultset=None):
else:
cache[cachekey] = [result]

if not_parm:
if not_parm is not None:
exclude = self._apply_not(not_parm, resultset)
result = difference(result, exclude)
return result
Expand Down Expand Up @@ -634,7 +634,7 @@ def query_index(self, record, resultset=None):
r = IISet((r, ))
if r is None:
return IISet()
if not_parm:
if not_parm is not None:
exclude = self._apply_not(not_parm, resultset)
r = difference(r, exclude)
return r
Expand Down

1 comment on commit 5662260

@sgeulette
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello,
Sorry for my slowness to give you a feedback.
Thanks for your work.
Using Plone I can't easily try those adaptations without modifying other products.
I keep in mind those branch to test it later.
Regards

Please sign in to comment.