Search in sources :

Example 1 with LengthSolrInputDocument

use of org.xwiki.search.solr.internal.metadata.LengthSolrInputDocument in project xwiki-platform by xwiki.

the class DefaultSolrIndexer method processBatch.

/**
 * Process a batch of operations that were just read from the index operations queue. This method also commits the
 * batch when it finishes to process it.
 *
 * @param queueEntry the batch to process
 * @return {@code true} to wait for another batch, {@code false} to stop the indexing thread
 */
private boolean processBatch(IndexQueueEntry queueEntry) {
    SolrInstance solrInstance = this.solrInstanceProvider.get();
    int length = 0;
    for (IndexQueueEntry batchEntry = queueEntry; batchEntry != null; batchEntry = this.indexQueue.poll()) {
        if (batchEntry == INDEX_QUEUE_ENTRY_STOP) {
            // Discard the current batch and stop the indexing thread.
            return false;
        }
        IndexOperation operation = batchEntry.operation;
        // For the current contiguous operations queue, group the changes
        try {
            this.ecim.initialize(new ExecutionContext());
            if (IndexOperation.INDEX.equals(operation)) {
                LengthSolrInputDocument solrDocument = getSolrDocument(batchEntry.reference);
                if (solrDocument != null) {
                    solrInstance.add(solrDocument);
                    length += solrDocument.getLength();
                    ++this.batchSize;
                }
            } else if (IndexOperation.DELETE.equals(operation)) {
                if (batchEntry.reference == null) {
                    solrInstance.deleteByQuery(batchEntry.deleteQuery);
                } else {
                    solrInstance.delete(this.solrRefereceResolver.getId(batchEntry.reference));
                }
                ++this.batchSize;
            }
        } catch (Throwable e) {
            this.logger.error("Failed to process entry [{}]", batchEntry, e);
        } finally {
            this.execution.removeContext();
        }
        // the reason why we perform it at the end of the batch.
        if (shouldCommit(length, this.batchSize)) {
            commit();
            length = 0;
        }
    }
    // Commit what's left
    if (this.batchSize > 0) {
        commit();
    }
    return true;
}
Also used : LengthSolrInputDocument(org.xwiki.search.solr.internal.metadata.LengthSolrInputDocument) ExecutionContext(org.xwiki.context.ExecutionContext) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance)

Aggregations

ExecutionContext (org.xwiki.context.ExecutionContext)1 SolrInstance (org.xwiki.search.solr.internal.api.SolrInstance)1 LengthSolrInputDocument (org.xwiki.search.solr.internal.metadata.LengthSolrInputDocument)1