gpt4 book ai didi

java - Maven 上的 Lucene - java.lang.IllegalArgumentException UTF8 编码长度超过最大长度 32766 错误

转载 作者:行者123 更新时间:2023-12-02 10:00:24 25 4
gpt4 key购买 nike

我正在尝试使用 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,所以我不太确定如何解决这个问题。

有人可以指导我到正确的地方来解决这个问题吗?

提前谢谢您。

最佳答案

如果您想要索引文本而不是单个单词,则应该使用可以将文本分解为单词的工具,例如 WhitespaceAnalyzer

关于java - Maven 上的 Lucene - java.lang.IllegalArgumentException UTF8 编码长度超过最大长度 32766 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55673494/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com