Skip to content

Commit

Permalink
Continue to fix clearing of special values
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed May 27, 2019
1 parent cf950e6 commit 78efffb
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
29 changes: 12 additions & 17 deletions src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,30 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
# we have an existing entry for this document, and we need
# to figure out if any of the keywords have actually changed
if oldKeywords in (missing, empty):
oldSpecialvalue = oldKeywords
oldKeywords = OOSet()
elif not isinstance(oldKeywords, OOSet):
oldKeywords = OOSet(oldKeywords)
self.removeSpecialIndexEntry(oldKeywords, documentId)
oldSet = OOSet()
else:
if not isinstance(oldKeywords, OOSet):
oldKeywords = OOSet(oldKeywords)
oldSet = oldKeywords

if newKeywords in (missing, empty):
newSpecialvalue = newKeywords
newKeywords = OOSet()
self.insertSpecialIndexEntry(newKeywords, documentId)
newSet = OOSet()
else:
newKeywords = OOSet(newKeywords)
newSet = newKeywords = OOSet(newKeywords)

fdiff = difference(oldKeywords, newKeywords)
rdiff = difference(newKeywords, oldKeywords)
fdiff = difference(oldSet, newSet)
rdiff = difference(newSet, oldSet)
if fdiff or rdiff:
# if we've got forward or reverse changes
if newKeywords:
self._unindex[documentId] = OOSet(newKeywords)
else:
self.insertSpecialIndexEntry(newSpecialvalue, documentId)
self._unindex[documentId] = newSpecialvalue

if fdiff:
self.unindex_objectKeywords(documentId, fdiff)
if rdiff:
for kw in rdiff:
self.insertForwardIndexEntry(kw, documentId)

if not oldKeywords and oldSpecialvalue in (missing, empty):
self.removeSpecialIndexEntry(oldSpecialvalue, documentId)
self._unindex[documentId] = newKeywords

return 1

Expand Down
2 changes: 1 addition & 1 deletion src/Products/PluginIndexes/KeywordIndex/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def foo(self, name):
def test_value_removes(self):
to_index = Dummy(['hello'])
self._index._index_object(10, to_index, attr='foo')
self.assertTrue(self._index._unindex.get(10))
self.assertEqual(list(self._index._unindex.get(10)), ['hello'])

to_index = Dummy('')
self._index._index_object(10, to_index, attr='foo')
Expand Down
4 changes: 4 additions & 0 deletions src/Products/PluginIndexes/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ def getIndexNames():
class _SpecialIndexValue(str):
"""generic marker class for values that cannot be indexed regularly"""

def __iter__(self):
# don't treat _SpecialIndexValue as iterable string
yield self

def __bool__(self):
return False

Expand Down
7 changes: 6 additions & 1 deletion src/Products/PluginIndexes/unindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,12 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
oldDatum = self._unindex.get(documentId, _marker)
if datum != oldDatum:
if oldDatum is not _marker:
self.removeForwardIndexEntry(oldDatum, documentId)

if oldDatum in [missing, empty]:
self.removeSpecialIndexEntry(oldDatum, documentId)
else:
self.removeForwardIndexEntry(oldDatum, documentId)

if datum is _marker:
try:
del self._unindex[documentId]
Expand Down

0 comments on commit 78efffb

Please sign in to comment.