码迷,mamicode.com
首页 > 其他好文 > 详细

solr深分页,游标操作分页,解决性能问题

时间:2015-05-26 16:14:12      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:solr

 @Test
    public void pageByCursor() {
try {
   solrServer.connect();
   String query = "tablename:log_baseresult_netbehavior";
   SolrQuery q = new SolrQuery(query);
   q.setRows(10000000).setSort(SortClause.asc("rowkey"));


   String cursorMark = CursorMarkParams.CURSOR_MARK_START;


   boolean done = false;


   long time1 = System.currentTimeMillis();
   while (!done) {
q.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
QueryResponse qresponse = solrServer.query(q, METHOD.POST);

String nextCursorMark = qresponse.getNextCursorMark();

SolrDocumentList sList = qresponse.getResults();
System.out.println("---------"+sList.size());
/*for (SolrDocument doc : sList) {
   Collection<String> fieldNames = doc.getFieldNames();
   if (fieldNames.contains("rowkey")) {
String rowKey = (String) doc.getFieldValue("rowkey");
//System.out.println(rowKey);
   }
}*/

if (cursorMark.equals(nextCursorMark)) {
   done = true;
}
cursorMark = nextCursorMark;
   }
   long time2 = System.currentTimeMillis();
   System.out.println("time:"+(time2-time1));
} catch (SolrServerException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
}
    }

solr深分页,游标操作分页,解决性能问题

标签:solr

原文地址:http://blog.csdn.net/u013035314/article/details/46007767

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!