Skip to content

Commit

Permalink
Soft commit on reindexes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gforcada committed Jan 7, 2016
1 parent c0e8e05 commit f729e60
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGES.rst
Expand Up @@ -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)
------------------

Expand Down
2 changes: 1 addition & 1 deletion src/collective/solr/browser/maintenance.py
Expand Up @@ -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():
Expand Down
5 changes: 3 additions & 2 deletions src/collective/solr/solr.py
Expand Up @@ -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()

Expand Down

0 comments on commit f729e60

Please sign in to comment.