我需要在Java中獲取Apache Solr中所有文檔的索引大小。此代碼獲得的numFound表示Apache Solr中文檔的總數。通過使用ReplicationHandler,我認爲我可以通過此鏈接獲取某人在此處所告訴的索引大小.. http://lucene.472066.n3.nabble.com/cheking-the-size-of-the-index-using-solrj-API-s-td692686.html。但我沒有得到索引大小。如何獲得索引中的索引大小
BufferedWriter out1 = null;
FileWriter fstream1 = new FileWriter("src/test/resources/solr-document-id-desc.txt");
out1 = new BufferedWriter(fstream1);
ApplicationContext context = null;
context = new ClassPathXmlApplicationContext("application-context.xml");
CommonsHttpSolrServer solrServer = (CommonsHttpSolrServer) context.getBean("solrServer");
SolrQuery solrQuery = new SolrQuery().setQuery("*:*");
QueryResponse rsp = solrServer.query(solrQuery);
//I am trying to use replicationhandler but I am not able to get the index size using statistics. Is there any way to get the index size..?
ReplicationHandler handler2 = new ReplicationHandler();
System.out.println(handler2.getDescription());
NamedList statistics = handler2.getStatistics();
System.out.println("Statistics "+ statistics);
System.out.println(rsp.getResults().getNumFound());
Iterator<SolrDocument> iter = rsp.getResults().iterator();
while (iter.hasNext()) {
SolrDocument resultDoc = iter.next();
System.out.println(resultDoc.getFieldNames());
String id = (String) resultDoc.getFieldValue("numFound");
String description = (String) resultDoc.getFieldValue("description");
System.out.println(id+"~~"+description);
out1.write(id+"~~"+description);
out1.newLine();
}
out1.close();
Any suggestions will be appreciated..
更新代碼: -
ReplicationHandler handler2 = new ReplicationHandler();
System.out.println(handler2.getDescription());
NamedList statistics = handler2.getStatistics();
System.out.println("Statistics "+ statistics.get("indexSize"));
我的建議是讓你的問題更清晰:)你已經提交了代碼,但沒有說你正在嘗試*做什麼或者實際做了什麼,或者你遇到了什麼問題。請閱讀http://tinyurl.com/so-hints –
@JonSkeet,我已經更新了這些問題。讓我知道現在是否有意義.. – ferhan
不是真的 - 你說你*有*得到索引大小,但是你「沒有得到」它......所以會發生什麼? –