Polishing.

This commit is contained in:
Peter-Josef Meisch 2021-11-21 21:08:05 +01:00
parent a22419c418
commit 44f9b29b66
No known key found for this signature in database
GPG Key ID: DE108246970C7708
6 changed files with 46 additions and 27 deletions

View File

@ -244,7 +244,11 @@ public class NativeSearchQueryBuilder {
return this;
}
/**
* @since 4.4
*/
public NativeSearchQueryBuilder withStoredFields(Collection<String> storedFields) {
if (this.storedFields == null) {
this.storedFields = new ArrayList<>(storedFields);
} else {
@ -253,7 +257,11 @@ public class NativeSearchQueryBuilder {
return this;
}
/**
* @since 4.4
*/
public NativeSearchQueryBuilder withStoredFields(String... storedFields) {
if (this.storedFields == null) {
this.storedFields = new ArrayList<>(storedFields.length);
}

View File

@ -51,16 +51,7 @@ import org.springframework.data.mapping.MappingException;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PreferredConstructor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.DefaultSpELExpressionEvaluator;
import org.springframework.data.mapping.model.EntityInstantiator;
import org.springframework.data.mapping.model.EntityInstantiators;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
import org.springframework.data.mapping.model.PropertyValueProvider;
import org.springframework.data.mapping.model.SpELContext;
import org.springframework.data.mapping.model.SpELExpressionEvaluator;
import org.springframework.data.mapping.model.SpELExpressionParameterValueProvider;
import org.springframework.data.mapping.model.*;
import org.springframework.data.util.ClassTypeInformation;
import org.springframework.data.util.TypeInformation;
import org.springframework.format.datetime.DateFormatterRegistrar;

View File

@ -113,9 +113,11 @@ public class BaseQuery implements Query {
@Override
public void addStoredFields(String... storedFields) {
if (storedFields.length == 0) {
return;
}
if (this.storedFields == null) {
this.storedFields = new ArrayList<>(storedFields.length);
}

View File

@ -113,6 +113,7 @@ public interface Query {
* Add stored fields to be added as part of search request
*
* @param storedFields
* @since 4.4
*/
void addStoredFields(String... storedFields);
@ -120,6 +121,7 @@ public interface Query {
* Get stored fields to be returned as part of search request
*
* @return null if not set
* @since 4.4
*/
@Nullable
List<String> getStoredFields();
@ -128,6 +130,7 @@ public interface Query {
* Set stored fields to be returned as part of search request
*
* @param storedFields
* @since 4.4
*/
void setStoredFields(@Nullable List<String> storedFields);

View File

@ -474,28 +474,38 @@ public class CriteriaQueryMappingUnitTests {
// region test entities
static class Person {
@Nullable @Id String id;
@Nullable @Field(name = "first-name") String firstName;
@Nullable @Field(name = "last-name") String lastName;
@Nullable @MultiField(mainField = @Field(name = "nick-name"),
@Nullable
@Id String id;
@Nullable
@Field(name = "first-name") String firstName;
@Nullable
@Field(name = "last-name") String lastName;
@Nullable
@MultiField(mainField = @Field(name = "nick-name"),
otherFields = { @InnerField(suffix = "keyword", type = FieldType.Keyword) }) String nickName;
@Nullable @Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
@Nullable @Field(name = "birth-date", type = FieldType.Date, format = {},
pattern = "dd.MM.uuuu") LocalDate birthDate;
@Nullable
@Field(name = "created-date", type = FieldType.Date, format = DateFormat.epoch_millis) Date createdDate;
@Nullable
@Field(name = "birth-date", type = FieldType.Date, format = {}, pattern = "dd.MM.uuuu") LocalDate birthDate;
}
static class House {
@Nullable @Id String id;
@Nullable @Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
@Nullable
@Id String id;
@Nullable
@Field(name = "per-sons", type = FieldType.Nested) List<Person> persons;
}
static class ObjectWithPerson {
@Nullable @Id String id;
@Nullable @Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
@Nullable
@Id String id;
@Nullable
@Field(name = "per-sons", type = FieldType.Object) List<Person> persons;
}
static class GeoShapeEntity {
@Nullable @Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
@Nullable
@Field(name = "geo-shape-field") GeoJson<?> geoShapeField;
}
// endregion
}

View File

@ -552,19 +552,24 @@ class RequestFactoryTests {
@DisplayName("should set stored fields on SearchRequest")
void shouldSetStoredFieldsOnSearchRequest() {
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location").build();
Query query = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withStoredFields("lastName", "location")
.build();
SearchRequest searchRequest = requestFactory.searchRequest(query, Person.class, IndexCoordinates.of("persons"));
assertThat(searchRequest.source().storedFields()).isNotNull();
assertThat(searchRequest.source().storedFields().fieldNames()).isEqualTo(Arrays.asList("last-name", "current-location"));
assertThat(searchRequest.source().storedFields().fieldNames())
.isEqualTo(Arrays.asList("last-name", "current-location"));
}
// region entities
static class Person {
@Nullable @Id String id;
@Nullable @Field(name = "last-name") String lastName;
@Nullable @Field(name = "current-location") GeoPoint location;
@Nullable
@Id String id;
@Nullable
@Field(name = "last-name") String lastName;
@Nullable
@Field(name = "current-location") GeoPoint location;
public Person() {}