Solr执行查询操作

方法一:

 1     @Test
 2     public void test3(){
 3         try {
 4             SolrQuery query=new SolrQuery("*");
 5             QueryResponse response=httpSolrServer.query(query);
 6             SolrDocumentList list=response.getResults();
 7             for(SolrDocument sd:list){
 8                 System.out.println(sd);
 9                 System.out.println(sd.getFieldValue("news_title"));
10             }
11         } catch (SolrServerException e) {
12             e.printStackTrace();
13         }

方法二:

 1     @Test
 2     public void test4(){
 3         try {
 4             SolrQuery query=new SolrQuery("*");
 5             QueryResponse response=httpSolrServer.query(query);
 6             List<News> list=response.getBeans(News.class);
 7             for(News n:list){
 8                 System.out.println(n.getTitle());
 9             }
10         } catch (SolrServerException e) {
11             e.printStackTrace();
12         }
13     }

 

posted @ 2012-04-24 00:45  Paul.Lau  阅读(690)  评论(0编辑  收藏  举报