1. 程式人生 > >獲取solr 索引庫中總記錄條數

獲取solr 索引庫中總記錄條數

 /**
     * 獲取索引庫中總記錄條數
     * @return
     */
    public  long getSolrIndexCount(){
    	long num = 0;
		try {
			SolrQuery params = new SolrQuery();
			params.set("q", "*:*");
			QueryResponse	rsp = server.query(params);
			SolrDocumentList docs = rsp.getResults();  
			num = docs.getNumFound();  
			System.out.println(num);
		} catch (SolrServerException e) {
			e.printStackTrace();
		}     
    	return num;
    }