[英]What is the difference between SolrTemplate and SolrClient?
我正在記錄我在 Spring 數據的 solr apache 的一些教程之后編寫的代碼,我意識到我不知道solrTemplate
和SolrClient
之間的區別?
我正在記錄以下代碼:
@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);
}
}
以下是 SolrClient 的SolrClient
文檔中的描述
Abstraction through which all communication with a Solr server may be routed
這意味着您的所有 solr 調用都將通過 solrClient 路由,因此我們需要將 solr 服務器地址、端口(也很少)配置為solrClient
。
其中solrTemplate
用於 solr 操作,如查詢、計數等。 solrTemplate
將使用solrClient
這就是為什么在配置solrTemplate
時,會傳遞solrClient
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.