31
31
import java .util .function .BiConsumer ;
32
32
import java .util .stream .Collectors ;
33
33
34
+ import com .fasterxml .jackson .core .JsonEncoding ;
35
+ import com .fasterxml .jackson .core .JsonFactory ;
36
+ import com .fasterxml .jackson .core .JsonGenerator ;
37
+
34
38
import org .elasticsearch .action .get .GetResponse ;
35
39
import org .elasticsearch .action .get .MultiGetItemResponse ;
36
40
import org .elasticsearch .action .get .MultiGetResponse ;
47
51
import org .springframework .util .Assert ;
48
52
import org .springframework .util .StringUtils ;
49
53
50
- import com .fasterxml .jackson .core .JsonEncoding ;
51
- import com .fasterxml .jackson .core .JsonFactory ;
52
- import com .fasterxml .jackson .core .JsonGenerator ;
53
-
54
54
/**
55
55
* Utility class to adapt {@link org.elasticsearch.action.get.GetResponse},
56
56
* {@link org.elasticsearch.index.get.GetResult}, {@link org.elasticsearch.action.get.MultiGetResponse}
60
60
* @author Mark Paluch
61
61
* @author Peter-Josef Meisch
62
62
* @author Roman Puchkovskiy
63
+ * @author Matt Gilene
63
64
* @since 4.0
64
65
*/
65
66
public class DocumentAdapters {
@@ -181,14 +182,15 @@ public static SearchDocument from(SearchHit source) {
181
182
182
183
NestedMetaData nestedMetaData = from (source .getNestedIdentity ());
183
184
Explanation explanation = from (source .getExplanation ());
185
+ List <String > matchedQueries = from (source .getMatchedQueries ());
184
186
185
187
BytesReference sourceRef = source .getSourceRef ();
186
188
187
189
if (sourceRef == null || sourceRef .length () == 0 ) {
188
190
return new SearchDocumentAdapter (
189
191
source .getScore (), source .getSortValues (), source .getFields (), highlightFields , fromDocumentFields (source ,
190
192
source .getIndex (), source .getId (), source .getVersion (), source .getSeqNo (), source .getPrimaryTerm ()),
191
- innerHits , nestedMetaData , explanation );
193
+ innerHits , nestedMetaData , explanation , matchedQueries );
192
194
}
193
195
194
196
Document document = Document .from (source .getSourceAsMap ());
@@ -202,7 +204,7 @@ public static SearchDocument from(SearchHit source) {
202
204
document .setPrimaryTerm (source .getPrimaryTerm ());
203
205
204
206
return new SearchDocumentAdapter (source .getScore (), source .getSortValues (), source .getFields (), highlightFields ,
205
- document , innerHits , nestedMetaData , explanation );
207
+ document , innerHits , nestedMetaData , explanation , matchedQueries );
206
208
}
207
209
208
210
@ Nullable
@@ -231,6 +233,11 @@ private static NestedMetaData from(@Nullable SearchHit.NestedIdentity nestedIden
231
233
return NestedMetaData .of (nestedIdentity .getField ().string (), nestedIdentity .getOffset (), child );
232
234
}
233
235
236
+ @ Nullable
237
+ private static List <String > from (@ Nullable String [] matchedQueries ) {
238
+ return matchedQueries == null ? null : Arrays .asList (matchedQueries );
239
+ }
240
+
234
241
/**
235
242
* Create an unmodifiable {@link Document} from {@link Iterable} of {@link DocumentField}s.
236
243
*
@@ -484,10 +491,11 @@ static class SearchDocumentAdapter implements SearchDocument {
484
491
private final Map <String , SearchDocumentResponse > innerHits = new HashMap <>();
485
492
@ Nullable private final NestedMetaData nestedMetaData ;
486
493
@ Nullable private final Explanation explanation ;
494
+ @ Nullable private final List <String > matchedQueries ;
487
495
488
496
SearchDocumentAdapter (float score , Object [] sortValues , Map <String , DocumentField > fields ,
489
497
Map <String , List <String >> highlightFields , Document delegate , Map <String , SearchDocumentResponse > innerHits ,
490
- @ Nullable NestedMetaData nestedMetaData , @ Nullable Explanation explanation ) {
498
+ @ Nullable NestedMetaData nestedMetaData , @ Nullable Explanation explanation , @ Nullable List < String > matchedQueries ) {
491
499
492
500
this .score = score ;
493
501
this .sortValues = sortValues ;
@@ -497,6 +505,7 @@ static class SearchDocumentAdapter implements SearchDocument {
497
505
this .innerHits .putAll (innerHits );
498
506
this .nestedMetaData = nestedMetaData ;
499
507
this .explanation = explanation ;
508
+ this .matchedQueries = matchedQueries ;
500
509
}
501
510
502
511
@ Override
@@ -679,6 +688,12 @@ public Explanation getExplanation() {
679
688
return explanation ;
680
689
}
681
690
691
+ @ Override
692
+ @ Nullable
693
+ public List <String > getMatchedQueries () {
694
+ return matchedQueries ;
695
+ }
696
+
682
697
@ Override
683
698
public boolean equals (Object o ) {
684
699
if (this == o ) {
0 commit comments