Example usage for org.apache.solr.core SolrResourceLoader locateSolrHome

List of usage examples for org.apache.solr.core SolrResourceLoader locateSolrHome

Introduction

In this page you can find the example usage for org.apache.solr.core SolrResourceLoader locateSolrHome.

Prototype

public static Path locateSolrHome() 

Source Link

Document

Finds the solrhome based on looking up the value in one of three places:
  1. JNDI: via java:comp/env/solr/home
  2. The system property solr.solr.home
  3. Look in the current working directory for a solr/ directory

The return value is normalized.

Usage

From source file:com.github.bibreen.mecab_ko_lucene_analyzer.StandardIndexTokenizerFactory.java

License:Apache License

private void setMeCabDicDir(Map<String, String> args) {
    String path = get(args, "mecabDicDir", StandardIndexTokenizerFactory.DEFAULT_MECAB_DIC_DIR);
    if (path != null) {
        if (path.startsWith("/")) {
            mecabDicDir = path;//from  w  w  w.  ja v  a2  s.  co m
        } else {
            mecabDicDir = SolrResourceLoader.locateSolrHome() + path;
        }
    }
}

From source file:com.googlecode.solrgeonames.harvester.Harvester.java

License:Open Source License

/**
 * Start up an embedded Solr server.//from www  .  jav  a2  s  .c  o m
 *
 * @param home: The path to the Solr home directory
 * @return EmbeddedSolrServer: The instantiated server
 * @throws Exception if any errors occur
 */
private EmbeddedSolrServer startSolr(String home) throws Exception {
    try {
        SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null);
        IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null);

        solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
                solrConfig.getResourceLoader().getInstanceDir());
        descriptor.setConfigName(solrConfig.getResourceName());
        descriptor.setSchemaName(schema.getResourceName());

        solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor);
        solrContainer.register("", solrCore, false);
        return new EmbeddedSolrServer(solrContainer, "");
    } catch (Exception ex) {
        log.error("\nFailed to start Solr server\n");
        throw ex;
    }
}

From source file:com.googlecode.solrgeonames.server.GeoContextListener.java

License:Open Source License

/**
 * Start up an embedded Solr server.//  w  w w  .  j  a  v  a2  s  . c  o  m
 *
 * @param home: The path to the Solr home directory
 * @return EmbeddedSolrServer: The instantiated server
 * @throws Exception if any errors occur
 */
