throws QueryException {
// examine each clause in the Nutch query
Clause[] clauses = input.getClauses();
for (int i = 0; i < clauses.length; i++) {
Clause c = clauses[i];
// skip non-matching clauses
if (!c.getField().equals(field))
continue;
// optimize phrase clause
if (c.isPhrase()) {
String[] opt = CommonGrams.optimizePhrase(c.getPhrase(), field);
if (opt.length==1) {
c = new Clause(new Query.Term(opt[0]),
c.isRequired(), c.isProhibited());
} else {
c = new Clause(new Phrase(opt), c.isRequired(), c.isProhibited());
}
}
// construct appropriate Lucene clause
org.apache.lucene.search.Query luceneClause;
if (c.isPhrase()) {
Phrase nutchPhrase = c.getPhrase();
Query.Term[] terms = nutchPhrase.getTerms();
PhraseQuery lucenePhrase = new PhraseQuery();
for (int j = 0; j < terms.length; j++) {
lucenePhrase.add(new Term(field, terms[j].toString()));
}
luceneClause = lucenePhrase;
} else {
luceneClause = new TermQuery(new Term(field, c.getTerm().toString()));
}
// set boost
luceneClause.setBoost(boost);
// add it as specified in query
output.add(luceneClause, c.isRequired(), c.isProhibited());
}
// return the modified Lucene query
return output;
}