如何使用solrj API將數據從xml文件加載到solr中?使用solrj和java以編程方式將數據加載到solr中
3
A
回答
4
使用Java 6,您可以使用Xpath從您的xml文件中獲取所需的內容。然後,您從您從xml中提取的內容填充SolrInputDocument。當該文件包含您需要的所有內容時,請使用加方法SolrServer將其提交給Solr。
5
謝謝帕斯卡。我想念我的問題,我實際上在使用groovy。但是,在任何情況下你的方法做的工作,但是這是我的解決方案:
CommonsHttpSolrServer server = SolrServerSingleton.getInstance().getServer();
def dataDir = System.getProperty("user.dir");
File xmlFile = new File(dataDir+"/book.xml");
def xml = xmlFile.getText();
DirectXmlRequest xmlreq = new DirectXmlRequest("/update", xml);
server.request(xmlreq);
server.commit();
的第一個參數來DirectXmlRequest是一個URL路徑,它必須是「/更新」,而且可變XML是一個包含XML字符串。例如
<add>
<doc>
<field name="title">blah</field>
</doc>
</add>
-1
SolrClient client = new HttpSolrClient("http://localhost:8983/solr/jiva/");
String dataDir = System.getProperty("user.dir");
File xmlFile = new File(dataDir + "/Alovera-Juice.xml");
if (xmlFile.exists()) {
InputStream is = new FileInputStream(xmlFile);
String str = IOUtils.toString(is);
DirectXmlRequest dxr = new DirectXmlRequest("/update", str);
client.request(dxr);
client.commit();
}
相關問題
- 1. 如何以編程方式將數據加載到gridview?
- 2. 以編程方式將數據從JSON加載到對象?
- 3. 以編程方式使用Django的加載數據
- 4. 以編程方式將URL加載到ng-view中
- 5. 以編程方式將數據添加到umbraco節點
- 6. 以編程方式將行添加到數據綁定的DataGridView?
- 7. 以編程方式將數據添加到客戶端
- 8. 以編程方式將非數據綁定列添加到gridview
- 9. Solr動態模式更新使用solrj
- 10. 將數量以編程方式在magento中添加到數量
- 11. 以編程方式將UIButtons和UIImage添加到UIScrollview中
- 12. 以編程方式將UILabels和UIButtons添加到Swift中的UIScrollView
- 13. 以編程方式將佈局加載到另一個佈局
- 14. 如何以編程方式將.epub加載到iphone
- 15. Java - 以編程方式將文件追加到Jar文件
- 16. 如何以編程方式加載Java中的librxtxSerial
- 17. 以編程方式加載和刪除應用程序
- 18. 如何以編程方式將自定義Java視圖類加載到RelativeLayout
- 19. 如何使用SolrJ重新加載Solr核心?
- 20. 使用MonoTouch以編程方式將UITextField添加到UIView
- 21. 以編程方式將資源加載爲字節數組
- 22. 在C#中以編程方式將formview綁定到數據表#
- 23. 以編程方式將數據從UITextFields存儲到NSArray中iOS
- 24. 以編程方式加載主界面?
- 25. 以編程方式加載圖像
- 26. 以編程方式加載clojure庫
- 27. 如何以編程方式加載UIViewController?
- 28. PropertyPlaceholderConfigurer無法以編程方式加載
- 29. 如何以編程方式加載UIViewController
- 30. 以編程方式將用戶控件加載到母版頁中的div
你知道,如果這也可以用於JSON和javabin? – Stainedart 2013-12-04 01:09:09