gpt4 book ai didi

java - SolrTemplate 和 SolrClient 有什么区别?

转载 作者:行者123 更新时间:2023-12-02 08:40:33 26 4
gpt4 key购买 nike

我正在记录我在 solr apache 的 Spring 数据教程之后编写的代码,我意识到我不知道 solrTemplateSolrClient 之间的区别> ?

我正在记录以下代码:

@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);
}
}

最佳答案

以下是 apache 文档中对 SolrClient 的描述

Abstraction through which all communication with a Solr server may be routed

这意味着您的所有 solr 调用都将通过 solrClient 路由,因此我们需要将 solr 服务器地址、端口(还有其他一些)配置为 solrClient

其中 solrTemplate 用于 solr 操作,如查询、计数等。solrTemplate 将使用 solrClient,这就是为什么在配置 solrTemplate 时,会传递 solrClient

关于java - SolrTemplate 和 SolrClient 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61416182/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com