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();
}
}
页:
[1]