QueryParser.parse导致TokenStream合同违规

时间:2015-01-06 19:06:07

标签: lucene

我继承了一个使用Lucene 4.4.0的项目,我正在尝试更新它以使用Lucene 4.6.1。

当调用我的类的parse方法时,它会调用Lucene的org.apache.lucene.queryparser.classic.QueryParser上的解析。我的班级看起来有点像这样:

public class SomeClass {

    String field;
    Analyzer analyzer;

    // omitted for brevity...

    public Query parse(String query) throws ParseException {
        QueryParserBase parser = new QueryParser(Version.LUCENE_46, field, analyzer);
        parser.parse(query);
    }
}

由于升级到4.6.1 parser.parse(query)会产生如下异常:

java.lang.IllegalStateException: TokenStream contract violation: close() call missing
    at org.apache.lucene.analysis.Tokenizer.setReader(Tokenizer.java:89)
    at org.apache.lucene.analysis.Analyzer$TokenStreamComponents.setReader(Analyzer.java:307)
    at org.apache.lucene.analysis.standard.StandardAnalyzer$1.setReader(StandardAnalyzer.java:120)
    at org.apache.lucene.analysis.Analyzer.tokenStream(Analyzer.java:183)
    at org.apache.lucene.util.QueryBuilder.createFieldQuery(QueryBuilder.java:207)
    at org.apache.lucene.queryparser.classic.QueryParserBase.newFieldQuery(QueryParserBase.java:470)
    at org.apache.lucene.queryparser.classic.QueryParserBase.getFieldQuery(QueryParserBase.java:462)
    at org.apache.lucene.queryparser.classic.QueryParserBase.handleBareTokenQuery(QueryParserBase.java:842)
    at org.apache.lucene.queryparser.classic.QueryParser.Term(QueryParser.java:358)
    at org.apache.lucene.queryparser.classic.QueryParser.Clause(QueryParser.java:257)
    at org.apache.lucene.queryparser.classic.QueryParser.Query(QueryParser.java:181)
    at org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:170)
    at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:120)

我不熟悉Lucene最新的API更改,但我似乎无法访问TokenStream来致电close()reset()

那么,我是怎么解决这个问题的?

0 个答案:

没有答案