File tree 2 files changed +57
-1
lines changed
modules/lang-painless/src/test/resources/rest-api-spec/test/painless
server/src/main/java/org/elasticsearch/common/lucene/search/function
2 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 496
496
- match : { hits.total: 2 }
497
497
- match : { hits.hits.0._id : "2" }
498
498
- match : { hits.hits.1._id : "1" }
499
+
500
+
501
+ ---
502
+ " Script Score With Highlight " :
503
+ - skip :
504
+ version : " - 7.4.0"
505
+ reason : " highlight for script_score was introduced in 7.4.1"
506
+
507
+ - do :
508
+ indices.create :
509
+ index : test_index
510
+ body :
511
+ mappings :
512
+ " properties " :
513
+ " company " :
514
+ " type " : " text"
515
+ " reputation " :
516
+ " type " : " integer"
517
+ - do :
518
+ bulk :
519
+ refresh : true
520
+ body :
521
+ - ' {"index": {"_index": "test_index", "_id" : "1"}}'
522
+ - ' {"company": "ABC company", "reputation": 300}'
523
+ - ' {"index": {"_index": "test_index", "_id" : "2"}}'
524
+ - ' {"company": "ABC ABCD company", "reputation": 200}'
525
+ - ' {"index": {"_index": "test_index", "_id" : "3"}}'
526
+ - ' {"company": "ABCD company", "reputation": 100}'
527
+
528
+ - do :
529
+ search :
530
+ body :
531
+ query :
532
+ script_score :
533
+ script :
534
+ source : " doc['reputation'].value"
535
+ query :
536
+ bool :
537
+ should :
538
+ - match :
539
+ company : ABC
540
+ - match :
541
+ company : ABCD
542
+ highlight :
543
+ fields :
544
+ company : {}
545
+
546
+ - match : {hits.hits.0.highlight.company.0: "<em>ABC</em> company"}
547
+ - match : {hits.hits.1.highlight.company.0: "<em>ABC</em> <em>ABCD</em> company"}
548
+ - match : {hits.hits.2.highlight.company.0: "<em>ABCD</em> company"}
Original file line number Diff line number Diff line change 22
22
import org .apache .lucene .index .IndexReader ;
23
23
import org .apache .lucene .index .LeafReaderContext ;
24
24
import org .apache .lucene .index .Term ;
25
+ import org .apache .lucene .search .BooleanClause ;
25
26
import org .apache .lucene .search .DocIdSetIterator ;
26
27
import org .apache .lucene .search .Explanation ;
27
28
import org .apache .lucene .search .Query ;
29
+ import org .apache .lucene .search .QueryVisitor ;
28
30
import org .apache .lucene .search .Weight ;
29
31
import org .apache .lucene .search .IndexSearcher ;
30
32
import org .apache .lucene .search .ScoreMode ;
31
33
import org .apache .lucene .search .Scorer ;
32
34
import org .elasticsearch .ElasticsearchException ;
33
35
34
-
35
36
import java .io .IOException ;
36
37
import java .util .Objects ;
37
38
import java .util .Set ;
@@ -137,6 +138,11 @@ public boolean isCacheable(LeafReaderContext ctx) {
137
138
};
138
139
}
139
140
141
+ @ Override
142
+ public void visit (QueryVisitor visitor ) {
143
+ // Highlighters must visit the child query to extract terms
144
+ subQuery .visit (visitor .getSubVisitor (BooleanClause .Occur .MUST , this ));
145
+ }
140
146
141
147
@ Override
142
148
public String toString (String field ) {
You can’t perform that action at this time.
0 commit comments