Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions solr/core/src/java/org/apache/solr/parser/SolrQueryParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,24 @@ protected Query newFieldQuery(
return query;
}

/**
* Delegates to {@link QueryBuilder#createFieldQuery(org.apache.lucene.analysis.Analyzer,
* org.apache.lucene.search.BooleanClause.Occur, java.lang.String, java.lang.String, boolean,
* int)} but returns MatchNoDocsQuery rather than null
*/
protected Query createFieldQuery(
Analyzer analyzer,
BooleanClause.Occur operator,
String field,
String queryText,
boolean quoted,
int phraseSlop) {

Query fieldQuery =
super.createFieldQuery(analyzer, operator, field, queryText, quoted, phraseSlop);
return fieldQuery != null ? fieldQuery : new MatchNoDocsQuery("empty query");
}

/**
* Base implementation delegates to {@link #getFieldQuery(String,String,boolean,boolean)}. This
* method may be overridden, for example, to return a SpanNearQuery instead of a PhraseQuery.
Expand Down
3 changes: 2 additions & 1 deletion solr/core/src/java/org/apache/solr/util/SolrPluginUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.apache.lucene.search.BoostQuery;
import org.apache.lucene.search.DisjunctionMaxQuery;
import org.apache.lucene.search.Explanation;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Sort;
import org.apache.solr.common.SolrException;
Expand Down Expand Up @@ -595,7 +596,7 @@ public static void setMinShouldMatch(BooleanQuery.Builder q, String spec, boolea
optionalDismaxClauses++;
}
} else {
optionalClauses++;
if (!(c.query() instanceof MatchNoDocsQuery)) optionalClauses++;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions solr/core/src/test-files/solr/collection1/conf/schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<analyzer type="query">
<tokenizer class="solr.LetterTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.StopFilterFactory" words="stopwords.txt"/>
</analyzer>
</fieldType>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.NamedMatches;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
Expand Down Expand Up @@ -109,6 +110,20 @@ public void testMinShouldMatchThresholdsLower() throws Exception {
assertEquals(expected, actual);
}

@Test
public void testMinShouldMatchWithEmptyClauseCausedByStopWord() throws Exception {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test fails: undefined field name_sw


Query actual =
parseQuery(req("q", "{!bool should=name:foo should=name:bar should=teststop:to mm=-1}"));

BooleanQuery expected =
shouldBuilder("foo", "bar")
.setMinimumNumberShouldMatch(1)
.add(new MatchNoDocsQuery(""), BooleanClause.Occur.SHOULD)
.build();
assertEquals(expected, actual);
}

@Test
public void testMinShouldMatchThresholdsUpper() throws Exception {
Query actual =
Expand Down