Index: src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java =================================================================== --- src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java (revision 641620) +++ src/java/org/apache/lucene/queryParser/MultiFieldQueryParser.java (working copy) @@ -99,17 +99,9 @@ if (field == null) { Vector clauses = new Vector(); for (int i = 0; i < fields.length; i++) { - Query q = super.getFieldQuery(fields[i], queryText); + Query q = getFieldQuery(fields[i], queryText, slop); if (q != null) { - //If the user passes a map of boosts - if (boosts != null) { - //Get the boost from the map and apply them - Float boost = (Float)boosts.get(fields[i]); - if (boost != null) { - q.setBoost(boost.floatValue()); - } - } - applySlop(q,slop); + applyBoost(fields[i], q); clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD)); } } @@ -117,25 +109,41 @@ return null; return getBooleanQuery(clauses, true); } - Query q = super.getFieldQuery(field, queryText); - applySlop(q,slop); - return q; + return super.getFieldQuery(field, queryText, slop); } - private void applySlop(Query q, int slop) { - if (q instanceof PhraseQuery) { - ((PhraseQuery) q).setSlop(slop); - } else if (q instanceof MultiPhraseQuery) { - ((MultiPhraseQuery) q).setSlop(slop); + protected Query getFieldQuery(String field, String queryText) throws ParseException { + if (field == null) { + Vector clauses = new Vector(); + for (int i = 0; i < fields.length; i++) { + Query q = getFieldQuery(fields[i], queryText); + if (q != null) { + applyBoost(fields[i], q); + clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD)); + } + } + if (clauses.size() == 0) // happens for stopwords + return null; + return getBooleanQuery(clauses, true); } + return super.getFieldQuery(field, queryText); } - - protected Query getFieldQuery(String field, String queryText) throws ParseException { - return getFieldQuery(field, queryText, 0); + /** + * Applies a boost to the query if a boost has been set for the specified field. + * + * @param field the field specified in the query. + * @param q the query itself. + */ + private void applyBoost(String field, Query q) { + if (boosts != null) { + Float boost = (Float)boosts.get(field); + if (boost != null) { + q.setBoost(boost.floatValue()); + } + } } - protected Query getFuzzyQuery(String field, String termStr, float minSimilarity) throws ParseException { if (field == null) {