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,15 @@ 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
+ if (matchedQueries == null ) {
239
+ return null ;
240
+ }
241
+
242
+ return List .of (matchedQueries );
243
+ }
244
+
234
245
/**
235
246
* Create an unmodifiable {@link Document} from {@link Iterable} of {@link DocumentField}s.
236
247
*
@@ -484,10 +495,11 @@ static class SearchDocumentAdapter implements SearchDocument {
484
495
private final Map <String , SearchDocumentResponse > innerHits = new HashMap <>();
485
496
@ Nullable private final NestedMetaData nestedMetaData ;
486
497
@ Nullable private final Explanation explanation ;
498
+ @ Nullable private final List <String > matchedQueries ;
487
499
488
500
SearchDocumentAdapter (float score , Object [] sortValues , Map <String , DocumentField > fields ,
489
501
Map <String , List <String >> highlightFields , Document delegate , Map <String , SearchDocumentResponse > innerHits ,
490
- @ Nullable NestedMetaData nestedMetaData , @ Nullable Explanation explanation ) {
502
+ @ Nullable NestedMetaData nestedMetaData , @ Nullable Explanation explanation , @ Nullable List < String > matchedQueries ) {
491
503
492
504
this .score = score ;
493
505
this .sortValues = sortValues ;
@@ -497,6 +509,7 @@ static class SearchDocumentAdapter implements SearchDocument {
497
509
this .innerHits .putAll (innerHits );
498
510
this .nestedMetaData = nestedMetaData ;
499
511
this .explanation = explanation ;
512
+ this .matchedQueries = matchedQueries ;
500
513
}
501
514
502
515
@ Override
@@ -679,6 +692,12 @@ public Explanation getExplanation() {
679
692
return explanation ;
680
693
}
681
694
695
+ @ Override
696
+ @ Nullable
697
+ public List <String > getMatchedQueries () {
698
+ return matchedQueries ;
699
+ }
700
+
682
701
@ Override
683
702
public boolean equals (Object o ) {
684
703
if (this == o ) {
0 commit comments