Skip to content

Commit 82c1e1d

Browse files
committed
added tests cases
1 parent 87d2009 commit 82c1e1d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

server/src/internalClusterTest/java/org/elasticsearch/search/fetch/subphase/highlight/HighlighterSearchIT.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,6 +3539,44 @@ public void testConstantKeywordFieldNoHighlightingQueryString() throws IOExcepti
35393539
assertHitCount(search, 0);
35403540
}
35413541

3542+
public void testConstantKeywordFieldHighlightingSimpleQueryString() throws IOException {
3543+
String index = "test";
3544+
String constantKeywordFieldName = "test_constant_keyword_field";
3545+
String constantValue = "constant_value";
3546+
3547+
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
3548+
assertAcked(prepareCreate(index).setMapping(mappings));
3549+
3550+
XContentBuilder document = jsonBuilder().startObject()
3551+
.field("foo", "bar")
3552+
.field(constantKeywordFieldName, constantValue)
3553+
.endObject();
3554+
saveDocumentIntoIndex(index, "1", document);
3555+
3556+
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.simpleQueryStringQuery(constantValue));
3557+
3558+
assertNoFailures(search);
3559+
assertHighlight(search, 0, constantKeywordFieldName, 0, 1, equalTo("<em>constant_value</em>"));
3560+
}
3561+
3562+
public void testConstantKeywordFieldNoHighlightingSimpleQueryString() throws IOException {
3563+
String index = "test";
3564+
String constantKeywordFieldName = "test_constant_keyword_field";
3565+
String constantValue = "constant_value";
3566+
String queryString = "foobar";
3567+
3568+
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
3569+
assertAcked(prepareCreate(index).setMapping(mappings));
3570+
3571+
XContentBuilder document = jsonBuilder().startObject().field("foo", "bar").endObject();
3572+
saveDocumentIntoIndex(index, "1", document);
3573+
3574+
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.simpleQueryStringQuery(queryString));
3575+
3576+
assertNoFailures(search);
3577+
assertHitCount(search, 0);
3578+
}
3579+
35423580
public void testConstantKeywordFieldHighlightingTerm() throws IOException {
35433581
String index = "test";
35443582
String constantKeywordFieldName = "test_constant_keyword_field";

server/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
package org.elasticsearch.index.query;
1010

1111
import org.apache.lucene.analysis.Analyzer;
12+
import org.apache.lucene.index.Term;
1213
import org.apache.lucene.search.FuzzyQuery;
1314
import org.apache.lucene.search.Query;
15+
import org.apache.lucene.search.WildcardQuery;
1416
import org.elasticsearch.TransportVersion;
1517
import org.elasticsearch.common.ParsingException;
1618
import org.elasticsearch.common.Strings;
@@ -600,4 +602,9 @@ protected boolean doEquals(SimpleQueryStringBuilder other) {
600602
public TransportVersion getMinimalSupportedVersion() {
601603
return TransportVersion.ZERO;
602604
}
605+
606+
@Override
607+
public Query toHighlightQuery(String fieldName) {
608+
return new WildcardQuery(new Term(fieldName, queryText));
609+
}
603610
}

0 commit comments

Comments
 (0)