DATAES-91 - fixed payload feature, added corresponding unit tests to cover it, fixed code format
This commit is contained in:
committed by
Artur Konczak
parent
0ad982b233
commit
1255dfa89d
@@ -10,41 +10,41 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@Document(indexName = "test-completion-index", type = "annotated-completion-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class AnnotatedCompletionEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@CompletionField(payloads = true, maxInputLength = 100)
|
||||
private Completion suggest;
|
||||
@CompletionField(payloads = true, maxInputLength = 100)
|
||||
private Completion suggest;
|
||||
|
||||
private AnnotatedCompletionEntity() {
|
||||
}
|
||||
private AnnotatedCompletionEntity() {
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public AnnotatedCompletionEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,47 +24,47 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
*/
|
||||
public class AnnotatedCompletionEntityBuilder {
|
||||
|
||||
private CompletionEntity result;
|
||||
private AnnotatedCompletionEntity result;
|
||||
|
||||
public AnnotatedCompletionEntityBuilder(String id) {
|
||||
result = new CompletionEntity(id);
|
||||
}
|
||||
public AnnotatedCompletionEntityBuilder(String id) {
|
||||
result = new AnnotatedCompletionEntity(id);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
public AnnotatedCompletionEntityBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
public AnnotatedCompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionEntity build() {
|
||||
return result;
|
||||
}
|
||||
public AnnotatedCompletionEntity build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,41 +12,41 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@Document(indexName = "test-completion-index", type = "completion-annotation-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class CompletionAnnotatedEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
@CompletionField(payloads = true)
|
||||
private Completion suggest;
|
||||
@CompletionField(payloads = true)
|
||||
private Completion suggest;
|
||||
|
||||
private CompletionAnnotatedEntity() {
|
||||
}
|
||||
private CompletionAnnotatedEntity() {
|
||||
}
|
||||
|
||||
public CompletionAnnotatedEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public CompletionAnnotatedEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,40 +9,40 @@ import org.springframework.data.elasticsearch.annotations.Document;
|
||||
@Document(indexName = "test-completion-index", type = "completion-type", indexStoreType = "memory", shards = 1, replicas = 0, refreshInterval = "-1")
|
||||
public class CompletionEntity {
|
||||
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
@Id
|
||||
private String id;
|
||||
private String name;
|
||||
|
||||
private Completion suggest;
|
||||
private Completion suggest;
|
||||
|
||||
private CompletionEntity() {
|
||||
}
|
||||
private CompletionEntity() {
|
||||
}
|
||||
|
||||
public CompletionEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public CompletionEntity(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
public Completion getSuggest() {
|
||||
return suggest;
|
||||
}
|
||||
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
public void setSuggest(Completion suggest) {
|
||||
this.suggest = suggest;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,52 +24,52 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
*/
|
||||
public class CompletionEntityAnnotatedBuilder {
|
||||
|
||||
private CompletionAnnotatedEntity result;
|
||||
private CompletionAnnotatedEntity result;
|
||||
|
||||
public CompletionEntityAnnotatedBuilder(String id) {
|
||||
result = new CompletionAnnotatedEntity(id);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
if (output != null) {
|
||||
suggest.setOutput(output);
|
||||
public CompletionEntityAnnotatedBuilder(String id) {
|
||||
result = new CompletionAnnotatedEntity(id);
|
||||
}
|
||||
if (payload != null) {
|
||||
suggest.setPayload(payload);
|
||||
}
|
||||
if (weight != null) {
|
||||
suggest.setWeight(weight);
|
||||
}
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionAnnotatedEntity build() {
|
||||
return result;
|
||||
}
|
||||
public CompletionEntityAnnotatedBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public CompletionEntityAnnotatedBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
if (output != null) {
|
||||
suggest.setOutput(output);
|
||||
}
|
||||
if (payload != null) {
|
||||
suggest.setPayload(payload);
|
||||
}
|
||||
if (weight != null) {
|
||||
suggest.setWeight(weight);
|
||||
}
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionAnnotatedEntity build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,47 +22,47 @@ import org.springframework.data.elasticsearch.core.query.IndexQuery;
|
||||
*/
|
||||
public class CompletionEntityBuilder {
|
||||
|
||||
private CompletionEntity result;
|
||||
private CompletionEntity result;
|
||||
|
||||
public CompletionEntityBuilder(String id) {
|
||||
result = new CompletionEntity(id);
|
||||
}
|
||||
public CompletionEntityBuilder(String id) {
|
||||
result = new CompletionEntity(id);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
public CompletionEntityBuilder name(String name) {
|
||||
result.setName(name);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
public CompletionEntityBuilder suggest(String[] input) {
|
||||
return suggest(input, null, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
public CompletionEntityBuilder suggest(String[] input, String output) {
|
||||
return suggest(input, output, null, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload) {
|
||||
return suggest(input, output, payload, null);
|
||||
}
|
||||
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
public CompletionEntityBuilder suggest(String[] input, String output, Object payload, Integer weight) {
|
||||
Completion suggest = new Completion(input);
|
||||
suggest.setOutput(output);
|
||||
suggest.setPayload(payload);
|
||||
suggest.setWeight(weight);
|
||||
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
result.setSuggest(suggest);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CompletionEntity build() {
|
||||
return result;
|
||||
}
|
||||
public CompletionEntity build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
public IndexQuery buildIndex() {
|
||||
IndexQuery indexQuery = new IndexQuery();
|
||||
indexQuery.setId(result.getId());
|
||||
indexQuery.setObject(result);
|
||||
return indexQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.completion;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.action.suggest.SuggestResponse;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestion;
|
||||
import org.elasticsearch.search.suggest.completion.CompletionSuggestionFuzzyBuilder;
|
||||
@@ -45,88 +52,193 @@ import static org.junit.Assert.assertEquals;
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
public class ElasticsearchTemplateCompletionTests {
|
||||
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
@Autowired
|
||||
private ElasticsearchTemplate elasticsearchTemplate;
|
||||
|
||||
private void loadCompletionObjectEntities() {
|
||||
elasticsearchTemplate.deleteIndex(CompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(CompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(CompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(CompletionEntity.class);
|
||||
private void loadCompletionObjectEntities() {
|
||||
elasticsearchTemplate.deleteIndex(CompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(CompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(CompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(CompletionEntity.class);
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new CompletionEntityBuilder("1").name("Rizwan Idrees").suggest(new String[]{"Rizwan Idrees"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("2").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak", null, 60).buildIndex());
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new CompletionEntityBuilder("1").name("Rizwan Idrees").suggest(new String[]{"Rizwan Idrees"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("2").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("3").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new CompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak").buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(CompletionEntity.class, true);
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(CompletionEntity.class, true);
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntities() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
|
||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||
nonDocumentEntity.setSomeField1("foo");
|
||||
nonDocumentEntity.setSomeField2("bar");
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Rizwan Idrees").suggest(new String[]{"Rizwan", "Idrees"}, "Rizwan Idrees").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak").buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntitiesWithPayloads() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
|
||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||
nonDocumentEntity.setSomeField1("Payload");
|
||||
nonDocumentEntity.setSomeField2("test");
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}, null, Double.MAX_VALUE).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, Long.MAX_VALUE).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, "Payload test").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4").suggest(new String[]{"Mewes Kochheim4"}, null, nonDocumentEntity).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntitiesWithWeights() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Mewes Kochheim1").suggest(new String[]{"Mewes Kochheim1"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mewes Kochheim2").suggest(new String[]{"Mewes Kochheim2"}, null, null, 0).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Mewes Kochheim3").suggest(new String[]{"Mewes Kochheim3"}, null, null, 1).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Mewes Kochheim4").suggest(new String[]{"Mewes Kochheim4"}, null, null, Integer.MAX_VALUE).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPutMappingForGivenEntity() throws Exception {
|
||||
//given
|
||||
Class entity = CompletionEntity.class;
|
||||
elasticsearchTemplate.createIndex(entity);
|
||||
|
||||
//when
|
||||
assertThat(elasticsearchTemplate.putMapping(entity), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingCompletionEntity() {
|
||||
//given
|
||||
loadCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand", "Mohsin Husen"));
|
||||
}
|
||||
|
||||
private void loadAnnotatedCompletionObjectEntities() {
|
||||
elasticsearchTemplate.deleteIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.createIndex(AnnotatedCompletionEntity.class);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
elasticsearchTemplate.putMapping(AnnotatedCompletionEntity.class);
|
||||
@Test
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
NonDocumentEntity nonDocumentEntity = new NonDocumentEntity();
|
||||
nonDocumentEntity.setSomeField1("foo");
|
||||
nonDocumentEntity.setSomeField2("bar");
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
List<IndexQuery> indexQueries = new ArrayList<IndexQuery>();
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("1").name("Franck Marchand").suggest(new String[]{"Franck", "Marchand"}).buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("2").name("Mohsin Husen").suggest(new String[]{"Mohsin", "Husen"}, "Mohsin Husen").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("3").name("Rizwan Idrees").suggest(new String[]{"Rizwan", "Idrees"}, "Rizwan Idrees", "Payload test").buildIndex());
|
||||
indexQueries.add(new AnnotatedCompletionEntityBuilder("4").name("Artur Konczak").suggest(new String[]{"Artur", "Konczak"}, "Artur Konczak", nonDocumentEntity, 60).buildIndex());
|
||||
|
||||
elasticsearchTemplate.bulkIndex(indexQueries);
|
||||
elasticsearchTemplate.refresh(AnnotatedCompletionEntity.class, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldPutMappingForGivenEntity() throws Exception {
|
||||
//given
|
||||
Class entity = CompletionEntity.class;
|
||||
elasticsearchTemplate.createIndex(entity);
|
||||
|
||||
//when
|
||||
assertThat(elasticsearchTemplate.putMapping(entity), is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingCompletionObjectEntity() {
|
||||
//given
|
||||
loadCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand","Mohsin Husen"));
|
||||
}
|
||||
assertThat(options.get(1).getText().string(), isOneOf("Marchand","Mohsin Husen"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsForGivenCriteriaQueryUsingloadAnnotatedCompletionObjectEntity() {
|
||||
//given
|
||||
loadCompletionObjectEntities();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
@Test
|
||||
public void shouldFindSuggestionsWithPayloadsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntitiesWithPayloads();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(2));
|
||||
assertThat(options.get(0).getText().string(), isOneOf("Marchand","Mohsin Husen"));
|
||||
}
|
||||
//then
|
||||
assertThat(options.size(), is(4));
|
||||
for (CompletionSuggestion.Entry.Option option : options) {
|
||||
if (option.getText().string().equals("Mewes Kochheim1")) {
|
||||
assertEquals(Double.MAX_VALUE, option.getPayloadAsDouble(), 0);
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim2")) {
|
||||
assertEquals(Long.MAX_VALUE, option.getPayloadAsLong());
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim3")) {
|
||||
assertEquals("Payload test", option.getPayloadAsString());
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim4")) {
|
||||
assertEquals("Payload", option.getPayloadAsMap().get("someField1"));
|
||||
assertEquals("test", option.getPayloadAsMap().get("someField2"));
|
||||
} else {
|
||||
fail("Unexpected option");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindSuggestionsWithWeightsForGivenCriteriaQueryUsingAnnotatedCompletionEntity() {
|
||||
//given
|
||||
loadAnnotatedCompletionObjectEntitiesWithWeights();
|
||||
CompletionSuggestionFuzzyBuilder completionSuggestionFuzzyBuilder = new CompletionSuggestionFuzzyBuilder("test-suggest")
|
||||
.text("m")
|
||||
.field("suggest");
|
||||
|
||||
//when
|
||||
SuggestResponse suggestResponse = elasticsearchTemplate.suggest(completionSuggestionFuzzyBuilder, CompletionEntity.class);
|
||||
CompletionSuggestion completionSuggestion = suggestResponse.getSuggest().getSuggestion("test-suggest");
|
||||
List<CompletionSuggestion.Entry.Option> options = completionSuggestion.getEntries().get(0).getOptions();
|
||||
|
||||
//then
|
||||
assertThat(options.size(), is(4));
|
||||
for (CompletionSuggestion.Entry.Option option : options) {
|
||||
if (option.getText().string().equals("Mewes Kochheim1")) {
|
||||
assertEquals(4, option.getScore(), 0);
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim2")) {
|
||||
assertEquals(0, option.getScore(), 0);
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim3")) {
|
||||
assertEquals(1, option.getScore(), 0);
|
||||
}
|
||||
else if (option.getText().string().equals("Mewes Kochheim4")) {
|
||||
assertEquals(Integer.MAX_VALUE, option.getScore(), 0);
|
||||
} else {
|
||||
fail("Unexpected option");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user