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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Lucene on Maven - java.lang.IllegalArgumentException UTF8编码长度超过最大长度32766错误相关的知识,希望对你有一定的参考价值。

我试图用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

以上是关于Lucene on Maven - java.lang.IllegalArgumentException UTF8编码长度超过最大长度32766错误的主要内容,如果未能解决你的问题,请参考以下文章

lucene Maven依赖

Lucene(01)

Lucene全文检索引擎

如何在maven的pom.xml中添加本地jar包

一种常见的maven打包后同名文件冲突错误

黑马javaweb10期(web前端+jsp+mybatis+ssh+_Activity+数据库+Maven+lucene)