lucene 抛出的异常(分享)

1) too many boolean clauses异常

例如:

String keyword=".......";//(keyword的长度太长)

Query indexQuery = new QueryParser("name",analyzer).parse(keyword);

有没有人遇到过 上面的查询当 keyword很长时报错的问题? too many boolean clauses

QueryParser会将keyword切分为多个TermQuery组成的BooleanQuery.

所以当keyword被切成过于1024个时,就会出现刚刚那个异常。

查看原因是:

BooleanQuery.SetMaxClauseCount()

默认是1024

所以可以设置BooleanQuery.SetMaxClauseCount(比较大的数);这样就可以解决。

2)Increment must be zero or greater: -2147483648

org.apache.lucene.queryParser.ParseException

异常

出现的位置应该是

// 设置位移增量的,相对于TokenStream中该Token的前一个,只能设置为1或0

//默认为1,如果为0,则表示多个Term都具有同一个位置。
public void setPositionIncrement(int positionIncrement) {
    if (positionIncrement < 0)
      throw new IllegalArgumentException
        ("Increment must be zero or greater: " + positionIncrement);
    this.positionIncrement = positionIncrement;
}

3.异常org.apache.lucene.queryParser.ParseException: Cannot parse '': Encountered "<EOF>" at line 1, column 0.
Was expecting one of:
  <NOT> ...
  "+" ...
  "-" ...
  "(" ...
  "*" ...
  <QUOTED> ...
  <TERM> ...
  <PREFIXTERM> ...
  <WILDTERM> ...
  "[" ...
  "{" ...
  <NUMBER> ...
  <TERM> ...
  "*" ...
检查查询语句是否有lucene保留的关键字或者语料库中当前被分析的文本是空文本

http://blog.sina.com.cn/s/blog_5ddc071f0100p9vj.html

原文地址:https://www.cnblogs.com/qhyhao/p/3461319.html