2

I have a spring boot application where I am embedding a solr server. I seem to be forced right now to name my solr core as "collection1" so that my code indeed finds the core to load

anyone know how I can make this arbitrary ?

@Configuration
@EnableSolrRepositories(basePackages = ["uk.xxx"], multicoreSupport = true)
class SolrContext {

    static final String SOLR_HOST = 'solr.host'
    static final String SOLR_EMBEDDED_PATH = 'solr.embedded.path'


    @Resource
    Environment environment

    @Bean
    public SolrServer solrServer() {
        EmbeddedSolrServerFactory factory = new EmbeddedSolrServerFactory(environment.getRequiredProperty(SOLR_EMBEDDED_PATH))
        return factory.getSolrServer()
    }

    @Bean
    public SolrOperations solrTemplate() {
        return new SolrTemplate(solrServer())
    }

}

tried like you said, still no good, I named my core 'coursefinder', and passed that in like you said but its still looking for colelction1 :

@Bean
public SolrServer solrServer() {
        println "starting embedded solr index"
        EmbeddedSolrServerFactory factory = new EmbeddedSolrServerFactory(grailsApplication.config.getProperty('solr.embedded.path'))
        return factory.getSolrServer("coursefinder")

    }
}

output

starting embedded solr index
ERROR org.apache.solr.core.CoreContainer - Error creating core [collection1]: Could not load conf for core collection1: Error loading solr config from /Developer/dev/LSE/coursefinder-grails-angular/embeddedsolr/collection1/conf/solrconfig.xml
org.apache.solr.common.SolrException: Could not load conf for core collection1: Error loading solr config from /Developer/dev/LSE/coursefinder-grails-angular/embeddedsolr/collection1/conf/solrconfig.xml
    at org.apache.solr.core.ConfigSetService.getConfig(ConfigSetService.java:66)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:489)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:255)
    at org.apache.solr.core.CoreContainer$1.call(CoreContainer.java:249)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)`
freedev
  • 25,946
  • 8
  • 108
  • 125
1977
  • 2,580
  • 6
  • 26
  • 37
  • How are you creating the core? You can set it's name to whatever you want while creating the core. – Binoy Dalal Mar 17 '16 at 06:33
  • I copied the collection1 core int he examples directory and then I renamed it. I also changed the name in the core.properties file. However, EmbeddedSolrServerFactory seems to lookup 'collection1' by default – 1977 Mar 17 '16 at 14:03

3 Answers3

0

Change return factory.getSolrServer() to return factory.getSolrServer("yourcorename")

Binoy Dalal
  • 866
  • 10
  • 25
0

I tried all many posted solution, the only thing which is working for solr 5.x is the following.

Be aware that you have a core.properties beneath the home folder which has the same name inside.

Best way is to build a core with solr create and use that structure as home folder.

Following is for Spring based jUnit testing

@Bean
public EmbeddedSolrServer solrServerFactoryBean() {
    String folder = "src/main/resources/server/solr/";
    CoreContainer container = new CoreContainer(folder);
    container.load();
    return new EmbeddedSolrServer(container, "myName");

}

@Bean
public SolrTemplate solrTemplate(EmbeddedSolrServer server) throws Exception {
    SolrTemplate solrTemplate = new SolrTemplate(server);
    return solrTemplate;
}
beagle
  • 137
  • 1
  • 12
0

Not sure how to do this using spring boot but I wrote an example that helps to load multiple instances of EmbeddedSolrServer per testing purpose.

Infact EmbeddedSolrServer is widely used in many tests of the Solr codebase.

https://github.com/freedev/EmbeddedSolrServer-junit-example

freedev
  • 25,946
  • 8
  • 108
  • 125