Search in sources :

Example 6 with SolrInstance

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

the class SolrInstanceProviderTest method testRemoteInstanceRetrieval.

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

Example 7 with SolrInstance

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

the class DefaultSolrIndexer method commit.

/**
 * Commit.
 */
private void commit() {
    SolrInstance solrInstance = this.solrInstanceProvider.get();
    try {
        solrInstance.commit();
    } catch (Exception e) {
        this.logger.error("Failed to commit index changes to the Solr server. Rolling back.", e);
        try {
            solrInstance.rollback();
        } catch (Exception ex) {
            // Just log the failure.
            this.logger.error("Failed to rollback index changes.", ex);
        }
    }
    this.batchSize = 0;
}
Also used : ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) ComponentLifecycleException(org.xwiki.component.manager.ComponentLifecycleException) InitializationException(org.xwiki.component.phase.InitializationException) SolrIndexerException(org.xwiki.search.solr.internal.api.SolrIndexerException) JobException(org.xwiki.job.JobException) ExecutionContextException(org.xwiki.context.ExecutionContextException) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance)

Example 8 with SolrInstance

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

the class SolrQueryExecutor method execute.

@Override
public <T> List<T> execute(Query query) throws QueryException {
    this.progress.startStep(query, "query.solr.progress.execute", "Execute Solr query [{}]", query);
    this.progress.pushLevelProgress(3, query);
    try {
        this.progress.startStep(query, "query.solr.progress.execute.prepare", "Prepare");
        SolrInstance solrInstance = solrInstanceProvider.get();
        SolrQuery solrQuery = createSolrQuery(query);
        this.progress.startStep(query, "query.solr.progress.execute.execute", "Execute");
        QueryResponse response = solrInstance.query(solrQuery);
        this.progress.startStep(query, "query.solr.progress.execute.filter", "Filter");
        // Check access rights need to be checked before returning the response.
        // FIXME: this is not really the best way, mostly because at this point all grouping operations
        // have already been performed and any change on the result will not ensure that the grouping
        // information (facets, highlighting, maxScore, etc.) is still relevant.
        // A better way would be using a PostFilter as described in this article:
        // http://java.dzone.com/articles/custom-security-filtering-solr
        // Basically, we would be asking
        List<DocumentReference> usersToCheck = new ArrayList<>(2);
        if (query instanceof SecureQuery) {
            if (((SecureQuery) query).isCurrentUserChecked()) {
                usersToCheck.add(xcontextProvider.get().getUserReference());
            }
            if (((SecureQuery) query).isCurrentAuthorChecked()) {
                usersToCheck.add(xcontextProvider.get().getAuthorReference());
            }
        } else {
            usersToCheck.add(xcontextProvider.get().getUserReference());
            usersToCheck.add(xcontextProvider.get().getAuthorReference());
        }
        if (!usersToCheck.isEmpty()) {
            filterResponse(response, usersToCheck);
        }
        return (List<T>) Arrays.asList(response);
    } catch (Exception e) {
        throw new QueryException("Exception while executing query", query, e);
    } finally {
        this.progress.popLevelProgress(query);
        this.progress.endStep(query);
    }
}
Also used : QueryException(org.xwiki.query.QueryException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) ArrayList(java.util.ArrayList) SolrDocumentList(org.apache.solr.common.SolrDocumentList) ArrayList(java.util.ArrayList) List(java.util.List) SecureQuery(org.xwiki.query.SecureQuery) SolrQuery(org.apache.solr.client.solrj.SolrQuery) DocumentReference(org.xwiki.model.reference.DocumentReference) QueryException(org.xwiki.query.QueryException) SolrInstance(org.xwiki.search.solr.internal.api.SolrInstance)

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