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

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/u013035314/article/details/46007767
游标分页操作,解决页码过大时的性能问题。当然这容易内存泄露,需要谨慎处理;代码如下
 @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();
}
    }


                                    
展开阅读全文

没有更多推荐了,返回首页