Skip to content

Commit

Permalink
BooleanIndex was wrong when index inversion occured
Browse files Browse the repository at this point in the history
  when an existing content was reindexed with an opposite value.
  Fixes LP #1236354.
  • Loading branch information
tdesvenain authored and hannosch committed Oct 15, 2013
1 parent 7de6910 commit 3142f9a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Changelog
2.13.25 (unreleased)
--------------------

- BooleanIndex was wrong when index inversion occured
when an existing content was reindexed with an opposite value.
Fixes LP #1236354.

2.13.24 (2013-10-15)
--------------------
Expand Down
30 changes: 15 additions & 15 deletions src/Products/PluginIndexes/BooleanIndex/BooleanIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,27 @@ def insertForwardIndexEntry(self, entry, documentId):
"""
# when we get the first entry, decide to index the opposite of what
# we got, as indexing zero items is fewer than one
length = self._length
index_length = self._index_length
# BBB inline migration
if index_length is None:
if self._index_length is None:
self._inline_migration()
length = self._length
index_length = self._index_length
if length.value == 0:

if self._length.value == 0:
self._index_value = int(not bool(entry))

# if the added entry value is index value, insert it into index
if bool(entry) is bool(self._index_value):
# is the index (after adding the current entry) larger than 60%
# of the total length? than switch the indexed value
if (index_length.value + 1) >= ((length.value + 1) * 0.6):
self._invert_index()
return

self._index_length.change(1)
self._index.insert(documentId)
index_length.change(1)

# insert value into global unindex (before computing index invert)
self._unindex[documentId] = entry
self._length.change(1)

# is the index (after adding the current entry) larger than 60%
# of the total length? than switch the indexed value
if bool(entry) is bool(self._index_value):
if (self._index_length.value) >= ((self._length.value) * 0.6):
self._invert_index()

def removeForwardIndexEntry(self, entry, documentId, check=True):
"""Take the entry provided and remove any reference to documentId
Expand Down Expand Up @@ -185,8 +187,6 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):

if datum is not _marker:
self.insertForwardIndexEntry(datum, documentId)
self._unindex[documentId] = datum
self._length.change(1)

returnStatus = 1

Expand Down
1 change: 1 addition & 0 deletions src/Products/PluginIndexes/BooleanIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_reindexation_when_index_reversed(self):
self.assertFalse(index._index_value)

res = index._apply_index({'truth': True})[0]
self.assertEqual(list(index._index), [2])
self.assertEqual(list(res), [1, 3, 4])


Expand Down

0 comments on commit 3142f9a

Please sign in to comment.