use of org.apache.lucene.search.DefaultSimilarity in project greplin-lucene-utils by Cue.
the class ConstantQueryNormBoostingQuery method rewrite.
@Override
public Query rewrite(final IndexReader reader) throws IOException {
BooleanQuery result = new BooleanQuery() {
@Override
public Similarity getSimilarity(final Searcher searcher) {
final Similarity base = searcher.getSimilarity();
return new DefaultSimilarity() {
@Override
public float queryNorm(final float sumOfSquaredWeights) {
return base.queryNorm(sumOfSquaredWeights);
}
@Override
public float coord(final int overlap, final int max) {
switch(overlap) {
case // matched only one clause
1:
return 1.0f;
case // matched both clauses
2:
return ConstantQueryNormBoostingQuery.this.boost;
default:
return 0.0f;
}
}
};
}
};
result.add(this.match, BooleanClause.Occur.MUST);
result.add(this.context, BooleanClause.Occur.SHOULD);
return result;
}
Aggregations