Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
Fixed problem discribed here : https://dev.plone.org/ticket/13310 : Z…
Browse files Browse the repository at this point in the history
…CTextIndex not reindexed when the new value is an empty value
  • Loading branch information
gbastien committed Nov 13, 2012
1 parent 24c1669 commit f5a6ae6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGES.txt
Expand Up @@ -3,7 +3,9 @@ Changelog

2.13.4 (unreleased)
-------------------

- Fixed problem where the index was not reindexed if the new value was an empty value
leading to inconsistence between the object attribute (that is empty) and the index
that still contains the old indexed value [gauthier.bastien]

2.13.3 (2011-07-28)
-------------------
Expand Down
5 changes: 1 addition & 4 deletions src/Products/ZCTextIndex/ZCTextIndex.py
Expand Up @@ -176,7 +176,6 @@ def index_object(self, documentId, obj, threshold=None):
try: fields = self._indexed_attrs
except: fields = [ self._fieldname ]

res = 0
all_texts = []
for attr in fields:
text = getattr(obj, attr, None)
Expand All @@ -195,9 +194,7 @@ def index_object(self, documentId, obj, threshold=None):
# Check that we're sending only strings
all_texts = filter(lambda text: isinstance(text, basestring), \
all_texts)
if all_texts:
return self.index.index_doc(documentId, all_texts)
return res
return self.index.index_doc(documentId, all_texts)

def unindex_object(self, docid):
if self.index.has_doc(docid):
Expand Down
31 changes: 31 additions & 0 deletions src/Products/ZCTextIndex/tests/testZCTextIndex.py
Expand Up @@ -176,6 +176,37 @@ def testListAttributes(self):
nbest, total = zc_index.query('Tuesday Tim York')
self.assertEqual(len(nbest), 0)

def testReindex(self):
lexicon = PLexicon('lexicon', '',
Splitter(),
CaseNormalizer(),
StopWordRemover())
caller = LexiconHolder(self.lexicon)
zc_index = ZCTextIndex('name',
None,
caller,
self.IndexFactory,
'text',
'lexicon')
doc = Indexable('Hello Tim')
zc_index.index_object(1, doc)
nbest, total = zc_index.query('glorious')
self.assertEqual(len(nbest), 0)
nbest, total = zc_index.query('Tim')
self.assertEqual(len(nbest), 1)
# reindex with another value
doc.text = 'Goodbye George'
zc_index.index_object(1, doc)
nbest, total = zc_index.query('Tim')
self.assertEqual(len(nbest), 0)
nbest, total = zc_index.query('Goodbye')
self.assertEqual(len(nbest), 1)
# reindex with an empty value
doc.text = ''
zc_index.index_object(1, doc)
nbest, total = zc_index.query('George')
self.assertEqual(len(nbest), 0)

def testStopWords(self):
# the only non-stopword is question
text = ("to be or not to be "
Expand Down

0 comments on commit f5a6ae6

Please sign in to comment.