Example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer

List of usage examples for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.embedded EmbeddedSolrServer EmbeddedSolrServer.

Prototype

public EmbeddedSolrServer(CoreContainer coreContainer, String coreName) 

Source Link

Document

Create an EmbeddedSolrServer wrapping a CoreContainer.

Usage

From source file:com.hurence.logisland.service.solr.SolrRule.java

License:Apache License

@Override
protected void before() throws Throwable {

    String base = getClass().getResource("/solr/").getPath();

    FileUtils.deleteDirectory(new File(base + "chronix/data"));
    container = new CoreContainer(base);
    container.load();/*from  w  w  w. java  2 s.co  m*/

    server = new EmbeddedSolrServer(container, "chronix");

    getClient().deleteByQuery("*:*");
    getClient().commit();
}

From source file:com.indoqa.solr.server.factory.EmbeddedSolrServerBuilder.java

License:Apache License

public static SolrServer build(String url, String embeddedSolrConfigurationDir) throws IOException {
    String solrHome = getNormalizedPath(embeddedSolrConfigurationDir);

    InputStream solrXmlInputStream = EmbeddedSolrServerBuilder.class
            .getResourceAsStream("/embedded-core-container/solr.xml");

    SolrResourceLoader loader = new SolrResourceLoader(solrHome);
    ConfigSolr configSolr = ConfigSolr.fromInputStream(loader, solrXmlInputStream);

    solrXmlInputStream.close();// w ww  .j ava  2s . co m

    CoreContainer container = new CoreContainer(loader, configSolr);
    container.load();

    String dataDir = getNormalizedPath(getDataDir(url));
    CoreDescriptor coreDescriptor = new CoreDescriptor(container, "Embedded Core", solrHome, CORE_DATADIR,
            dataDir);
    SolrCore core = container.create(coreDescriptor);

    return new EmbeddedSolrServer(container, core.getName());
}

From source file:com.lyncode.oai.proxy.core.SolrServerManager.java

License:Apache License

public static void initialize() {
    if (server == null) {
        String config = ConfigurationManager.getConfiguration().getString("solr.home");
        System.setProperty("solr.solr.home", config);
        System.setProperty("solr.data.dir", config + File.separator + "data");
        CoreContainer.Initializer initializer = new CoreContainer.Initializer();
        CoreContainer coreContainer;//from  w w  w  . ja  va2  s.  c o m
        try {
            coreContainer = initializer.initialize();
            server = new EmbeddedSolrServer(coreContainer, "");

            try {
                server.query(new SolrQuery("*:*"));
                log.info("Solr Server initialized");
            } catch (SolrServerException e) {
                log.error(e.getMessage(), e);
            }
        } catch (IOException e1) {
            log.error(e1.getMessage(), e1);
        } catch (ParserConfigurationException e1) {
            log.error(e1.getMessage(), e1);
        } catch (SAXException e1) {
            log.error(e1.getMessage(), e1);
        }
    }
}

From source file:com.mycompany.sparkrentals.client.RentalSolrClientTest.java

@Before
public void setUp() throws IOException, SolrServerException {
    File resourceDir = new File("src/test/resources/solr");
    //use a temporary folder for solr home
    FileUtils.copyDirectory(resourceDir, tempSolrHome.getRoot());
    CoreContainer coreContainer = new CoreContainer(tempSolrHome.getRoot().getAbsolutePath());
    coreContainer.load();/*from  w w w  . ja va  2s.c  o  m*/
    server = new EmbeddedSolrServer(coreContainer, "new_core");

    //populate initial data
    List<Rental> rentals = new ArrayList<>();
    rentals.add(new Rental("A1234", "city1", "province2", "country2", "fjkso", "Villa", true, true, true, true,
            10f, "$", 1, new Date()));
    rentals.add(new Rental("A2234", "city2", "province2", "country9", "dfsdd", "studio", true, false, true,
            true, 11f, "$", 2, new Date()));
    rentals.add(new Rental("A3234", "city3", "province5", "country1", "e9r3e", "studio", false, true, false,
            true, 7.2f, "$", 3, new Date()));
    Date threeDaysAgo = new Date(new Date().getTime() - 3 * 24 * 3600 * 1000);
    rentals.add(new Rental("A4234", "city4", "province7", "country6", "ghree", "Single Floor", true, false,
            true, true, 8f, "$", 2, threeDaysAgo));

    for (Rental rental : rentals) {
        server.addBean(rental);
        server.commit();
    }

    client = new RentalSolrClient();
    client.setSolrClient(server);
}

From source file:com.ngdata.hbaseindexer.mr.TestUtils.java

License:Apache License

