Skip to content

Fix type of returned sort values. #2786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static SearchDocument from(Hit<?> hit, JsonpMapper jsonpMapper) {
document.setPrimaryTerm(hit.primaryTerm() != null && hit.primaryTerm() > 0 ? hit.primaryTerm() : 0);

float score = hit.score() != null ? hit.score().floatValue() : Float.NaN;
return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toString).toArray(),
return new SearchDocumentAdapter(document, score, hit.sort().stream().map(TypeUtils::toObject).toArray(),
documentFields, highlightFields, innerHits, nestedMetaData, explanation, matchedQueries, hit.routing());
}

Expand Down Expand Up @@ -237,3 +237,4 @@ public static List<MultiGetItem<Document>> from(MgetResponse<EntityAsMap> mgetRe
.collect(Collectors.toList());
}
}
🚝
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,27 @@ void shouldSortDirectorsByYearOfBirthOfActorInTheirMoviesAscending() {
assertThat(searchHits.getSearchHit(0).getContent().id).isEqualTo(francisFordCoppola.id);
var sortValues = searchHits.getSearchHit(0).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1924");
assertThat(sortValues.get(0)).isEqualTo(1924L);

assertThat(searchHits.getSearchHit(1).getContent().id).isEqualTo(stanleyKubrik.id);
sortValues = searchHits.getSearchHit(1).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1937");
assertThat(sortValues.get(0)).isEqualTo(1937L);
}

@Test // #1784
@DisplayName("should sort directors by year of birth of actor in their movies descending")
void shouldSortDirectorsByYearOfBirthOfActorInTheirMoviesDescending() {

var order = new org.springframework.data.elasticsearch.core.query.Order(Sort.Direction.DESC,
"movies.actors.yearOfBirth") //
.withNested( //
Nested.builder("movies") //
.withNested(Nested.builder("movies.actors") //
.build()) //
.build());
var order = new org.springframework.data.elasticsearch.core.query.Order(Sort.Direction.DESC,
"movies.actors.yearOfBirth") //
.withNested( //
Nested.builder("movies") //
.withNested(Nested.builder("movies.actors") //
.build()) //
.build());

var query = Query.findAll().addSort(Sort.by(order));
var query = Query.findAll().addSort(Sort.by(order));

var searchHits = operations.search(query, Director.class);

Expand All @@ -132,32 +132,32 @@ void shouldSortDirectorsByYearOfBirthOfActorInTheirMoviesDescending() {
assertThat(searchHits.getSearchHit(0).getContent().id).isEqualTo(stanleyKubrik.id);
var sortValues = searchHits.getSearchHit(0).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1959");
assertThat(sortValues.get(0)).isEqualTo(1959L);

assertThat(searchHits.getSearchHit(1).getContent().id).isEqualTo(francisFordCoppola.id);
sortValues = searchHits.getSearchHit(1).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1946");
assertThat(sortValues.get(0)).isEqualTo(1946L);
}

@Test // #1784
@DisplayName("should sort directors by year of birth of male actor in their movies descending")
void shouldSortDirectorsByYearOfBirthOfMaleActorInTheirMoviesDescending() {

var filter = StringQuery.builder("""
{ "term": {"movies.actors.sex": "m"} }
""").build();
var order = new org.springframework.data.elasticsearch.core.query.Order(Sort.Direction.DESC,
"movies.actors.yearOfBirth") //
.withNested( //
Nested.builder("movies") //
.withNested( //
Nested.builder("movies.actors") //
.withFilter(filter) //
.build()) //
.build());
var filter = StringQuery.builder("""
{ "term": {"movies.actors.sex": "m"} }
""").build();
var order = new org.springframework.data.elasticsearch.core.query.Order(Sort.Direction.DESC,
"movies.actors.yearOfBirth") //
.withNested( //
Nested.builder("movies") //
.withNested( //
Nested.builder("movies.actors") //
.withFilter(filter) //
.build()) //
.build());

var query = Query.findAll().addSort(Sort.by(order));
var query = Query.findAll().addSort(Sort.by(order));

var searchHits = operations.search(query, Director.class);

Expand All @@ -166,12 +166,12 @@ void shouldSortDirectorsByYearOfBirthOfMaleActorInTheirMoviesDescending() {
assertThat(searchHits.getSearchHit(0).getContent().id).isEqualTo(stanleyKubrik.id);
var sortValues = searchHits.getSearchHit(0).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1959");
assertThat(sortValues.get(0)).isEqualTo(1959L);

assertThat(searchHits.getSearchHit(1).getContent().id).isEqualTo(francisFordCoppola.id);
sortValues = searchHits.getSearchHit(1).getSortValues();
assertThat(sortValues).hasSize(1);
assertThat(sortValues.get(0)).isEqualTo("1940");
assertThat(sortValues.get(0)).isEqualTo(1940L);
}

@Document(indexName = "#{@indexNameProvider.indexName()}")
Expand Down