77 */
88package org .elasticsearch .search .fetch .subphase .highlight ;
99
10- import com .carrotsearch .randomizedtesting .generators .RandomPicks ;
11-
1210import net .bytebuddy .utility .RandomString ;
1311
12+ import com .carrotsearch .randomizedtesting .generators .RandomPicks ;
13+
1414import org .apache .lucene .analysis .Analyzer ;
1515import org .apache .lucene .analysis .TokenFilter ;
1616import org .apache .lucene .analysis .TokenStream ;
2727import org .elasticsearch .common .geo .GeoPoint ;
2828import org .elasticsearch .common .settings .Settings ;
2929import org .elasticsearch .common .settings .Settings .Builder ;
30- import org .elasticsearch .common .text .Text ;
3130import org .elasticsearch .common .time .DateFormatter ;
3231import org .elasticsearch .common .util .Maps ;
3332import org .elasticsearch .index .analysis .AbstractIndexAnalyzerProvider ;
4746import org .elasticsearch .plugins .Plugin ;
4847import org .elasticsearch .rest .RestStatus ;
4948import org .elasticsearch .search .SearchHit ;
50- import org .elasticsearch .search .SearchHits ;
5149import org .elasticsearch .search .builder .SearchSourceBuilder ;
5250import org .elasticsearch .search .fetch .subphase .highlight .HighlightBuilder .BoundaryScannerType ;
5351import 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}
0 commit comments