DATAES-912 - Derived Query with "In" Keyword does not work on Text field.
Original PR: #510
This commit is contained in:
committed by
GitHub
parent
4ef442966f
commit
79fdc449b8
@@ -197,14 +197,22 @@ class ElasticsearchPartQueryTests {
|
||||
|
||||
String query = getQueryBuilder(methodName, parameterClasses, parameters);
|
||||
|
||||
String expected = "{\"query\": {" + //
|
||||
" \"bool\" : {" + //
|
||||
" \"must\" : [" + //
|
||||
" {\"bool\" : {\"must\" : [{\"terms\" : {\"name\" : [\"" + names.get(0) + "\", \"" + names.get(1)
|
||||
+ "\"]}}]}}" + //
|
||||
" ]" + //
|
||||
" }" + //
|
||||
"}}"; //
|
||||
String expected = "{\n" + //
|
||||
" \"query\": {\n" + //
|
||||
" \"bool\": {\n" + //
|
||||
" \"must\": [\n" + //
|
||||
" {\n" + //
|
||||
" \"query_string\": {\n" + //
|
||||
" \"query\": \"\\\"Title\\\" \\\"Title2\\\"\",\n" + //
|
||||
" \"fields\": [\n" + //
|
||||
" \"name^1.0\"\n" + //
|
||||
" ]\n" + //
|
||||
" }\n" + //
|
||||
" }\n" + //
|
||||
" ]\n" + //
|
||||
" }\n" + //
|
||||
" }\n" + //
|
||||
"}\n"; //
|
||||
|
||||
assertEquals(expected, query, false);
|
||||
}
|
||||
@@ -220,14 +228,22 @@ class ElasticsearchPartQueryTests {
|
||||
|
||||
String query = getQueryBuilder(methodName, parameterClasses, parameters);
|
||||
|
||||
String expected = "{\"query\": {" + //
|
||||
" \"bool\" : {" + //
|
||||
" \"must\" : [" + //
|
||||
" {\"bool\" : {\"must_not\" : [{\"terms\" : {\"name\" : [\"" + names.get(0) + "\", \"" + names.get(1)
|
||||
+ "\"]}}]}}" + //
|
||||
" ]" + //
|
||||
" }" + //
|
||||
"}}"; //
|
||||
String expected = "{\n" + //
|
||||
" \"query\": {\n" + //
|
||||
" \"bool\": {\n" + //
|
||||
" \"must\": [\n" + //
|
||||
" {\n" + //
|
||||
" \"query_string\": {\n" + //
|
||||
" \"query\": \"NOT(\\\"Title\\\" \\\"Title2\\\")\",\n" + //
|
||||
" \"fields\": [\n" + //
|
||||
" \"name^1.0\"\n" + //
|
||||
" ]\n" + //
|
||||
" }\n" + //
|
||||
" }\n" + //
|
||||
" ]\n" + //
|
||||
" }\n" + //
|
||||
" }\n" + //
|
||||
"}\n"; //
|
||||
|
||||
assertEquals(expected, query, false);
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-647
|
||||
public void shouldHandleManyValuesQueryingIn() {
|
||||
public void shouldHandleManyKeywordValuesQueryingIn() {
|
||||
|
||||
// given
|
||||
String documentId1 = nextIdAsString();
|
||||
@@ -378,7 +378,8 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
List<String> keywords = new ArrayList<>();
|
||||
keywords.add("foo");
|
||||
|
||||
for (int i = 0; i < 1025; i++) {
|
||||
// limit for normal query clauses is 1024, for keywords we change to terms queries
|
||||
for (int i = 0; i < 1200; i++) {
|
||||
keywords.add(nextIdAsString());
|
||||
}
|
||||
|
||||
@@ -391,7 +392,7 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
}
|
||||
|
||||
@Test // DATAES-647
|
||||
public void shouldHandleManyValuesQueryingNotIn() {
|
||||
public void shouldHandleManyKeywordValuesQueryingNotIn() {
|
||||
|
||||
// given
|
||||
String documentId1 = nextIdAsString();
|
||||
@@ -409,7 +410,8 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
List<String> keywords = new ArrayList<>();
|
||||
keywords.add("foo");
|
||||
|
||||
for (int i = 0; i < 1025; i++) {
|
||||
// limit for normal query clauses is 1024, for keywords we change to terms queries
|
||||
for (int i = 0; i < 1200; i++) {
|
||||
keywords.add(nextIdAsString());
|
||||
}
|
||||
|
||||
@@ -421,6 +423,46 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
assertThat(list.get(0).getId()).isEqualTo(documentId2);
|
||||
}
|
||||
|
||||
@Test // DATAES-912
|
||||
void shouldHandleTextFieldQueryingIn() {
|
||||
String documentId1 = nextIdAsString();
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("foo");
|
||||
repository.save(sampleEntity1);
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
List<SampleEntity> list = repository.findByMessageIn(Arrays.asList("Foo", "Bar"));
|
||||
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list.stream().map(SampleEntity::getId)).containsExactlyInAnyOrder(documentId1, documentId2);
|
||||
}
|
||||
|
||||
@Test // DATAES-912
|
||||
void shouldHandleTextFieldQueryingNotIn() {
|
||||
String documentId1 = nextIdAsString();
|
||||
SampleEntity sampleEntity1 = new SampleEntity();
|
||||
sampleEntity1.setId(documentId1);
|
||||
sampleEntity1.setMessage("foo");
|
||||
repository.save(sampleEntity1);
|
||||
|
||||
String documentId2 = nextIdAsString();
|
||||
SampleEntity sampleEntity2 = new SampleEntity();
|
||||
sampleEntity2.setId(documentId2);
|
||||
sampleEntity2.setMessage("bar");
|
||||
repository.save(sampleEntity2);
|
||||
|
||||
List<SampleEntity> list = repository.findByMessageNotIn(Arrays.asList("Boo", "Bar"));
|
||||
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0).getId()).isEqualTo(documentId1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCustomMethodForTrue() {
|
||||
|
||||
@@ -1622,6 +1664,10 @@ public abstract class CustomMethodRepositoryBaseTests {
|
||||
|
||||
List<SampleEntity> findByKeywordNotIn(List<String> keywords);
|
||||
|
||||
List<SampleEntity> findByMessageIn(List<String> keywords);
|
||||
|
||||
List<SampleEntity> findByMessageNotIn(List<String> keywords);
|
||||
|
||||
Page<SampleEntity> findByIdNotIn(List<String> ids, Pageable pageable);
|
||||
|
||||
Page<SampleEntity> findByAvailableTrue(Pageable pageable);
|
||||
|
||||
Reference in New Issue
Block a user