I have not been able to work out how to get custom coordination going to demote results based on a specific term [ ... ]
Yeah, it's a little more complicated than perhaps it should be.
I've attached a class which does this. I think it's faster and more effective than what you proposed. This only works in the 1.4 codebase (current CVS), as it requires the new Query.getSimilarity() method.
To use this, change the line in your test program from:
Query balancedQuery =
NegatingQuery.createQuery(positiveQuery,negativeQuery,1);to
Query balancedQuery =
new BoostingQuery(positiveQuery, negativeQuery, 0.01f);Please tell if you find it useful.
Doug
import java.io.IOException; import org.apache.lucene.search.*; import org.apache.lucene.index.*;
/** Boosts the results of a query when a second query also matches.*/
public class BoostingQuery extends Query {
private float boost; // the amount to boost by
private Query match; // query to match
private Query context; // boost when matches too
public BoostingQuery(Query match, Query context, float boost) {
this.match = match;
this.context = (Query)context.clone(); // clone before boost
this.boost = boost;
context.setBoost(0.0f); // ignore context-only matches
}
public Query rewrite(IndexReader reader) throws IOException {
BooleanQuery result = new BooleanQuery() {
public Similarity getSimilarity(Searcher searcher) {
return new DefaultSimilarity() {
public float coord(int overlap, int max) {
switch (overlap) {
case 1: // matched only one clause
return 1.0f; // use the score as-is
case 2: // matched both clauses
return boost; // multiply by boost
default:
return 0.0f;
}
}
};
}
};
result.add(match, true, false);
result.add(context, false, false);
return result;
}
public String toString(String field) {
return match.toString(field) + "/" + context.toString(field);
}
}
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
