private long fillIndex(final OProgressListener iProgressListener, final boolean rebuild) {
long documentIndexed = 0;
try {
long documentNum = 0;
long documentTotal = 0;
for (final String cluster : clustersToIndex)
documentTotal += storage.count(storage.getClusterIdByName(cluster));
if (iProgressListener != null)
iProgressListener.onBegin(this, documentTotal, rebuild);
for (final String clusterName : clustersToIndex) {
final long[] metrics = indexCluster(clusterName, iProgressListener, documentNum, documentIndexed, documentTotal);
documentNum = metrics[0];
documentIndexed = metrics[1];
}
if (iProgressListener != null)
iProgressListener.onCompletition(this, true);
} catch (final RuntimeException e) {
if (iProgressListener != null)
iProgressListener.onCompletition(this, false);
throw e;
}
return documentIndexed;
}