mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-05-15 13:15:58 +00:00
Make CompletionField annotation composable.
Original Pull Request #1841 Closes #1836
This commit is contained in:
parent
b515f18b33
commit
bc4c913a97
@ -23,13 +23,15 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
import java.lang.annotation.Target;
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Based on the reference doc - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
|
* Based on the reference doc -
|
||||||
|
* https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
|
||||||
*
|
*
|
||||||
* @author Mewes Kochheim
|
* @author Mewes Kochheim
|
||||||
* @author Robert Gruendler
|
* @author Robert Gruendler
|
||||||
|
* @author Peter-Josef Meisch
|
||||||
*/
|
*/
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.FIELD)
|
@Target({ ElementType.FIELD, ElementType.ANNOTATION_TYPE })
|
||||||
@Documented
|
@Documented
|
||||||
@Inherited
|
@Inherited
|
||||||
public @interface CompletionField {
|
public @interface CompletionField {
|
||||||
|
@ -32,6 +32,7 @@ import org.junit.jupiter.api.DisplayName;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.core.annotation.AliasFor;
|
import org.springframework.core.annotation.AliasFor;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
|
import org.springframework.data.elasticsearch.core.completion.Completion;
|
||||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||||
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
|
import org.springframework.data.elasticsearch.core.index.MappingBuilder;
|
||||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||||
@ -73,12 +74,17 @@ public class ComposableAnnotationsUnitTest {
|
|||||||
assertThat(property.storeNullValue()).isTrue();
|
assertThat(property.storeNullValue()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test // DATAES-362
|
@Test // DATAES-362, #1836
|
||||||
@DisplayName("should use composed Field annotations in MappingBuilder")
|
@DisplayName("should use composed Field annotations in MappingBuilder")
|
||||||
void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
|
void shouldUseComposedFieldAnnotationsInMappingBuilder() throws JSONException {
|
||||||
|
|
||||||
String expected = "{\n" + //
|
String expected = "{\n" + //
|
||||||
" \"properties\":{\n" + //
|
" \"properties\": {\n" + //
|
||||||
|
" \"_class\": {\n" + //
|
||||||
|
" \"type\": \"keyword\",\n" + //
|
||||||
|
" \"index\": false,\n" + //
|
||||||
|
" \"doc_values\": false\n" + //
|
||||||
|
" },\n" + //
|
||||||
" \"null-value\": {\n" + //
|
" \"null-value\": {\n" + //
|
||||||
" \"null_value\": \"NULL\"\n" + //
|
" \"null_value\": \"NULL\"\n" + //
|
||||||
" },\n" + //
|
" },\n" + //
|
||||||
@ -93,13 +99,21 @@ public class ComposableAnnotationsUnitTest {
|
|||||||
" \"type\": \"keyword\"\n" + //
|
" \"type\": \"keyword\"\n" + //
|
||||||
" }\n" + //
|
" }\n" + //
|
||||||
" }\n" + //
|
" }\n" + //
|
||||||
|
" },\n" + //
|
||||||
|
" \"suggest\": {\n" + //
|
||||||
|
" \"type\": \"completion\",\n" + //
|
||||||
|
" \"max_input_length\": 50,\n" + //
|
||||||
|
" \"preserve_position_increments\": true,\n" + //
|
||||||
|
" \"preserve_separators\": true,\n" + //
|
||||||
|
" \"search_analyzer\": \"myAnalyzer\",\n" + //
|
||||||
|
" \"analyzer\": \"myAnalyzer\"\n" + //
|
||||||
" }\n" + //
|
" }\n" + //
|
||||||
" }\n" + //
|
" }\n" + //
|
||||||
"}\n"; //
|
"}\n"; //
|
||||||
|
|
||||||
String mapping = mappingBuilder.buildPropertyMapping(ComposedAnnotationEntity.class);
|
String mapping = mappingBuilder.buildPropertyMapping(ComposedAnnotationEntity.class);
|
||||||
|
|
||||||
assertEquals(expected, mapping, false);
|
assertEquals(expected, mapping, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inherited
|
@Inherited
|
||||||
@ -142,12 +156,21 @@ public class ComposableAnnotationsUnitTest {
|
|||||||
public @interface TextKeywordField {
|
public @interface TextKeywordField {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Inherited
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target(ElementType.FIELD)
|
||||||
|
@CompletionField(analyzer = "myAnalyzer", searchAnalyzer = "myAnalyzer")
|
||||||
|
public @interface MyAnalyzerCompletionField {
|
||||||
|
}
|
||||||
|
|
||||||
@DocumentNoCreate(indexName = "test-no-create")
|
@DocumentNoCreate(indexName = "test-no-create")
|
||||||
static class ComposedAnnotationEntity {
|
static class ComposedAnnotationEntity {
|
||||||
@Nullable @Id private String id;
|
@Nullable @Id private String id;
|
||||||
@Nullable @NullValueField(name = "null-value") private String nullValue;
|
@Nullable @NullValueField(name = "null-value") private String nullValue;
|
||||||
@Nullable @LocalDateField private LocalDate theDate;
|
@Nullable @LocalDateField private LocalDate theDate;
|
||||||
@Nullable @TextKeywordField private String multiField;
|
@Nullable @TextKeywordField private String multiField;
|
||||||
|
@Nullable @MyAnalyzerCompletionField private Completion suggest;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getId() {
|
public String getId() {
|
||||||
@ -184,5 +207,14 @@ public class ComposableAnnotationsUnitTest {
|
|||||||
public void setMultiField(@Nullable String multiField) {
|
public void setMultiField(@Nullable String multiField) {
|
||||||
this.multiField = multiField;
|
this.multiField = multiField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public Completion getSuggest() {
|
||||||
|
return suggest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSuggest(@Nullable Completion suggest) {
|
||||||
|
this.suggest = suggest;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user