开发者

Lucene QueryParser needed that works with Custom Analyzer having stopfilter and porterstemfilter

开发者 https://www.devze.com 2022-12-31 14:41 出处:网络
With QueryParser, the stemfilter开发者_运维百科 does not seem to work and with AnalyzingQueryParser, the stop filter is not effective.

With QueryParser, the stemfilter开发者_运维百科 does not seem to work and with AnalyzingQueryParser, the stop filter is not effective.

Is my observation correct? How to solve this problem?

Update OK So did some experiments with the code. The AnalyzingQueryParser does not allow stopfilter and the QueryParser does not allow porterstemmerfilter with fuzzysearches.

So I need a QueryParser that allows fuzzy searches along with support for porterstemfilter and stopfilter.


You can override extend the QueryParser by subclassing it if need be. I was able to use the StopAnalyzer with AnalyzingQueryParser without problems:

Analyzer analyzer1 = new StopAnalyzer(Version.LUCENE_30, ImmutableSet.of("foo", "bar", "blop"));
QueryParser qp = new AnalyzingQueryParser(Version.LUCENE_30, "field", analyzer1);
Query q = qp.parse("foobar foo bar blop hello");
System.out.println("query  " + q);

q = qp.parse("foobar~ foo~ bar~ hell~");
System.out.println("query  " + q);

Create the query: field:foobar field:hello and field:foobar~0.5 hell~0.5 . This is lucene 3.0.3, so I'm not sure if this applies to your question back then. Anyway, I stumbled upon this and hoped it might help. You might run into problems with the stemmers if they add wildcard queries, in which case you might want to override the methods:

@Override
protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException {
    return super.getFuzzyQuery(field, termStr, minSimilarity);
}

@Override
protected Query getWildcardQuery(String field, String termStr) throws ParseException {
    return super.getWildcardQuery(field, termStr);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消