Change default operator to "or" for "low_freq_operator" and "high_freq_operator" parameters for "common" queries
Closes #3178
This commit is contained in:
parent
8d59ed3ab0
commit
f537b8ccee
|
@ -51,9 +51,9 @@ public class CommonTermsQueryParser implements QueryParser {
|
|||
|
||||
static final float DEFAULT_MAX_TERM_DOC_FREQ = 0.01f;
|
||||
|
||||
static final Occur DEFAULT_HIGH_FREQ_OCCUR = Occur.MUST;
|
||||
static final Occur DEFAULT_HIGH_FREQ_OCCUR = Occur.SHOULD;
|
||||
|
||||
static final Occur DEFAULT_LOW_FREQ_OCCUR = Occur.MUST;
|
||||
static final Occur DEFAULT_LOW_FREQ_OCCUR = Occur.SHOULD;
|
||||
|
||||
static final boolean DEFAULT_DISABLE_COORDS = true;
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class CommonTermsQueryParser implements QueryParser {
|
|||
String minimumShouldMatch = null;
|
||||
boolean disableCoords = DEFAULT_DISABLE_COORDS;
|
||||
Occur highFreqOccur = DEFAULT_HIGH_FREQ_OCCUR;
|
||||
Occur lowFreqOccur = DEFAULT_HIGH_FREQ_OCCUR;
|
||||
Occur lowFreqOccur = DEFAULT_LOW_FREQ_OCCUR;
|
||||
float maxTermFrequency = DEFAULT_MAX_TERM_DOC_FREQ;
|
||||
token = parser.nextToken();
|
||||
if (token == XContentParser.Token.START_OBJECT) {
|
||||
|
|
|
@ -127,13 +127,19 @@ public class SimpleQueryTests extends AbstractSharedClusterTest {
|
|||
client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "3").setSource("field1", "quick lazy huge brown", "field2", "the quick lazy huge brown fox jumps over the tree").setRefresh(true).execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3)).execute().actionGet();
|
||||
SearchResponse searchResponse = client().prepareSearch().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).execute().actionGet();
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("2"));
|
||||
assertThat(searchResponse.getHits().getHits()[2].getId(), equalTo("3"));
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).execute().actionGet();
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("2"));
|
||||
|
||||
|
||||
searchResponse = client().prepareSearch().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).execute().actionGet();
|
||||
// Default
|
||||
searchResponse = client().prepareSearch().setQuery(QueryBuilders.commonTerms("field1", "the quick brown").cutoffFrequency(3)).execute().actionGet();
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(3l));
|
||||
assertThat(searchResponse.getHits().getHits()[0].getId(), equalTo("1"));
|
||||
assertThat(searchResponse.getHits().getHits()[1].getId(), equalTo("2"));
|
||||
|
|
Loading…
Reference in New Issue