DATACMNS-1645 - Add search prefix for part tree queries.
We're adding search as prefix for derived repository query methods to improve readability when a Spring Data module is integrated with a search engine. Now it's possible to create a `search…By…` query like `searchByFirstname`.
This commit is contained in:
@@ -57,7 +57,7 @@ public class PartTree implements Streamable<OrPart> {
|
||||
* @see <a href="https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html#ubc">Pattern</a>
|
||||
*/
|
||||
private static final String KEYWORD_TEMPLATE = "(%s)(?=(\\p{Lu}|\\P{InBASIC_LATIN}))";
|
||||
private static final String QUERY_PATTERN = "find|read|get|query|stream";
|
||||
private static final String QUERY_PATTERN = "find|read|get|query|search|stream";
|
||||
private static final String COUNT_PATTERN = "count";
|
||||
private static final String EXISTS_PATTERN = "exists";
|
||||
private static final String DELETE_PATTERN = "delete|remove";
|
||||
|
||||
@@ -50,7 +50,8 @@ import org.springframework.data.repository.query.parser.PartTree.OrPart;
|
||||
*/
|
||||
public class PartTreeUnitTests {
|
||||
|
||||
private String[] PREFIXES = { "find", "read", "get", "query", "stream", "count", "delete", "remove", "exists" };
|
||||
private String[] PREFIXES = { "find", "read", "get", "query", "search", "stream", "count", "delete", "remove",
|
||||
"exists" };
|
||||
|
||||
@Test
|
||||
public void rejectsNullSource() {
|
||||
@@ -400,6 +401,15 @@ public class PartTreeUnitTests {
|
||||
assertThat(parts).containsExactly(part("firstname"), part("lastname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1645
|
||||
public void searchPrefixShouldBeSupportedInRepositoryQueryMethods() {
|
||||
|
||||
PartTree tree = new PartTree("searchByFirstnameAndLastname", User.class);
|
||||
Iterable<Part> parts = tree.getParts();
|
||||
|
||||
assertThat(parts).containsExactly(part("firstname"), part("lastname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-303
|
||||
public void identifiesExtendedCountByCorrectly() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user