Web services 从solr检索数据的web服务
如何在java中编写RESTWeb服务以从solr服务器查询数据。我有一个java代码要从solr查询Web services 从solr检索数据的web服务,web-services,rest,solr,Web Services,Rest,Solr,如何在java中编写RESTWeb服务以从solr服务器查询数据。我有一个java代码要从solr查询 CommonsHttpSolrServer server = null; try { server = new CommonsHttpSolrServer("http://localhost:8080/solr/"); } catch(Exception e) {
CommonsHttpSolrServer server = null;
try
{
server = new CommonsHttpSolrServer("http://localhost:8080/solr/");
}
catch(Exception e)
{
e.printStackTrace();
}
SolrQuery query = new SolrQuery();
query.setQuery(solrquery);
query.set("rows",1000);
// query.setQueryType("dismax");
// query.setFacet(true);
// query.addFacetField("lastname");
// query.addFacetField("locality4");
// query.setFacetMinCount(2);
// query.setIncludeScore(true);
try
{
QueryResponse qr = server.query(query);
SolrDocumentList sdl = qr.getResults();
我需要通过将id作为查询参数在web服务中获得相同的功能。如果您只想查询作为参数传递给web服务的id-
String id = "100145";
String url = "http://localhost:8080/solr/core_name"; // core name needed if using multicore support
CommonsHttpSolrServer solrServer;
try {
solrServer = new CommonsHttpSolrServer(url);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "id:"+id);
QueryResponse qres = solrServer.query(qparams);
SolrDocumentList results = qres.getResults();
SolrDocument doc = results.get(0);
System.out.println(doc.getFieldValue("id"));
} catch (Exception e) {
e.printStackTrace();
}
如果您只想查询作为参数传递给Web服务的id-
String id = "100145";
String url = "http://localhost:8080/solr/core_name"; // core name needed if using multicore support
CommonsHttpSolrServer solrServer;
try {
solrServer = new CommonsHttpSolrServer(url);
ModifiableSolrParams qparams = new ModifiableSolrParams();
qparams.add("q", "id:"+id);
QueryResponse qres = solrServer.query(qparams);
SolrDocumentList results = qres.getResults();
SolrDocument doc = results.get(0);
System.out.println(doc.getFieldValue("id"));
} catch (Exception e) {
e.printStackTrace();
}
我想写一个rest web服务,而不是java之前的应用程序。这段代码放在web服务中。你可以找到很多关于编写一个简单的web服务并公开它的文章。我想编写一个rest web服务,而不是java之前的应用程序。这些代码放在web服务中。您可以找到大量关于编写简单Web服务并公开它的文章。