|
@@ -321,7 +321,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
|
|
|
|
|
|
searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get();
|
|
|
assertHitCount(searchResponse, 3l);
|
|
|
- // standard drops "the" since its a stopword
|
|
|
+ // stop drops "the" since its a stopword
|
|
|
assertFirstHit(searchResponse, hasId("1"));
|
|
|
assertSecondHit(searchResponse, hasId("3"));
|
|
|
assertThirdHit(searchResponse, hasId("2"));
|
|
@@ -340,7 +340,7 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
|
|
|
|
|
|
searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the quick brown").cutoffFrequency(3).operator(MatchQueryBuilder.Operator.AND).analyzer("stop")).get();
|
|
|
assertHitCount(searchResponse, 3l);
|
|
|
- // standard drops "the" since its a stopword
|
|
|
+ // stop drops "the" since its a stopword
|
|
|
assertFirstHit(searchResponse, hasId("1"));
|
|
|
assertSecondHit(searchResponse, hasId("3"));
|
|
|
assertThirdHit(searchResponse, hasId("2"));
|
|
@@ -353,6 +353,104 @@ public class SimpleQueryTests extends ElasticsearchIntegrationTest {
|
|
|
assertThirdHit(searchResponse, hasId("2"));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ public void testCommonTermsQueryStackedTokens() throws Exception {
|
|
|
+ assertAcked(prepareCreate("test")
|
|
|
+ .setSettings(settingsBuilder()
|
|
|
+ .put(indexSettings())
|
|
|
+ .put(SETTING_NUMBER_OF_SHARDS,1)
|
|
|
+ .put("index.analysis.filter.syns.type","synonym")
|
|
|
+ .putArray("index.analysis.filter.syns.synonyms","quick,fast")
|
|
|
+ .put("index.analysis.analyzer.syns.tokenizer","whitespace")
|
|
|
+ .put("index.analysis.analyzer.syns.filter","syns")
|
|
|
+ )
|
|
|
+ .addMapping("type1", "field1", "type=string,analyzer=syns", "field2", "type=string,analyzer=syns"));
|
|
|
+ ensureGreen();
|
|
|
+
|
|
|
+ indexRandom(true, client().prepareIndex("test", "type1", "3").setSource("field1", "quick lazy huge brown pidgin", "field2", "the quick lazy huge brown fox jumps over the tree"),
|
|
|
+ client().prepareIndex("test", "type1", "1").setSource("field1", "the quick brown fox"),
|
|
|
+ client().prepareIndex("test", "type1", "2").setSource("field1", "the quick lazy huge brown fox jumps over the tree") );
|
|
|
+
|
|
|
+ SearchResponse searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.OR)).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+ assertThirdHit(searchResponse, hasId("3"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3).lowFreqOperator(Operator.AND)).get();
|
|
|
+ assertThat(searchResponse.getHits().totalHits(), equalTo(2l));
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ // Default
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast brown").cutoffFrequency(3)).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+ assertThirdHit(searchResponse, hasId("3"));
|
|
|
+
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast huge fox").lowFreqMinimumShouldMatch("3")).get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("5")).get();
|
|
|
+ assertHitCount(searchResponse, 2l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1).highFreqMinimumShouldMatch("6")).get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery("{ \"common\" : { \"field1\" : { \"query\" : \"the fast lazy fox brown\", \"cutoff_frequency\" : 1, \"minimum_should_match\" : { \"high_freq\" : 6 } } } }").get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ // Default
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the fast lazy fox brown").cutoffFrequency(1)).get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(commonTerms("field1", "the quick brown").cutoffFrequency(3).analyzer("stop")).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ // stop drops "the" since its a stopword
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("3"));
|
|
|
+ assertThirdHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ // try the same with match query
|
|
|
+ searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the fast brown").cutoffFrequency(3).operator(MatchQueryBuilder.Operator.AND)).get();
|
|
|
+ assertHitCount(searchResponse, 2l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the fast brown").cutoffFrequency(3).operator(MatchQueryBuilder.Operator.OR)).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+ assertThirdHit(searchResponse, hasId("3"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the fast brown").cutoffFrequency(3).operator(MatchQueryBuilder.Operator.AND).analyzer("stop")).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ // stop drops "the" since its a stopword
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("3"));
|
|
|
+ assertThirdHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ searchResponse = client().prepareSearch().setQuery(matchQuery("field1", "the fast brown").cutoffFrequency(3).minimumShouldMatch("3")).get();
|
|
|
+ assertHitCount(searchResponse, 2l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ assertSecondHit(searchResponse, hasId("2"));
|
|
|
+
|
|
|
+ // try the same with multi match query
|
|
|
+ searchResponse = client().prepareSearch().setQuery(multiMatchQuery("the fast brown", "field1", "field2").cutoffFrequency(3).operator(MatchQueryBuilder.Operator.AND)).get();
|
|
|
+ assertHitCount(searchResponse, 3l);
|
|
|
+ assertFirstHit(searchResponse, hasId("3")); // better score due to different query stats
|
|
|
+ assertSecondHit(searchResponse, hasId("1"));
|
|
|
+ assertThirdHit(searchResponse, hasId("2"));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void testOmitTermFreqsAndPositions() throws Exception {
|
|
|
Version version = Version.CURRENT;
|