从JSF中的solrj中检索信息

时间:2013-04-27 19:42:12

标签: mysql jsf solr

更新:简化示例并更改了我的问题。 在找到关键字时使用以下代码检索数据,但当我使用不在数据中的关键字时,它会为我提供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

0 个答案:

没有答案