mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-16 09:02:24 +00:00
DATAES-552 - @Query annotation fail when passing over 10 parameters
Updated the replacePlaceholders methods to use replaceFirst to prevent duplication substitutions. Original Pull Request: #267
This commit is contained in:
parent
16bf8450f0
commit
b93bd07a3a
@ -32,6 +32,7 @@ import org.springframework.util.Assert;
|
|||||||
* @author Rizwan Idrees
|
* @author Rizwan Idrees
|
||||||
* @author Mohsin Husen
|
* @author Mohsin Husen
|
||||||
* @author Mark Paluch
|
* @author Mark Paluch
|
||||||
|
* @author Taylor Ono
|
||||||
*/
|
*/
|
||||||
public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQuery {
|
public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQuery {
|
||||||
|
|
||||||
@ -86,8 +87,9 @@ public class ElasticsearchStringQuery extends AbstractElasticsearchRepositoryQue
|
|||||||
String result = input;
|
String result = input;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group();
|
String group = matcher.group();
|
||||||
|
group = "\\" + group;
|
||||||
int index = Integer.parseInt(matcher.group(1));
|
int index = Integer.parseInt(matcher.group(1));
|
||||||
result = result.replace(group, getParameterWithIndex(accessor, index));
|
result = result.replaceFirst(group, getParameterWithIndex(accessor, index));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import org.springframework.util.ObjectUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Christoph Strobl
|
* @author Christoph Strobl
|
||||||
|
* @author Taylor Ono
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public class ReactiveElasticsearchStringQuery extends AbstractReactiveElasticsearchRepositoryQuery {
|
public class ReactiveElasticsearchStringQuery extends AbstractReactiveElasticsearchRepositoryQuery {
|
||||||
@ -60,8 +61,9 @@ public class ReactiveElasticsearchStringQuery extends AbstractReactiveElasticsea
|
|||||||
String result = input;
|
String result = input;
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
String group = matcher.group();
|
String group = matcher.group();
|
||||||
|
group = "\\" + group;
|
||||||
int index = Integer.parseInt(matcher.group(1));
|
int index = Integer.parseInt(matcher.group(1));
|
||||||
result = result.replace(group, getParameterWithIndex(accessor, index));
|
result = result.replaceFirst(group, getParameterWithIndex(accessor, index));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,20 @@ public class ReactiveElasticsearchStringQueryUnitTests {
|
|||||||
assertThat(((StringQuery) query).getSource()).isEqualTo(reference.getSource());
|
assertThat(((StringQuery) query).getSource()).isEqualTo(reference.getSource());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test // DATAES-552
|
||||||
|
public void shouldReplaceLotsOfParametersCorrectly() throws Exception {
|
||||||
|
|
||||||
|
ReactiveElasticsearchStringQuery elasticsearchStringQuery = createQueryForMethod("findWithQuiteSomeParameters",
|
||||||
|
String.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class,
|
||||||
|
String.class, String.class, String.class, String.class);
|
||||||
|
StubParameterAccessor accesor = new StubParameterAccessor("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
|
||||||
|
"l");
|
||||||
|
org.springframework.data.elasticsearch.core.query.Query query = elasticsearchStringQuery.createQuery(accesor);
|
||||||
|
StringQuery reference = new StringQuery("name:(a, b, c, d, e, f, g, h, i, j, k, l)");
|
||||||
|
assertThat(query).isInstanceOf(StringQuery.class);
|
||||||
|
assertThat(((StringQuery) query).getSource()).isEqualTo(reference.getSource());
|
||||||
|
}
|
||||||
|
|
||||||
private ReactiveElasticsearchStringQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception {
|
private ReactiveElasticsearchStringQuery createQueryForMethod(String name, Class<?>... parameters) throws Exception {
|
||||||
|
|
||||||
Method method = SampleRepository.class.getMethod(name, parameters);
|
Method method = SampleRepository.class.getMethod(name, parameters);
|
||||||
@ -104,5 +118,9 @@ public class ReactiveElasticsearchStringQueryUnitTests {
|
|||||||
|
|
||||||
@Query("{ 'bool' : { 'must' : { 'term' : { 'name' : '?#{[0]}' } } } }")
|
@Query("{ 'bool' : { 'must' : { 'term' : { 'name' : '?#{[0]}' } } } }")
|
||||||
Flux<Person> findByNameWithExpression(String param0);
|
Flux<Person> findByNameWithExpression(String param0);
|
||||||
|
|
||||||
|
@Query(value = "name:(?0, ?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11)")
|
||||||
|
Person findWithQuiteSomeParameters(String arg0, String arg1, String arg2, String arg3, String arg4, String arg5,
|
||||||
|
String arg6, String arg7, String arg8, String arg9, String arg10, String arg11);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user