SolrJ从Java

时间:2015-11-10 15:44:18

标签: java solr solrj

我正在尝试使用相同版本的SolrJ从我的Java代码连接到运行5.3.1的Solr服务器。我不断在Eclipse中收到HttpSolrServer已被弃用的消息,但无法找到替换它的地方。有没有人知道如何使用SolrJ使用当前的东西从Java连接到Solr? SolrJ文档似乎都暗示HttpSolrServer是受支持的方式,但Eclipse并不满意。

4 个答案:

答案 0 :(得分:1)

Eclipse将每个具有@Deprecated注释的类标记为已弃用 HttpSolrServer确实已弃用,HttpSolrClient是其替换

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

答案 1 :(得分:1)

从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

答案 2 :(得分:0)

公共类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());

}

}

答案 3 :(得分:0)

弃用:

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

使用它:

SolrClient client = new HttpSolrClient.Builder(solrLocation).build();