mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-08 13:12:10 +00:00
Polishing.
This commit is contained in:
parent
7c466395c4
commit
a82952b124
@ -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));
|
||||||
});
|
});
|
||||||
|
@ -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,39 +41,40 @@ 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>()
|
||||||
.total(total -> total
|
.total(total -> total
|
||||||
.value(0)
|
.value(0)
|
||||||
.relation(TotalHitsRelation.Eq))
|
.relation(TotalHitsRelation.Eq))
|
||||||
.hits(new ArrayList<>())
|
.hits(new ArrayList<>())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final var suggestionTest = new Suggestion.Builder<EntityAsMap>()
|
final var suggestionTest = new Suggestion.Builder<EntityAsMap>()
|
||||||
.phrase(phrase -> phrase
|
.phrase(phrase -> phrase
|
||||||
.text("National")
|
.text("National")
|
||||||
.offset(0)
|
.offset(0)
|
||||||
.length(8)
|
.length(8)
|
||||||
.options(option -> option
|
.options(option -> option
|
||||||
.text("nations")
|
.text("nations")
|
||||||
.highlighted("highlighted-nations")
|
.highlighted("highlighted-nations")
|
||||||
.score(0.11480146)
|
.score(0.11480146)
|
||||||
.collateMatch(false))
|
.collateMatch(false))
|
||||||
.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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user