private EmbeddedSolrServer startSolr(String home) throws Exception {
    SolrConfig solrConfig = new SolrConfig(home, SOLR_CONFIG, null);
    IndexSchema schema = new IndexSchema(solrConfig, SOLR_SCHEMA, null);

    solrContainer = new CoreContainer(new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
    CoreDescriptor descriptor = new CoreDescriptor(solrContainer, "",
            solrConfig.getResourceLoader().getInstanceDir());
    descriptor.setConfigName(solrConfig.getResourceName());
    descriptor.setSchemaName(schema.getResourceName());

    SolrCore solrCore = new SolrCore(null, solrConfig.getDataDir(), solrConfig, schema, descriptor);
    solrContainer.register("", solrCore, false);
    return new EmbeddedSolrServer(solrContainer, "");
}

From source file:jp.aegif.nemaki.util.impl.PropertyManagerImpl.java

License:Open Source License

/**
 * Override is not supported for update/*  w  ww . j a  v a  2s  . c  o  m*/
 */
@Override
public void modifyValue(String key, String value) {
    config.setProperty(key, value);

    SolrResourceLoader loader = new SolrResourceLoader(null);
    ClassLoader classLoader = loader.getClassLoader();
    URL url = classLoader.getResource(propertiesFile);

    try {
        if (url == null) {
            config.store(new FileOutputStream(new File(loader.locateSolrHome() + "/conf/" + propertiesFile)),
                    null);
        } else {
            config.store(new FileOutputStream(new File(url.toURI())), null);
        }
    } catch (Exception e) {
        logger.error("Error occurred during modification of porperty value.", e);
    }

}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_updateAndSuggest() {
    try {/*  ww w.ja  v a  2  s . com*/
        final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();
        suggestSolrServer.deleteAll();
        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, false),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.start();

        final SolrInputDocument doc = new SolrInputDocument();
        doc.setField("content",
                "Fess ?5 ?????????Java ????? OS ????Fess ? Apache ????? () ????????\n"
                        + "\n"
                        + "Seasar2 ????? 2 ??? Solr ????? ?? S2Robot ?????Web ???????MS Office ? zip ?????????????");
        doc.setField(config.getExpiresField(), DateUtil.getThreadLocalDateFormat().format(new Date()));
        controller.add(doc);
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertTrue(suggestSolrServer.select("*:*").getNumFound() > 10);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":jav*")
                .getNumFound() > 0);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":kensakuenjinn*")
                .getNumFound() > 0);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":inde*")
                .getNumFound() > 0);

        //suggest check
        final Suggester suggester = new Suggester();
        suggester.setNormalizer(TestUtils.createNormalizer());
        suggester.setConverter(TestUtils.createConverter());

        String q = suggester.buildSuggestQuery("jav", Arrays.asList(new String[] { "content" }), null, null);
        assertTrue(suggestSolrServer.select(q).getNumFound() > 0);
        q = suggester.buildSuggestQuery("kensakuenj", Arrays.asList(new String[] { "content" }), null, null);
        assertTrue(suggestSolrServer.select(q).getNumFound() > 0);
        q = suggester.buildSuggestQuery("inde", Arrays.asList(new String[] { "content" }), null, null);
        assertTrue(suggestSolrServer.select(q).getNumFound() > 0);

    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_update_multifield() {
    final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();

    try {/*w  w  w . j a  v a2s .  com*/
        suggestSolrServer.deleteAll();

        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, true),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.start();
        final SolrInputDocument doc = new SolrInputDocument();
        doc.setField("content",
                "Fess ?5 ?????????Java ????? OS ????Fess ? Apache ????? () ????????\n"
                        + "\n"
                        + "Seasar2 ????? 2 ??? Solr ????? ?? S2Robot ?????Web ???????MS Office ? zip ?????????????");
        doc.setField("title", "Fess?????page");
        doc.setField(config.getExpiresField(), DateUtil.getThreadLocalDateFormat().format(new Date()));
        controller.add(doc);
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertTrue(suggestSolrServer.select("*:*").getNumFound() > 10);
        assertEquals(1,
                suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":jav*").getNumFound());
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":kensakuenjinn*")
                .getNumFound() > 0);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":inde*")
                .getNumFound() > 0);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":fessnituitenose*")
                .getNumFound() > 0);

        //suggester check
        final Suggester suggester = new Suggester();
        suggester.setNormalizer(TestUtils.createNormalizer());
        suggester.setConverter(TestUtils.createConverter());

        String q = suggester.buildSuggestQuery("fessnituitenosetumei", Arrays.asList(new String[] { "title" }),
                null, null);
        assertEquals(1, suggestSolrServer.select(q).getNumFound());
        q = suggester.buildSuggestQuery("fessnituitenosetumei", Arrays.asList(new String[] { "content" }), null,
                null);
        assertEquals(0, suggestSolrServer.select(q).getNumFound());
    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_ttl_delete() {
    final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();

    try {/*  w w  w. j a  v  a 2  s.c o m*/
        suggestSolrServer.deleteAll();

        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, false),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.start();

        final String prevDate = DateUtil.getThreadLocalDateFormat().format(new Date());

        final SolrInputDocument doc = new SolrInputDocument();
        doc.setField("content", "?");
        doc.setField(config.getExpiresField(), prevDate);
        controller.add(doc);
        controller.commit();
        Thread.sleep(5 * 1000);
        assertTrue(suggestSolrServer.select("*:*").getNumFound() == 1);
        final SolrInputDocument doc2 = new SolrInputDocument();
        doc2.setField("content", "??");
        doc2.setField(config.getExpiresField(), DateUtil.getThreadLocalDateFormat().format(new Date()));
        controller.add(doc2);
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertEquals(2, suggestSolrServer.select("*:*").getNumFound());
        assertEquals(1,
                suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":mikan").getNumFound());
        assertEquals(1,
                suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":rinngo").getNumFound());

        controller.deleteByQuery(config.getExpiresField() + ":[* TO " + prevDate + "] NOT segment:hogehoge");
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertEquals(1, suggestSolrServer.select("*:*").getNumFound());
        assertEquals(1,
                suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":mikan").getNumFound());
        assertEquals(0,
                suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":rinngo").getNumFound());

    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_segment_delete() {
    final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();

    try {//from  w  w w .  j av a  2  s.  com
        suggestSolrServer.deleteAll();

        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, false),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.start();

        final SolrInputDocument doc = new SolrInputDocument();
        doc.setField("content", "?");
        doc.setField(config.getSegmentField(), "1000");
        controller.add(doc);
        controller.commit();
        Thread.sleep(5 * 1000);
        assertTrue(suggestSolrServer.select("*:*").getNumFound() == 1);
        final SolrInputDocument doc2 = new SolrInputDocument();
        doc2.setField("content", "??");
        doc2.setField(config.getSegmentField(), "2000");
        controller.add(doc2);
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertTrue(suggestSolrServer.select("*:*").getNumFound() == 2);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":mikan")
                .getNumFound() == 1);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":ringo")
                .getNumFound() == 1);

        controller.deleteByQuery(config.getSegmentField() + ":1000");
        controller.commit();
        Thread.sleep(5 * 1000);

        //assert
        assertTrue(suggestSolrServer.select("*:*").getNumFound() == 1);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":mikan")
                .getNumFound() == 1);
        assertTrue(suggestSolrServer.select(SuggestConstants.SuggestFieldNames.READING + ":ringo")
                .getNumFound() == 0);

    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_incrementUpdate() {
    final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();

    try {/*w w w.j  av  a2s .c o m*/
        suggestSolrServer.deleteAll();
        suggestSolrServer.commit();

        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, false),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.addLabelFieldName("label");
        controller.addRoleFieldName("role");
        controller.start();

        final SolrInputDocument doc = new SolrInputDocument();
        for (int i = 0; i < 5; i++) {
            doc.setField("content", "??");
            doc.setField("label", "label" + i);
            doc.setField("role", "role" + i);
            doc.setField(config.getExpiresField(), DateUtil.getThreadLocalDateFormat().format(new Date()));
            controller.add(doc);
            Thread.sleep(5 * 1000);
        }
        controller.commit();
        Thread.sleep(5 * 1000);
        final SolrDocumentList solrDocuments = suggestSolrServer.select("*:*");
        assertEquals(1, solrDocuments.getNumFound());
        final SolrDocument solrDocument = solrDocuments.get(0);
        final Object count = solrDocument.getFieldValue(SuggestConstants.SuggestFieldNames.COUNT);
        assertEquals("5", count.toString());
        final Collection<Object> labels = solrDocument
                .getFieldValues(SuggestConstants.SuggestFieldNames.LABELS);
        assertEquals(5, labels.size());
        for (int i = 0; i < 5; i++) {
            assertTrue(labels.contains("label" + i));
        }
        final Collection<Object> roles = solrDocument.getFieldValues(SuggestConstants.SuggestFieldNames.ROLES);
        assertEquals(5, roles.size());
        for (int i = 0; i < 5; i++) {
            assertTrue(roles.contains("role" + i));
        }
    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:jp.sf.fess.solr.plugin.suggest.SuggestUpdateControllerTest.java

License:Apache License

public void test_UpdateFromTransactionLog() {
    final SuggestSolrServer suggestSolrServer = TestUtils.createSuggestSolrServer();

    try {//from ww w . ja  v a2s  .  c  o  m
        suggestSolrServer.deleteAll();
        suggestSolrServer.commit();

        final SuggestUpdateConfig config = TestUtils.getSuggestUpdateConfig();
        final SuggestUpdateController controller = new SuggestUpdateController(config,
                getSuggestFieldInfoList(config, false),
                new SolrResourceLoader(SolrResourceLoader.locateSolrHome()));
        controller.addLabelFieldName("label");
        controller.start();

        final File classPath = new File(this.getClass().getClassLoader().getResource("").getPath());
        final File file = new File(classPath, "tlog.0000000000000000059");
        controller.addTransactionLog(file);

        Thread.sleep(10 * 1000);
        assertTrue(suggestSolrServer.select("*:*").getNumFound() > 100);
        assertTrue(suggestSolrServer.select("reading_s_m:kensa*").getNumFound() > 0);

        controller.close();
    } catch (final Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}