查询的总结:一般查询分为以下几个步骤:

1、创建查询对象

2、创建查询条件

3、执行查询,这里注意要有返回值

4、对查询结果进行取出 

 

   public void queryDocument() throws Exception {

         SolrServer solrServer = new HttpSolrServer("http://192.168.25.154:8080/solr");

         //创建一个查询对象

         SolrQuery query = new SolrQuery();

         //设置查询条件

         query.setQuery("*:*");

    //设置分页条件,当前开始页,显示多少条数

         query.setStart(20);

         query.setRows(50);

         //执行查询

         QueryResponse response = solrServer.query(query);

         //取查询结果

         SolrDocumentList solrDocumentList = response.getResults();

         System.out.println("共查询到记录:" + solrDocumentList.getNumFound());

         for (SolrDocument solrDocument : solrDocumentList) {

              System.out.println(solrDocument.get("id"));

              System.out.println(solrDocument.get("item_title"));

              System.out.println(solrDocument.get("item_price"));

              System.out.println(solrDocument.get("item_image"));

             

         }

     }