简体   繁体   English

SolrJ从Java连接到Solr

[英]SolrJ connect to Solr from Java

I'm trying to connect from my Java code to a Solr server running 5.3.1 using the same version of SolrJ. 我正在尝试使用相同版本的SolrJ从Java代码连接到运行5.3.1的Solr服务器。 I keep getting a message in Eclipse that HttpSolrServer is deprecated, but cannot find anywhere what it has been replaced with. 我在Eclipse中不断收到一条消息,提示已弃用HttpSolrServer,但在任何地方都找不到它所替换的内容。 Does anyone know how I can connect to Solr from Java using SolrJ using something current? 有谁知道我该如何使用最新的SolrJ从Java连接到Solr? The SolrJ documentation all seems to suggest that HttpSolrServer is the supported way, but Eclipse is not happy about it. SolrJ文档似乎都暗示HttpSolrServer是受支持的方式,但是Eclipse对此并不满意。

Eclipse marks every class that has @Deprecated annotation as deprecated. Eclipse将每个具有@Deprecated批注的类标记为已弃用。
HttpSolrServer was deprecated indeed and HttpSolrClient is its replacment HttpSolrServer已弃用HttpSolrServer ,而HttpSolrClient是其替代品

SolrClient solrClient = new HttpSolrClient.Builder(solrLocation).build(); SolrClient solrClient =新的HttpSolrClient.Builder(solrLocation).build();

Starting from Solr 6.1 this the preferred way with to create SolrJ HTTP client: 从Solr 6.1开始,这是创建SolrJ HTTP客户端的首选方法:

String urlString = "http://localhost:8983/solr/my-collection";
SolrClient solrClient = new HttpSolrClient.Builder(urlString).build();

http://lucene.apache.org/solr/6_5_0/solr-solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.Builder.html http://lucene.apache.org/solr/6_5_0/solr-solrj/org/apache/solr/client/solrj/impl/HttpSolrClient.Builder.html

public class SolrCient { 公共类SolrCient {

private static final Logger LOGGER = Logger.getLogger(SolrCient.class.getName());

private static final String SERVER_URL = "http://localhost:8983/solr/suggest";

public static void main(String[] args) throws IOException, SolrServerException {

    HttpSolrClient solr = new HttpSolrClient(SERVER_URL);

    QueryResponse  response = solr.query(new SolrQuery("*:*"));

    System.out.println(response.toString());

}

} }

deprecated: 不推荐使用:

SolrClient client = new HttpSolrClient(solrLocation); SolrClient客户端=新的HttpSolrClient(solrLocation);

use this: 用这个:

SolrClient client = new HttpSolrClient.Builder(solrLocation).build(); SolrClient客户端=新的HttpSolrClient.Builder(solrLocation).build();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM