Search in sources :

Example 41 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project stanbol by apache.

the class SolrYardTest method initYard.

@BeforeClass
public static final void initYard() throws YardException, IOException {
    // get the working directory
    // use property substitution to test this feature!
    String prefix = System.getProperty("basedir") == null ? "." : "${basedir}";
    String solrServerDir = prefix + TEST_INDEX_REL_PATH;
    log.info("Test Solr Server Directory: " + solrServerDir);
    SolrYardConfig config = new SolrYardConfig(TEST_YARD_ID, TEST_SOLR_CORE_NAME);
    config.setName("Solr Yard Test");
    config.setDescription("The Solr Yard instance used to execute the Unit Tests defined for the Yard Interface");
    config.setAllowInitialisation(true);
    //for unit testing we want immidiate commits (required after STANBOL-1092
    // as the default changed to false)
    config.setImmediateCommit(true);
    //init the ManagedSolrServer used for the UnitTest
    System.setProperty(ManagedSolrServer.MANAGED_SOLR_DIR_PROPERTY, solrServerDir);
    IndexReference solrServerRef = IndexReference.parse(config.getSolrServerLocation());
    solrServerProvider = StandaloneEmbeddedSolrServerProvider.getInstance();
    SolrServer server = solrServerProvider.getSolrServer(solrServerRef, config.isAllowInitialisation() ? config.getIndexConfigurationName() : null);
    //Optional support for the nsPrefix service
    final NamespacePrefixService nsPrefixService;
    ServiceLoader<NamespacePrefixService> spsl = ServiceLoader.load(NamespacePrefixService.class);
    Iterator<NamespacePrefixService> it = spsl.iterator();
    if (it.hasNext()) {
        nsPrefixService = it.next();
    } else {
        nsPrefixService = null;
    }
    yard = new SolrYard(server, config, nsPrefixService);
}
Also used : NamespacePrefixService(org.apache.stanbol.commons.namespaceprefix.NamespacePrefixService) IndexReference(org.apache.stanbol.commons.solr.IndexReference) StandaloneManagedSolrServer(org.apache.stanbol.commons.solr.managed.standalone.StandaloneManagedSolrServer) ManagedSolrServer(org.apache.stanbol.commons.solr.managed.ManagedSolrServer) SolrServer(org.apache.solr.client.solrj.SolrServer) SolrYard(org.apache.stanbol.entityhub.yard.solr.impl.SolrYard) SolrYardConfig(org.apache.stanbol.entityhub.yard.solr.impl.SolrYardConfig) BeforeClass(org.junit.BeforeClass)

Example 42 with SolrServer

use of org.apache.solr.client.solrj.SolrServer in project apex-malhar by apache.

the class AbstractSolrInputOperator method emitTuples.

@Override
public void emitTuples() {
    SolrParams solrQueryParams = getQueryParams();
    try {
        SolrServer solrServer = solrServerConnector.getSolrServer();
        QueryResponse response = solrServer.query(solrQueryParams);
        SolrDocumentList queriedDocuments = response.getResults();
        for (SolrDocument solrDocument : queriedDocuments) {
            emitTuple(solrDocument);
            lastEmittedTuple = solrDocument;
            lastEmittedTimeStamp = System.currentTimeMillis();
            logger.debug("Emiting document: " + solrDocument.getFieldValue("name"));
        }
    } catch (SolrServerException ex) {
        throw new RuntimeException("Unable to fetch documents from Solr server", ex);
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrParams(org.apache.solr.common.params.SolrParams) SolrDocumentList(org.apache.solr.common.SolrDocumentList) SolrServer(org.apache.solr.client.solrj.SolrServer)

Aggregations

SolrServer (org.apache.solr.client.solrj.SolrServer)42 ManagedSolrServer (org.apache.stanbol.commons.solr.managed.ManagedSolrServer)21 SolrServerException (org.apache.solr.client.solrj.SolrServerException)20 EmbeddedSolrServer (org.apache.solr.client.solrj.embedded.EmbeddedSolrServer)17 IOException (java.io.IOException)13 ClassifierException (org.apache.stanbol.enhancer.topic.api.ClassifierException)13 SolrQuery (org.apache.solr.client.solrj.SolrQuery)12 SolrDocument (org.apache.solr.common.SolrDocument)11 ConfigurationException (org.osgi.service.cm.ConfigurationException)11 TrainingSetException (org.apache.stanbol.enhancer.topic.api.training.TrainingSetException)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)9 OakSolrConfiguration (org.apache.jackrabbit.oak.plugins.index.solr.configuration.OakSolrConfiguration)8 ArrayList (java.util.ArrayList)7 ChainException (org.apache.stanbol.enhancer.servicesapi.ChainException)7 EngineException (org.apache.stanbol.enhancer.servicesapi.EngineException)7 InvalidContentException (org.apache.stanbol.enhancer.servicesapi.InvalidContentException)7 EntityhubException (org.apache.stanbol.entityhub.servicesapi.EntityhubException)7 SolrInputDocument (org.apache.solr.common.SolrInputDocument)6 Test (org.junit.Test)6