private static EmbeddedSolrServer createEmbeddedSolrServer(File solrHomeDir, FileSystem fs, Path outputShardDir)
        throws IOException {

    LOG.info("Creating embedded Solr server with solrHomeDir: " + solrHomeDir + ", fs: " + fs
            + ", outputShardDir: " + outputShardDir);

    // copy solrHomeDir to ensure it isn't modified across multiple unit tests or multiple EmbeddedSolrServer instances
    File tmpDir = Files.createTempDir();
    tmpDir.deleteOnExit();/*from  w w  w .  jav  a  2s  .c om*/
    FileUtils.copyDirectory(solrHomeDir, tmpDir);
    solrHomeDir = tmpDir;

    Path solrDataDir = new Path(outputShardDir, "data");

    String dataDirStr = solrDataDir.toUri().toString();

    SolrResourceLoader loader = new SolrResourceLoader(Paths.get(solrHomeDir.toString()), null, null);

    LOG.info(String.format(Locale.ENGLISH,
            "Constructed instance information solr.home %s (%s), instance dir %s, conf dir %s, writing index to solr.data.dir %s, with permdir %s",
            solrHomeDir, solrHomeDir.toURI(), loader.getInstancePath(), loader.getConfigDir(), dataDirStr,
            outputShardDir));

    // TODO: This is fragile and should be well documented
    System.setProperty("solr.directoryFactory", HdfsDirectoryFactory.class.getName());
    System.setProperty("solr.lock.type", DirectoryFactory.LOCK_TYPE_HDFS);
    System.setProperty("solr.hdfs.nrtcachingdirectory", "false");
    System.setProperty("solr.hdfs.blockcache.enabled", "false");
    System.setProperty("solr.autoCommit.maxTime", "600000");
    System.setProperty("solr.autoSoftCommit.maxTime", "-1");

    CoreContainer container = new CoreContainer(loader);
    container.load();

    SolrCore core = container.create("core1", Paths.get(solrHomeDir.toString()),
            ImmutableMap.of(CoreDescriptor.CORE_DATADIR, dataDirStr), false);

    if (!(core.getDirectoryFactory() instanceof HdfsDirectoryFactory)) {
        throw new UnsupportedOperationException(
                "Invalid configuration. Currently, the only DirectoryFactory supported is "
                        + HdfsDirectoryFactory.class.getSimpleName());
    }

    EmbeddedSolrServer solr = new EmbeddedSolrServer(container, "core1");
    return solr;
}

From source file:com.nominanuda.solr.SingletonSolrAware.java

License:Apache License

public synchronized EmbeddedSolrServer getEmbeddedSolrServerByCoreName(String coreName) {
    EmbeddedSolrServer server = serverMap.get(coreName);
    if (server == null) {
        if (coreContainer.getCoreNames().contains(coreName)) {
            server = new EmbeddedSolrServer(coreContainer, coreName);
            serverMap.put(coreName, server);
        } else {/*from   www.j a v  a2s .  co  m*/
            throw new IllegalArgumentException(coreName + " not found");
        }
    }
    return server;
}

From source file:com.norconex.committer.solr.SolrCommitterTest.java

License:Apache License

@Before
public void setup() throws Exception {

    File solrHome = tempFolder.newFolder("solr");
    initCore("src/test/resources/solrconfig.xml", "src/test/resources/schema.xml", solrHome.toString());

    server = new EmbeddedSolrServer(h.getCoreContainer(), h.getCore().getName());

    committer = new SolrCommitter(new ISolrServerFactory() {
        private static final long serialVersionUID = 4648990433469043210L;

        @Override//www . ja v a 2  s.  co  m
        public SolrServer createSolrServer(SolrCommitter solrCommitter) {
            return server;
        }
    });

    queue = tempFolder.newFolder("queue");
    committer.setQueueDir(queue.toString());
}

From source file:com.searchbox.engine.solr.EmbeddedSolr.java

License:Apache License

@Override
protected SolrServer getSolrServer(Collection collection) {
    return new EmbeddedSolrServer(coreContainer, collection.getName());
}

From source file:com.sindicetech.siren.solr.SolrServerWrapper.java

License:Open Source License

public SolrServerWrapper(final CoreContainer coreContainer) {
    this.coreContainer = coreContainer;
    server = new EmbeddedSolrServer(coreContainer, "");
}

From source file:com.temenos.interaction.commands.solr.AbstractSolrTest.java

License:Open Source License

@Before
public void setUp() throws Exception {
    System.setProperty("solr.solr.home", getSolrHome());

    // Just initialise the core used for sharding without any data
    TestHarness shardingTestHarness = initSolrCore(COMPANY_NAME + "/" + SOLR_CORE_FOR_SHARD);
    shardCoreSolrServer = new EmbeddedSolrServer(shardingTestHarness.getCoreContainer(),
            shardingTestHarness.getCore().getName());

    // Populate Entity1 Solr core
    TestHarness entity1TestHarness = initSolrCore(COMPANY_NAME + "/" + ENTITY1_TYPE);
    entity1SolrServer = new EmbeddedSolrServer(entity1TestHarness.getCoreContainer(),
            entity1TestHarness.getCore().getName());
    initEntity1TestData();//from w ww .  java2  s  . c o m

    // Populate Entity2 Solr core
    TestHarness entity2TestHarness = initSolrCore(COMPANY_NAME + "/" + ENTITY2_TYPE);
    entity2SolrServer = new EmbeddedSolrServer(entity2TestHarness.getCoreContainer(),
            entity2TestHarness.getCore().getName());

    initEntity2TestData();
}