Skip to content

Commit 58b2a9e

Browse files
committed
code format
1 parent 11b4dac commit 58b2a9e

File tree

2 files changed

+16
-41
lines changed

2 files changed

+16
-41
lines changed

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

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
*/
88
package org.elasticsearch.search.fetch.subphase.highlight;
99

10-
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
11-
1210
import net.bytebuddy.utility.RandomString;
1311

12+
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
13+
1414
import org.apache.lucene.analysis.Analyzer;
1515
import org.apache.lucene.analysis.TokenFilter;
1616
import org.apache.lucene.analysis.TokenStream;
@@ -27,7 +27,6 @@
2727
import org.elasticsearch.common.geo.GeoPoint;
2828
import org.elasticsearch.common.settings.Settings;
2929
import org.elasticsearch.common.settings.Settings.Builder;
30-
import org.elasticsearch.common.text.Text;
3130
import org.elasticsearch.common.time.DateFormatter;
3231
import org.elasticsearch.common.util.Maps;
3332
import org.elasticsearch.index.analysis.AbstractIndexAnalyzerProvider;
@@ -47,7 +46,6 @@
4746
import org.elasticsearch.plugins.Plugin;
4847
import org.elasticsearch.rest.RestStatus;
4948
import org.elasticsearch.search.SearchHit;
50-
import org.elasticsearch.search.SearchHits;
5149
import org.elasticsearch.search.builder.SearchSourceBuilder;
5250
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.BoundaryScannerType;
5351
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder.Field;
@@ -3514,10 +3512,7 @@ public void testConstantKeywordFieldHighlighting() throws IOException {
35143512
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
35153513
assertAcked(prepareCreate(index).setMapping(mappings));
35163514

3517-
XContentBuilder document = jsonBuilder().startObject()
3518-
.field("message", "some text")
3519-
.field("level", constantValue)
3520-
.endObject();
3515+
XContentBuilder document = jsonBuilder().startObject().field("message", "some text").field("level", constantValue).endObject();
35213516
saveDocumentIntoIndex(index, "1", document);
35223517

35233518
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.queryStringQuery(constantValue));
@@ -3527,17 +3522,15 @@ public void testConstantKeywordFieldHighlighting() throws IOException {
35273522
}
35283523

35293524
public void testImplicitConstantKeywordFieldHighlighting() throws IOException {
3530-
//Constant field value is defined by the mapping
3525+
// Constant field value is defined by the mapping
35313526
String index = "test";
35323527
String constantKeywordFieldName = "level";
35333528
String constantValue = new RandomString(5).nextString();
35343529

35353530
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
35363531
assertAcked(prepareCreate(index).setMapping(mappings));
35373532

3538-
XContentBuilder document = jsonBuilder().startObject()
3539-
.field("message", "some text")
3540-
.endObject();
3533+
XContentBuilder document = jsonBuilder().startObject().field("message", "some text").endObject();
35413534
saveDocumentIntoIndex(index, "1", document);
35423535

35433536
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.queryStringQuery(constantValue));
@@ -3555,9 +3548,7 @@ public void testConstantKeywordFieldPartialNoHighlighting() throws IOException {
35553548
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
35563549
assertAcked(prepareCreate(index).setMapping(mappings));
35573550

3558-
XContentBuilder document = jsonBuilder().startObject()
3559-
.field("message", "some text")
3560-
.endObject();
3551+
XContentBuilder document = jsonBuilder().startObject().field("message", "some text").endObject();
35613552
saveDocumentIntoIndex(index, "1", document);
35623553

35633554
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.queryStringQuery(partialConstantValue));
@@ -3575,9 +3566,7 @@ public void testConstantKeywordFieldPartialWithWildcardHighlighting() throws IOE
35753566
XContentBuilder mappings = prepareConstantKeywordMappings(constantKeywordFieldName, constantValue);
35763567
assertAcked(prepareCreate(index).setMapping(mappings));
35773568

