Search in sources :

Example 1 with SolrInstance

use of org.xwiki.search.solr.internal.api.SolrInstance 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)

Example 2 with SolrInstance

use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.

the class SolrDocumentIteratorTest method configure.

@Before
public void configure() throws Exception {
    solr = mock(SolrInstance.class);
    Provider<SolrInstance> solrInstanceProvider = mocker.registerMockComponent(new DefaultParameterizedType(null, Provider.class, SolrInstance.class));
    when(solrInstanceProvider.get()).thenReturn(solr);
    this.solrDocumentReferenceResolver = this.mocker.getInstance(new DefaultParameterizedType(null, DocumentReferenceResolver.class, SolrDocument.class));
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance) Provider(javax.inject.Provider) Before(org.junit.Before)

Example 3 with SolrInstance

use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.

the class SolrQueryExecutorTest method configure.

@Before
public void configure() throws Exception {
    ParameterizedType solrProviderType = new DefaultParameterizedType(null, Provider.class, SolrInstance.class);
    Provider<SolrInstance> provider = this.componentManager.registerMockComponent(solrProviderType);
    when(provider.get()).thenReturn(this.solr);
}
Also used : DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) ParameterizedType(java.lang.reflect.ParameterizedType) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance) Before(org.junit.Before)

Example 4 with SolrInstance

use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.

the class EmbeddedSolrInstanceInitializationTest method getInstanceAndAssertHomeDirectory.

/**
 * TODO DOCUMENT ME!
 *
 * @param expected
 * @throws ComponentLookupException
 * @throws Exception
 */
private void getInstanceAndAssertHomeDirectory(String expected) throws ComponentLookupException, Exception {
    SolrInstance instance = mocker.getInstance(SolrInstance.class, "embedded");
    Assert.assertNotNull(instance);
    EmbeddedSolrInstance implementation = ((EmbeddedSolrInstance) instance);
    CoreContainer container = implementation.getContainer();
    if (expected == null) {
        expected = implementation.getDefaultHomeDirectory();
    }
    Assert.assertEquals(expected, container.getSolrHome());
    Assert.assertEquals(1, container.getCores().size());
    SolrCore core = container.getCores().iterator().next();
    File coreBaseDirectory = new File(container.getSolrHome(), core.getName());
    File configDirectory = new File(coreBaseDirectory, DefaultSolrConfiguration.CONF_DIRECTORY);
    Assert.assertTrue(new File(configDirectory, core.getSchemaResource()).exists());
    Assert.assertTrue(new File(configDirectory, core.getConfigResource()).exists());
}
Also used : CoreContainer(org.apache.solr.core.CoreContainer) SolrCore(org.apache.solr.core.SolrCore) File(java.io.File) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance)

Example 5 with SolrInstance

use of org.xwiki.search.solr.internal.api.SolrInstance in project xwiki-platform by xwiki.

the class SolrInstanceProviderTest method testEmbeddedInstanceRetrieval.

@Test
public void testEmbeddedInstanceRetrieval() throws Exception {
    when(this.mockConfig.getServerType()).thenReturn("embedded");
    SolrInstance instance = this.mocker.getComponentUnderTest().get();
    Assert.assertNotNull(instance);
    Assert.assertSame(this.embedded, instance);
}
Also used : SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance) Test(org.junit.Test)

Aggregations

SolrInstance (org.xwiki.search.solr.internal.api.SolrInstance)8 Before (org.junit.Before)2 Test (org.junit.Test)2 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)2 File (java.io.File)1 ParameterizedType (java.lang.reflect.ParameterizedType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Provider (javax.inject.Provider)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocumentList (org.apache.solr.common.SolrDocumentList)1 CoreContainer (org.apache.solr.core.CoreContainer)1 SolrCore (org.apache.solr.core.SolrCore)1 ComponentLifecycleException (org.xwiki.component.manager.ComponentLifecycleException)1 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)1 InitializationException (org.xwiki.component.phase.InitializationException)1 ExecutionContext (org.xwiki.context.ExecutionContext)1 ExecutionContextException (org.xwiki.context.ExecutionContextException)1 JobException (org.xwiki.job.JobException)1