I was documenting my code that i wrote following some tutorials on Spring data for solr apache, and i realised i didn't know the diference between a solrTemplate and a SolrClient ?
i was documenting the following code :
@Configuration
@EnableSolrRepositories(basePackages = {"com.anouar.solr.nomenclaturespringdatasolr.repository",
"com.anouar.solr.nomenclaturespringdatasolr.dataImportHandler"},
namedQueriesLocation = "classpath:solr-named-queries.properties")
public class SolrConfig {
@Value("${spring.data.solr.host}")
String solrURL;
/**
* returns the bean that establishes the connection with Solr through port 8983
*
* @return SolrClient
*
* **/
@Bean
public SolrClient solrClient() {
return new HttpSolrClient.Builder(solrURL).build();
}
/**
*
* @param client the bean that is connected to Solr through port 8983
*
* **/
@Bean
public SolrTemplate solrTemplate(SolrClient client) throws Exception {
return new SolrTemplate(client);
}
}
Below is the description from apache documentation for
SolrClientwhich means all your solr calls will be route via solrClient so we need to configure solr server address, port(few other also) to
solrClient.where as
solrTemplateis for solr operations like query, count, etc..solrTemplatewill usesolrClientthat's why while configuringsolrTemplate,solrClientis passed.