mirror of https://github.com/apache/lucene.git
LUCENE-7472: MultiFieldQueryParser.getFieldQuery() drops queries that are neither BooleanQuery nor TermQuery.
This commit is contained in:
parent
221a6870b8
commit
6739e075b4
|
@ -46,6 +46,9 @@ New Features
|
|||
|
||||
Bug Fixes
|
||||
|
||||
* LUCENE-7472: MultiFieldQueryParser.getFieldQuery() drops queries that are
|
||||
neither BooleanQuery nor TermQuery. (Steve Rowe)
|
||||
|
||||
Improvements
|
||||
|
||||
* LUCENE-7439: FuzzyQuery now matches all terms within the specified
|
||||
|
|
|
@ -154,10 +154,10 @@ public class MultiFieldQueryParser extends QueryParser
|
|||
for (int i = 0; i < fields.length; i++) {
|
||||
Query q = super.getFieldQuery(fields[i], queryText, quoted);
|
||||
if (q != null) {
|
||||
if (q instanceof TermQuery) {
|
||||
maxTerms = Math.max(1, maxTerms);
|
||||
} else if (q instanceof BooleanQuery) {
|
||||
if (q instanceof BooleanQuery) {
|
||||
maxTerms = Math.max(maxTerms, ((BooleanQuery)q).clauses().size());
|
||||
} else {
|
||||
maxTerms = Math.max(1, maxTerms);
|
||||
}
|
||||
fieldQueries[i] = q;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.apache.lucene.index.DirectoryReader;
|
|||
import org.apache.lucene.index.IndexReader;
|
||||
import org.apache.lucene.index.IndexWriter;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.queryparser.util.QueryParserTestBase;
|
||||
import org.apache.lucene.search.BooleanClause.Occur;
|
||||
import org.apache.lucene.search.BooleanClause;
|
||||
import org.apache.lucene.search.BooleanQuery;
|
||||
|
@ -331,4 +332,25 @@ public class TestMultiFieldQueryParser extends LuceneTestCase {
|
|||
assertEquals(bq.build(), mfqp.parse("/[a-z][123]/"));
|
||||
}
|
||||
|
||||
/** whitespace+lowercase analyzer with synonyms (dogs,dog) and (guinea pig,cavy) */
|
||||
private class MockSynonymAnalyzer extends Analyzer {
|
||||
@Override
|
||||
public TokenStreamComponents createComponents(String fieldName) {
|
||||
Tokenizer tokenizer = new MockTokenizer(MockTokenizer.WHITESPACE, true);
|
||||
return new TokenStreamComponents(tokenizer, new MockSynonymFilter(tokenizer));
|
||||
}
|
||||
}
|
||||
|
||||
public void testSynonyms() throws ParseException {
|
||||
String[] fields = {"b", "t"};
|
||||
MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new MockSynonymAnalyzer());
|
||||
Query q = parser.parse("dogs");
|
||||
assertEquals("Synonym(b:dog b:dogs) Synonym(t:dog t:dogs)", q.toString());
|
||||
q = parser.parse("guinea pig");
|
||||
assertFalse(parser.getSplitOnWhitespace());
|
||||
assertEquals("(Synonym(b:cavy b:guinea) Synonym(t:cavy t:guinea)) (b:pig t:pig)", q.toString());
|
||||
parser.setSplitOnWhitespace(true);
|
||||
q = parser.parse("guinea pig");
|
||||
assertEquals("(b:guinea t:guinea) (b:pig t:pig)", q.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue