Skip to content

Commit eb816cc

Browse files
committed
Polishing.
1 parent 4dc8b25 commit eb816cc

File tree

5 files changed

+34
-27
lines changed

5 files changed

+34
-27
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/SearchHit.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/**
3232
* Encapsulates the found data with additional information from the search.
33-
*
33+
*
3434
* @param <T> the result data class.
3535
* @author Peter-Josef Meisch
3636
* @author Matt Gilene
@@ -48,8 +48,13 @@ public class SearchHit<T> {
4848
@Nullable private final NestedMetaData nestedMetaData;
4949
@Nullable private final String routing;
5050
@Nullable private final Explanation explanation;
51-
@Nullable private final List<String> matchedQueries;
51+
private final List<String> matchedQueries = new ArrayList<>();
5252

53+
/**
54+
* @deprecated since 4.2 use
55+
* {@link #SearchHit(String, String, String, float, Object[], Map, Map, NestedMetaData, Explanation, List, Object)}.
56+
*/
57+
@Deprecated
5358
public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score,
5459
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields, T content) {
5560
this(index, id, routing, score, sortValues, highlightFields, null, null, null, null, content);
@@ -58,8 +63,7 @@ public SearchHit(@Nullable String index, @Nullable String id, @Nullable String r
5863
public SearchHit(@Nullable String index, @Nullable String id, @Nullable String routing, float score,
5964
@Nullable Object[] sortValues, @Nullable Map<String, List<String>> highlightFields,
6065
@Nullable Map<String, SearchHits<?>> innerHits, @Nullable NestedMetaData nestedMetaData,
61-
@Nullable Explanation explanation,
62-
@Nullable List<String> matchedQueries, T content) {
66+
@Nullable Explanation explanation, @Nullable List<String> matchedQueries, T content) {
6367
this.index = index;
6468
this.id = id;
6569
this.routing = routing;
@@ -77,7 +81,10 @@ public SearchHit(@Nullable String index, @Nullable String id, @Nullable String r
7781
this.nestedMetaData = nestedMetaData;
7882
this.explanation = explanation;
7983
this.content = content;
80-
this.matchedQueries = matchedQueries;
84+
85+
if (matchedQueries != null) {
86+
this.matchedQueries.addAll(matchedQueries);
87+
}
8188
}
8289

8390
/**
@@ -125,7 +132,7 @@ public Map<String, List<String>> getHighlightFields() {
125132

126133
/**
127134
* gets the highlight values for a field.
128-
*
135+
*
129136
* @param field must not be {@literal null}
130137
* @return possibly empty List, never null
131138
*/
@@ -141,7 +148,7 @@ public List<String> getHighlightField(String field) {
141148
* nested entity class, the returned data will be of this type, otherwise
142149
* {{@link org.springframework.data.elasticsearch.core.document.SearchDocument}} instances are returned in this
143150
* {@link SearchHits} object.
144-
*
151+
*
145152
* @param name the inner hits name
146153
* @return {@link SearchHits} if available, otherwise {@literal null}
147154
*/
@@ -160,7 +167,7 @@ public Map<String, SearchHits<?>> getInnerHits() {
160167

161168
/**
162169
* If this is a nested inner hit, return the nested metadata information
163-
*
170+
*
164171
* @return {{@link NestedMetaData}
165172
* @since 4.1
166173
*/

Diff for: src/main/java/org/springframework/data/elasticsearch/core/document/DocumentAdapters.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@
3131
import java.util.function.BiConsumer;
3232
import java.util.stream.Collectors;
3333

34-
import com.fasterxml.jackson.core.JsonEncoding;
35-
import com.fasterxml.jackson.core.JsonFactory;
36-
import com.fasterxml.jackson.core.JsonGenerator;
37-
3834
import org.elasticsearch.action.get.GetResponse;
3935
import org.elasticsearch.action.get.MultiGetItemResponse;
4036
import org.elasticsearch.action.get.MultiGetResponse;
@@ -51,6 +47,10 @@
5147
import org.springframework.util.Assert;
5248
import org.springframework.util.StringUtils;
5349

50+
import com.fasterxml.jackson.core.JsonEncoding;
51+
import com.fasterxml.jackson.core.JsonFactory;
52+
import com.fasterxml.jackson.core.JsonGenerator;
53+
5454
/**
5555
* Utility class to adapt {@link org.elasticsearch.action.get.GetResponse},
5656
* {@link org.elasticsearch.index.get.GetResult}, {@link org.elasticsearch.action.get.MultiGetResponse}
@@ -131,7 +131,7 @@ public static Document from(GetResult source) {
131131

132132
/**
133133
* Creates a List of {@link MultiGetItem<Document>}s from {@link MultiGetResponse}.
134-
*
134+
*
135135
* @param source the source {@link MultiGetResponse}, not {@literal null}.
136136
* @return a list of Documents, contains null values for not found Documents.
137137
*/
@@ -146,7 +146,7 @@ public static List<MultiGetItem<Document>> from(MultiGetResponse source) {
146146

147147
/**
148148
* Creates a {@link MultiGetItem<Document>} from a {@link MultiGetItemResponse}.
149-
*
149+
*
150150
* @param itemResponse the response, must not be {@literal null}
151151
* @return the MultiGetItem
152152
*/
@@ -495,7 +495,8 @@ static class SearchDocumentAdapter implements SearchDocument {
495495

496496
SearchDocumentAdapter(float score, Object[] sortValues, Map<String, DocumentField> fields,
497497
Map<String, List<String>> highlightFields, Document delegate, Map<String, SearchDocumentResponse> innerHits,
498-
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation, @Nullable List<String> matchedQueries) {
498+
@Nullable NestedMetaData nestedMetaData, @Nullable Explanation explanation,
499+
@Nullable List<String> matchedQueries) {
499500

500501
this.score = score;
501502
this.sortValues = sortValues;

Diff for: src/test/java/org/springframework/data/elasticsearch/core/DocumentAdaptersUnitTests.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
*/
1616
package org.springframework.data.elasticsearch.core;
1717

18-
import static org.assertj.core.api.Assertions.assertThat;
18+
import static org.assertj.core.api.Assertions.*;
1919

20-
import java.io.IOException;
2120
import java.util.Arrays;
2221
import java.util.Collections;
2322
import java.util.LinkedHashMap;
@@ -138,13 +137,13 @@ public void shouldAdaptGetResultSource() {
138137
}
139138

140139
@Test // DATAES-628, DATAES-848
141-
public void shouldAdaptSearchResponse() throws IOException {
140+
public void shouldAdaptSearchResponse() {
142141

143142
Map<String, DocumentField> fields = Collections.singletonMap("field",
144143
new DocumentField("field", Collections.singletonList("value")));
145144

146145
SearchShardTarget shard = new SearchShardTarget("node", new ShardId("index", "uuid", 42), null, null);
147-
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), fields, null);
146+
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), null, fields);
148147
searchHit.shard(shard);
149148
searchHit.setSeqNo(1);
150149
searchHit.setPrimaryTerm(2);
@@ -219,7 +218,7 @@ public void shouldAdaptSearchResponseSource() {
219218
BytesArray source = new BytesArray("{\"field\":\"value\"}");
220219

221220
SearchShardTarget shard = new SearchShardTarget("node", new ShardId("index", "uuid", 42), null, null);
222-
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), Collections.emptyMap(), null);
221+
SearchHit searchHit = new SearchHit(123, "my-id", new Text("type"), null, null);
223222
searchHit.shard(shard);
224223
searchHit.sourceRef(source).score(42);
225224
searchHit.version(22);

Diff for: src/test/java/org/springframework/data/elasticsearch/core/SearchHitSupportTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ void unwrapsSearchHitsIteratorToCloseableIteratorOfEntities() {
5959
void shouldReturnTheSameListInstanceInSearchHitsAndGetContent() {
6060

6161
List<SearchHit<String>> hits = new ArrayList<>();
62-
hits.add(new SearchHit<>(null, null, null, 0, null, null, "one"));
63-
hits.add(new SearchHit<>(null, null, null, 0, null, null, "two"));
64-
hits.add(new SearchHit<>(null, null, null, 0, null, null, "three"));
65-
hits.add(new SearchHit<>(null, null, null, 0, null, null, "four"));
66-
hits.add(new SearchHit<>(null, null, null, 0, null, null, "five"));
62+
hits.add(new SearchHit<>(null, null, null, 0, null, null, null, null, null, null, "one"));
63+
hits.add(new SearchHit<>(null, null, null, 0, null, null, null, null, null, null, "two"));
64+
hits.add(new SearchHit<>(null, null, null, 0, null, null, null, null, null, null, "three"));
65+
hits.add(new SearchHit<>(null, null, null, 0, null, null, null, null, null, null, "four"));
66+
hits.add(new SearchHit<>(null, null, null, 0, null, null, null, null, null, null, "five"));
6767

6868
SearchHits<String> originalSearchHits = new SearchHitsImpl<>(hits.size(), TotalHitsRelation.EQUAL_TO, 0, "scroll",
6969
hits, null);
@@ -112,7 +112,7 @@ public boolean hasNext() {
112112
@Override
113113
public SearchHit<String> next() {
114114
String nextString = iterator.next();
115-
return new SearchHit<>("index", "id", null, 1.0f, new Object[0], emptyMap(), nextString);
115+
return new SearchHit<>("index", "id", null, 1.0f, new Object[0], emptyMap(), null, null, null, null, nextString);
116116
}
117117
}
118118

Diff for: src/test/java/org/springframework/data/elasticsearch/core/StreamQueriesTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void shouldCallClearScrollOnIteratorClose() {
6262
}
6363

6464
private SearchHit<String> getOneSearchHit() {
65-
return new SearchHit<String>(null, null, null, 0, null, null, "one");
65+
return new SearchHit<String>(null, null, null, 0, null, null, null, null, null, null, "one");
6666
}
6767

6868
@Test // DATAES-766

0 commit comments

Comments
 (0)