更新:简化示例并更改了我的问题。使用以下代码在找到关键字时检索数据,但是当我使用不在数据中的关键字时,它给了我org.apache.solr.common.SolrException: missing content stream
class SearchBean
{
public void query(String q) throws IOException
{
HttpSolrServer server = null;
try
{
server = new HttpSolrServer("http://localhost:8080/solr/");
}
catch(Exception e)
{
e.printStackTrace();
}
SolrQuery query = new SolrQuery();
query.setQuery(q);
query.setFacet(true);
query.addFacetField("name");
query.addFacetField("title");
try
{
QueryResponse rsp = server.query(query);
SolrDocumentList docs = rsp.getResults();
List<ExampleBean> beans = rsp.getBeans(ExampleBean.class);
server.addBeans(beans);
System.out.println("Found: " + docs.getNumFound());
System.out.println("Start: " + docs.getStart());
System.out.println("Max Score: " + docs.getMaxScore());
System.out.println("--------------------------------");
System.out.println(rsp.toString());
System.out.println("--------------------------------");
for(ExampleBean example:beans){
System.out.println(example.getName().toString());
}
}
catch (SolrServerException e)
{
e.printStackTrace();
}
}
public static void main(String[] args) throws IOException
{
SearchBean solrj = new SearchBean();
solrj.query("test");
}
}
我已索引我的数据并通过 data-config.xml 导入到 solr