Skip to content

Commit

Permalink
Merge b75528a into e751233
Browse files Browse the repository at this point in the history
  • Loading branch information
elioschmutz committed May 11, 2017
2 parents e751233 + b75528a commit 2aaab40
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Changelog
5.0.4 (unreleased)
------------------

- Fix: Reindexing solr-objects with specific attributes (atomic-update) will remove
all indexed attributes on an object if it does not provide this index or if the
field is multivalued and the value is empty. (fixes #171)
[elioschmutz]

- Use unittest instead unittest2 in test_browser_suggest.py to fix tests.
[elioschmutz]

Expand Down
2 changes: 1 addition & 1 deletion src/collective/solr/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def index(self, obj, attributes=None):
attributes.add(uniqueKey)

data, missing = self.getData(obj, attributes=attributes)
if not data:
if not data or not set(data.keys()) - set([uniqueKey]):
return # don't index with no data...
prepareData(data)
if data.get(uniqueKey, None) is not None and not missing:
Expand Down
10 changes: 8 additions & 2 deletions src/collective/solr/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,14 @@ def add(self, boost_values=None, atomic_updates=True, **fields):
tmpl = tmpl.replace(' update="set"', '')

if isinstance(v, (list, tuple)): # multi-valued
for value in v:
lst.append(tmpl % self.escapeVal(value))
if v:
for value in v:
lst.append(tmpl % self.escapeVal(value))
else:
# Add an empty element for empty lists/tuples.
# Otherwise all indexes gets removed if you update an empty
# multivalued attribute.
lst.append(tmpl % '')
else:
lst.append(tmpl % self.escapeVal(v))
lst.append('</doc>')
Expand Down
3 changes: 1 addition & 2 deletions src/collective/solr/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from Acquisition import aq_base
from Acquisition import aq_parent
from DateTime import DateTime
from Missing import MV
from Products.CMFCore.utils import getToolByName
from collective.indexing.queue import getQueue
from collective.indexing.queue import processQueue
Expand Down Expand Up @@ -1215,7 +1214,7 @@ def testFlareHasDataForAllMetadataColumns(self):
self.maintenance.reindex()
results = solrSearchResults(SearchableText='Welcome')
self.assertEqual(len(results), 1)
self.assertEqual(results[0].get('Subject'), MV)
self.assertEqual(results[0].get('Subject'), [''])
schema = self.search.getManager().getSchema()
expected = set(list(schema.stored) + ['score']) # score gets added
self.assertEqual(set(results[0].keys()), expected)
Expand Down

0 comments on commit 2aaab40

Please sign in to comment.