Polishing.

This commit is contained in:
Peter-Josef Meisch 2023-09-03 14:39:49 +02:00
parent 7c466395c4
commit a82952b124
No known key found for this signature in database
GPG Key ID: DE108246970C7708
2 changed files with 30 additions and 28 deletions

View File

@ -219,7 +219,8 @@ class SearchDocumentResponseBuilder {
var phraseSuggestOptions = phraseSuggest.options(); var phraseSuggestOptions = phraseSuggest.options();
List<PhraseSuggestion.Entry.Option> options = new ArrayList<>(); List<PhraseSuggestion.Entry.Option> options = new ArrayList<>();
phraseSuggestOptions.forEach(optionES -> options phraseSuggestOptions.forEach(optionES -> options
.add(new PhraseSuggestion.Entry.Option(optionES.text(), optionES.highlighted(), optionES.score(), optionES.collateMatch()))); .add(new PhraseSuggestion.Entry.Option(optionES.text(), optionES.highlighted(), optionES.score(),
optionES.collateMatch())));
entries.add(new PhraseSuggestion.Entry(phraseSuggest.text(), phraseSuggest.offset(), phraseSuggest.length(), entries.add(new PhraseSuggestion.Entry(phraseSuggest.text(), phraseSuggest.offset(), phraseSuggest.length(),
options, null)); options, null));
}); });

View File

@ -15,6 +15,11 @@
*/ */
package org.springframework.data.elasticsearch.client.elc; package org.springframework.data.elasticsearch.client.elc;
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
import co.elastic.clients.elasticsearch.core.search.Suggestion;
import co.elastic.clients.elasticsearch.core.search.TotalHitsRelation;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -26,11 +31,6 @@ import org.springframework.data.elasticsearch.core.document.SearchDocumentRespon
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import co.elastic.clients.elasticsearch.core.search.HitsMetadata;
import co.elastic.clients.elasticsearch.core.search.Suggestion;
import co.elastic.clients.elasticsearch.core.search.TotalHitsRelation;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
/** /**
* Tests for the factory class to create {@link SearchDocumentResponse} instances. * Tests for the factory class to create {@link SearchDocumentResponse} instances.
* *
@ -41,7 +41,7 @@ class SearchDocumentResponseBuilderUnitTests {
private JacksonJsonpMapper jsonpMapper = new JacksonJsonpMapper(); private JacksonJsonpMapper jsonpMapper = new JacksonJsonpMapper();
@Test // GH-2681 @Test // #2681
void shouldGetPhraseSuggestion() throws JSONException { void shouldGetPhraseSuggestion() throws JSONException {
// arrange // arrange
final var hitsMetadata = new HitsMetadata.Builder<EntityAsMap>() final var hitsMetadata = new HitsMetadata.Builder<EntityAsMap>()
@ -64,16 +64,17 @@ class SearchDocumentResponseBuilderUnitTests {
.options(option -> option .options(option -> option
.text("national") .text("national")
.highlighted("highlighted-national") .highlighted("highlighted-national")
.score( 0.08063514) .score(0.08063514)
.collateMatch(false))) .collateMatch(false)))
.build(); .build();
final var sortProperties = ImmutableMap.<String, List<Suggestion<EntityAsMap>>>builder() final var sortProperties = ImmutableMap.<String, List<Suggestion<EntityAsMap>>> builder()
.put("suggestionTest", ImmutableList.of(suggestionTest)) .put("suggestionTest", ImmutableList.of(suggestionTest))
.build(); .build();
// act // act
final var actual = SearchDocumentResponseBuilder.from(hitsMetadata, null, null, null, sortProperties, null, jsonpMapper); final var actual = SearchDocumentResponseBuilder.from(hitsMetadata, null, null, null, sortProperties, null,
jsonpMapper);
// assert // assert
SoftAssertions softly = new SoftAssertions(); SoftAssertions softly = new SoftAssertions();