【发布时间】:2019-09-04 12:13:47
【问题描述】:
我正在尝试使用 Lucene Maven 索引超过字符串长度限制的大型文档。然后,我收到此错误。
Caused by: java.lang.IllegalArgumentException: Document contains at least one immense term in field="content" (whose UTF8 encoding is longer than the max length 32766), all of which were skipped. Please correct the analyzer to not produce such terms. The prefix of the first immense term is: '[65, 32, 98, 101, 110, 122, 111, 100, 105, 97, 122, 101, 112, 105, 110, 101, 32, 91, 116, 112, 108, 93, 73, 80, 65, 99, 45, 101, 110, 124]...', original message: bytes can be at most 32766 in length; got 85391
代码如下(它是http://lucenetutorial.com/lucene-in-5-minutes.html的副本,从文件中读取文档略有改动。):
File file = "doc.txt";
StandardAnalyzer analyzer = new StandardAnalyzer();
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter w = new IndexWriter(index, config);
Document doc = new Document();
Scanner scanner = new Scanner(file))
while (scanner.hasNextLine())
{
String line = scanner.nextLine();
doc.add(new StringField("content", line, Field.Store.YES));
w.addDocument(doc);
}
...
还有其他帖子与我遇到的问题相同,但它们是 SOLR 或 Elasticsearch 的解决方案,而不是 Maven 上的 Lucene,所以我不太确定如何解决这个问题。
谁能指导我到正确的地方来解决这个问题,好吗?
提前谢谢你。
【问题讨论】: