将文档添加到Lucene索引时出现ArrayIndexOutOfBounds异常(v 5.1.0)
在向索引中添加了几个文档之后,我不断收到ArrayIndexOutOfBounds异常。我有一个线程可以跨多台机器将文档添加到索引中。 我不确定这是否与我如何向文档中添加字段有关。“文本”可以是任意长度将文档添加到Lucene索引时出现ArrayIndexOutOfBounds异常(v 5.1.0),lucene,Lucene,在向索引中添加了几个文档之后,我不断收到ArrayIndexOutOfBounds异常。我有一个线程可以跨多台机器将文档添加到索引中。 我不确定这是否与我如何向文档中添加字段有关。“文本”可以是任意长度 public static void CreateIndex(){ int count = 0; try { IndexWriters.initIndexWriters(); //these are located on different machines on
public static void CreateIndex(){
int count = 0;
try {
IndexWriters.initIndexWriters(); //these are located on different machines on the network
int whichIndex = 0;
FileInputStream fis = new FileInputStream(Constants.MY_XML);
BufferedReader t = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
String title = "";
String articleId = "";
String str;
while ((str = t.readLine()) != null)
{
title = str.replace("<title>", "").replace("</title>", "").trim();
str = t.readLine();
articleId = str.replace("<id>", "").replace("</id>", "").trim();
str = t.readLine();
text = str.replace("<text>", "").replace("</text>", "").trim();
Document lDoc = new Document();
Field id = new TextField("id", articleId, Field.Store.YES);
Field title = new TextField("title", title, Field.Store.YES);
Field text = new TextField("text", text.toString(), Field.Store.YES);
Doc.add(id);
Doc.add(title);
Doc.add(text);
IndexWriters.indW[whichIndex].addDocument(Doc); //exception thrown here after adding couple of documents
whichIndex = (whichIndex+1)%(Constants.NUMNODES*Constants.PER_NODE_INDEXES_COUNT);
++count;
}
articleId = "";
text = null;
title = "";
}
}
}
IndexWriters.closeWriters();
}catch (IOException e) {
e.printStackTrace();
}catch( Exception e){
e.printStackTrace();
}
}
那么,您的代码中的假设是:
Constants.NUMNODES*Constants.PER_NODE_index_COUNT
等于(或小于)IndexWriters.indW.length
看来这个假设是不正确的
(这里也有一堆无关的
}
s,但是如果它编译了,我会假设这只是你在这里编辑发布时留下的东西)好吧,你的代码中的假设是:
Constants.NUMNODES*Constants.PER_NODE_index_COUNT
等于(或小于)IndexWriters.indW.length
看来这个假设是不正确的
(这里也有一堆无关的
}
s,但如果它编译了,我想这只是你在这里编辑帖子时留下的东西)实际常数。NUMNODES*Constants.PER_NODE_index_COUNT等于IndexWriters.indW.length.实际常数。NUMNODES*Constants.PER_NODE_index_COUNT等于IndexWriters.indW.length。
java.lang.ArrayIndexOutOfBoundsException: 32768
at org.apache.lucene.util.StringHelper.murmurhash3_x86_32(StringHelper.java:188)
at org.apache.lucene.util.BytesRefHash.doHash(BytesRefHash.java:460)
at org.apache.lucene.util.BytesRefHash.rehash(BytesRefHash.java:432)
at org.apache.lucene.util.BytesRefHash.add(BytesRefHash.java:323)
at org.apache.lucene.index.TermsHashPerField.add(TermsHashPerField.java:154)
at org.apache.lucene.index.DefaultIndexingChain$PerField.invert(DefaultIndexingChain.java:657)
at org.apache.lucene.index.DefaultIndexingChain.processField(DefaultIndexingChain.java:344)
at org.apache.lucene.index.DefaultIndexingChain.processDocument(DefaultIndexingChain.java:300)
at org.apache.lucene.index.DocumentsWriterPerThread.updateDocument(DocumentsWriterPerThread.java:232)
at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWriter.java:458)
at org.apache.lucene.index.IndexWriter.updateDocument(IndexWriter.java:1350)
at org.apache.lucene.index.IndexWriter.addDocument(IndexWriter.java:1138)