我正在使用Solr 4.5。我試圖通過多個html文件循環來使用Apache Tika 1.4從文件中提取數據。然後將這些元數據字段添加到SolrInputDocument。每次我必須循環文件並創建SolrInputDocument的實例。索引似乎非常慢,我們有大量的文件要索引。我需要這裏的專家建議。這是我正在使用的示例代碼。SolrInputDocument/tika提取很慢的索引許多文檔
String urlString = "http://server/solr/";
SolrServer solr = new HttpSolrServer(urlString);
UpdateRequest updrequest = new UpdateRequest("/update");
//For tika extraction initialisation
BodyContentHandler handler = new BodyContentHandler(10 * 1024 * 1024);
AutoDetectParser autoparser = new AutoDetectParser();
Metadata metadata = new Metadata();
ParseContext parseContext = new ParseContext();
然後在每一個HTML文件我打電話,我已經寫了蒂卡提取方法ExtractData由我通過我與我的文件一起初始化這裏的每個對象:
ExtractData(file,solr,updrequest,handler,autoparser,metadata,parseContext);
代碼爲ExtractData由如下所示
public void ExtractData(String file,SolrServer solr,UpdateRequest updrequest,BodyContentHandler handler,AutoDetectParser autoparser,Metadata metadata,ParseContext parseContext) throws IOException,
SAXException, TikaException, SolrServerException {
SolrInputDocument solrinputdocument = new SolrInputDocument();
metadata.set(Metadata.CONTENT_TYPE, "text/html");
autoparser.parse(input, handler, metadata, parseContext);
//loop all metadata from the extraction and add the fields to the solr
String[] metadataNames = metadata.names();
for (String name : metadataNames) {
solrinputdocument.addField(name, metadata.get(name));
}
}
updrequest.add(solrinputdocument);
solr.request(updrequest);
}
您是否嘗試過多線程提取過程?所以並不是一個接一個地提取文檔。 – cheffe
正如cheffe所說的,同時在不同的線程中提取內容。你也可以使用ConcurrentUpdateSolrServer來緩衝SolrInputDocuments – sidgate
有人可以告訴我們如何創建一個多線程的方式來進行這種提取。我從來沒有在多線程中工作。請幫忙。 – user3161879