From f729e603504c6f3bf846a5a8fbd08c8ca4bae945 Mon Sep 17 00:00:00 2001 From: Gil Forcada Date: Mon, 14 Dec 2015 13:00:23 +0100 Subject: [PATCH] Soft commit on reindexes Allow data to be saved and ready to be used by Solr. Note that at the end of reindex a hard commit is done which will save the changes on the disk. See: http://wiki.apache.org/solr/UpdateXmlMessages#A.22commit.22_and_.22optimize.22 --- docs/CHANGES.rst | 4 ++++ src/collective/solr/browser/maintenance.py | 2 +- src/collective/solr/solr.py | 5 +++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/CHANGES.rst b/docs/CHANGES.rst index e34afb69e..fbc95283b 100644 --- a/docs/CHANGES.rst +++ b/docs/CHANGES.rst @@ -37,6 +37,10 @@ Changelog - Unify all exceptions raised by collective.solr. [gforcada] +- Soft commit changes while reindexing. + This allows to get results on searches while reindexing is taking place. + [gforcada] + 4.1.0 (2015-02-19) ------------------ diff --git a/src/collective/solr/browser/maintenance.py b/src/collective/solr/browser/maintenance.py index a81c744dd..6b898a671 100644 --- a/src/collective/solr/browser/maintenance.py +++ b/src/collective/solr/browser/maintenance.py @@ -121,7 +121,7 @@ def reindex(self, batch=1000, skip=0, limit=0, ignore_portal_types=None, schema = manager.getSchema() key = schema.uniqueKey updates = {} # list to hold data to be updated - flush = lambda: conn.flush() + flush = lambda: conn.commit(soft=True) flush = notimeout(flush) def checkPoint(): diff --git a/src/collective/solr/solr.py b/src/collective/solr/solr.py index 52bbc86fb..c82a1a065 100644 --- a/src/collective/solr/solr.py +++ b/src/collective/solr/solr.py @@ -270,12 +270,13 @@ def add(self, boost_values=None, atomic_updates=True, **fields): return self.doUpdateXML(xstr) - def commit(self, waitSearcher=True, optimize=False): + def commit(self, waitSearcher=True, optimize=False, soft=False): data = { 'committype': optimize and 'optimize' or 'commit', 'nowait': not waitSearcher and ' waitSearcher="false"' or '', + 'soft': soft and ' softCommit="true"' or '', } - xstr = '<%(committype)s%(nowait)s/>' % data + xstr = '<%(committype)s%(soft)s%(nowait)s/>' % data self.doUpdateXML(xstr) return self.flush()