Skip to content

Commit

Permalink
Code further generalized II
Browse files Browse the repository at this point in the history
  • Loading branch information
andbag committed Jun 11, 2019
1 parent e595088 commit d059521
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/Products/PluginIndexes/KeywordIndex/KeywordIndex.py
Expand Up @@ -69,7 +69,7 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):

if oldKeywords is _marker:
# we've got a new document, let's not futz around.
if newKeywords in (missing, empty):
if self.providesSpecialIndex(newKeywords):
self.insertSpecialIndexEntry(newKeywords, documentId)
else:
newKeywords = self.index_objectKeywords(documentId,
Expand All @@ -82,6 +82,15 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
else:
# we have an existing entry for this document, and we need
# to figure out if any of the keywords have actually changed
if self.providesSpecialIndex(oldKeywords) and \
self.providesSpecialIndex(newKeywords):
if oldKeywords == newKeywords:
return 0
self.removeSpecialIndexEntry(oldKeywords, documentId)
self.insertSpecialIndexEntry(newKeywords, documentId)
self._unindex[documentId] = newKeywords
return 1

if self.providesSpecialIndex(oldKeywords):
self.removeSpecialIndexEntry(oldKeywords, documentId)
oldSet = OOSet()
Expand Down Expand Up @@ -109,6 +118,9 @@ def _index_object(self, documentId, obj, threshold=None, attr=''):
# is indexable?
if not newKeywords:
return 0
else:
# return if no diff
return 0

self._unindex[documentId] = newKeywords

Expand Down
17 changes: 14 additions & 3 deletions src/Products/PluginIndexes/interfaces.py
Expand Up @@ -285,8 +285,16 @@ def getIndexNames():
""" returns index names that are optimized by index """


class _SpecialIndexValue(str):
class SpecialIndexValue(object):
"""generic marker class for values that cannot be indexed regularly"""
def __init__(self, name):
self.name = name

def __str__(self):
return self.name

def __repr__(self):
return '<{0}: {1}>'.format(self.__class__.__name__, self.name)

def __iter__(self):
# don't treat _SpecialIndexValue as iterable string
Expand All @@ -298,6 +306,9 @@ def __bool__(self):
# python2.7 backward compatibility
__nonzero__ = __bool__

def __lt__(self, other):
return self.name < other.name


class _IIndexingSpecialValue(Interface):
"""Abstract marker interface to mark indexes which support a
Expand All @@ -321,7 +332,7 @@ class IIndexingMissingValue(_IIndexingSpecialValue):
# `missing` can be used as query term to query
# for objects the index does not have a value for
# (like a not defined value)
missing = _SpecialIndexValue('missing')
missing = SpecialIndexValue('missing')


class IIndexingEmptyValue(_IIndexingSpecialValue):
Expand All @@ -331,4 +342,4 @@ class IIndexingEmptyValue(_IIndexingSpecialValue):

# `empty` Value can be used as query term to query
# for objects with an empty value (like an empty set)
empty = _SpecialIndexValue('empty')
empty = SpecialIndexValue('empty')

0 comments on commit d059521

Please sign in to comment.