mirror of https://github.com/apache/lucene.git
LUCENE-1213: MultiFieldQueryParser ignored slop for single field phrases.
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@635839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
25f80c71c9
commit
29560fcf50
|
@ -67,6 +67,9 @@ Bug fixes
|
|||
scorer.next(). (Eks Dev, Michael Busch)
|
||||
|
||||
3. LUCENE-1182: Added scorePayload to SimilarityDelegator (Andi Vajda via Grant Ingersoll)
|
||||
|
||||
4. LUCENE-1213: MultiFieldQueryParser was ignoring slop in case
|
||||
of a single field phrase. (Trejkaz via Doron Cohen)
|
||||
|
||||
New features
|
||||
|
||||
|
|
|
@ -99,7 +99,7 @@ public class MultiFieldQueryParser extends QueryParser
|
|||
if (field == null) {
|
||||
Vector clauses = new Vector();
|
||||
for (int i = 0; i < fields.length; i++) {
|
||||
Query q = getFieldQuery(fields[i], queryText);
|
||||
Query q = super.getFieldQuery(fields[i], queryText);
|
||||
if (q != null) {
|
||||
//If the user passes a map of boosts
|
||||
if (boosts != null) {
|
||||
|
@ -109,12 +109,7 @@ public class MultiFieldQueryParser extends QueryParser
|
|||
q.setBoost(boost.floatValue());
|
||||
}
|
||||
}
|
||||
if (q instanceof PhraseQuery) {
|
||||
((PhraseQuery) q).setSlop(slop);
|
||||
}
|
||||
if (q instanceof MultiPhraseQuery) {
|
||||
((MultiPhraseQuery) q).setSlop(slop);
|
||||
}
|
||||
applySlop(q,slop);
|
||||
clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +117,17 @@ public class MultiFieldQueryParser extends QueryParser
|
|||
return null;
|
||||
return getBooleanQuery(clauses, true);
|
||||
}
|
||||
return super.getFieldQuery(field, queryText);
|
||||
Query q = super.getFieldQuery(field, queryText);
|
||||
applySlop(q,slop);
|
||||
return q;
|
||||
}
|
||||
|
||||
private void applySlop(Query q, int slop) {
|
||||
if (q instanceof PhraseQuery) {
|
||||
((PhraseQuery) q).setSlop(slop);
|
||||
} else if (q instanceof MultiPhraseQuery) {
|
||||
((MultiPhraseQuery) q).setSlop(slop);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -113,6 +113,10 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {
|
|||
q = mfqp.parse("\"foo bar\"~4");
|
||||
assertEquals("b:\"foo bar\"~4 t:\"foo bar\"~4", q.toString());
|
||||
|
||||
// LUCENE-1213: MultiFieldQueryParser was ignoring slop when phrase had a field.
|
||||
q = mfqp.parse("b:\"foo bar\"~4");
|
||||
assertEquals("b:\"foo bar\"~4", q.toString());
|
||||
|
||||
// make sure that terms which have a field are not touched:
|
||||
q = mfqp.parse("one f:two");
|
||||
assertEquals("(b:one t:one) f:two", q.toString());
|
||||
|
|
Loading…
Reference in New Issue