3578-
XContentBuilder document = jsonBuilder().startObject()
3579-
.field("message", "some text")
3580-
.endObject();
3569+
XContentBuilder document = jsonBuilder().startObject().field("message", "some text").endObject();
35813570
saveDocumentIntoIndex(index, "1", document);
35823571

35833572
SearchResponse search = prepareConstantKeywordSearch(QueryBuilders.queryStringQuery(partialConstantValueWithWildCard));
@@ -3604,22 +3593,14 @@ private XContentBuilder prepareConstantKeywordMappings(String constantKeywordFie
36043593
return mappings;
36053594
}
36063595

3607-
private SearchResponse prepareConstantKeywordSearch(QueryBuilder query){
3596+
private SearchResponse prepareConstantKeywordSearch(QueryBuilder query) {
36083597
return client().prepareSearch()
3609-
.setSource(
3610-
new SearchSourceBuilder().query(query)
3611-
.highlighter(new HighlightBuilder().field("*"))
3612-
)
3598+
.setSource(new SearchSourceBuilder().query(query).highlighter(new HighlightBuilder().field("*")))
36133599
.get();
36143600
}
36153601

3616-
private void saveDocumentIntoIndex(String index, String id, XContentBuilder document){
3617-
client().prepareIndex(index)
3618-
.setId(id)
3619-
.setSource(
3620-
document
3621-
)
3622-
.get();
3602+
private void saveDocumentIntoIndex(String index, String id, XContentBuilder document) {
3603+
client().prepareIndex(index).setId(id).setSource(document).get();
36233604
refresh();
36243605
}
36253606

@@ -3672,5 +3653,4 @@ public Analyzer get() {
36723653
}
36733654
}
36743655

3675-
36763656
}

server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightPhase.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void process(HitContext hitContext) throws IOException {
7070
for (String field : contextBuilders.keySet()) {
7171
FieldHighlightContext fieldContext = contextBuilders.get(field).apply(hitContext);
7272
Highlighter highlighter = getHighlighter(fieldContext.field);
73-
HighlightField highlightField = highlighter.highlight(fieldContext); //field context query should have also original query
73+
HighlightField highlightField = highlighter.highlight(fieldContext);
7474
if (highlightField != null) {
7575
// Note that we make sure to use the original field name in the response. This is because the
7676
// original field could be an alias, and highlighter implementations may instead reference the
@@ -144,13 +144,8 @@ private FieldContext contextBuilders(
144144
}
145145

146146
Query highlightQuery = field.fieldOptions().highlightQuery();
147-
if (fieldType instanceof ConstantFieldType){
148-
highlightQuery = new TermQuery(
149-
new Term(
150-
fieldType.name(),
151-
getValueForConstantFieldType(context, fieldType)
152-
)
153-
);
147+
if (fieldType instanceof ConstantFieldType) {
148+
highlightQuery = new TermQuery(new Term(fieldType.name(), getValueForConstantFieldType(context, fieldType)));
154149
}
155150
Query finalHighlightQuery = highlightQuery;
156151
builders.put(
@@ -171,9 +166,9 @@ private FieldContext contextBuilders(
171166
return new FieldContext(storedFieldsSpec, builders);
172167
}
173168

174-
private String getValueForConstantFieldType(FetchContext context, MappedFieldType fieldType){ //TODO Move this somewhere-else
169+
private String getValueForConstantFieldType(FetchContext context, MappedFieldType fieldType) {
175170
try {
176-
return (String) fieldType.valueFetcher(context.getSearchExecutionContext(), null).fetchValues(null,0, List.of()).get(0);
171+
return (String) fieldType.valueFetcher(context.getSearchExecutionContext(), null).fetchValues(null, 0, List.of()).get(0);
177172
} catch (IOException e) {
178173
throw new RuntimeException(e);
179174
}

0 commit comments

Comments
 (0)