Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 26709fd

Browse files
Add AOT parameter name detection for search queries.
See: #3265
1 parent 681d85c commit 26709fd

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

‎src/main/java/org/springframework/data/repository/aot/generate/AotQueryMethodGenerationContext.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.List;
2222

2323
import org.jspecify.annotations.Nullable;
24-
2524
import org.springframework.core.ResolvableType;
2625
import org.springframework.core.annotation.MergedAnnotation;
2726
import org.springframework.core.annotation.MergedAnnotationSelectors;
@@ -50,8 +49,8 @@ public class AotQueryMethodGenerationContext {
5049
private final MethodMetadata targetMethodMetadata;
5150
private final VariableNameFactory variableNameFactory;
5251

53-
protected AotQueryMethodGenerationContext(RepositoryInformation repositoryInformation, Method method,QueryMethodqueryMethod,
54-
AotRepositoryFragmentMetadata targetTypeMetadata) {
52+
protected AotQueryMethodGenerationContext(RepositoryInformation repositoryInformation, Method method,
53+
QueryMethodqueryMethod, AotRepositoryFragmentMetadata targetTypeMetadata) {
5554

5655
this.method = method;
5756
this.annotations = MergedAnnotations.from(method);
@@ -270,45 +269,64 @@ public String localVariable(String variableName) {
270269
* @return the parameter name for the {@link org.springframework.data.domain.Sort sort parameter} or {@code null} if
271270
* the method does not declare a sort parameter.
272271
*/
273-
@Nullable
274-
public String getSortParameterName() {
272+
public @Nullable String getSortParameterName() {
275273
return getParameterName(queryMethod.getParameters().getSortIndex());
276274
}
277275

278276
/**
279277
* @return the parameter name for the {@link org.springframework.data.domain.Pageable pageable parameter} or
280278
* {@code null} if the method does not declare a pageable parameter.
281279
*/
282-
@Nullable
283-
public String getPageableParameterName() {
280+
public @Nullable String getPageableParameterName() {
284281
return getParameterName(queryMethod.getParameters().getPageableIndex());
285282
}
286283

287284
/**
288285
* @return the parameter name for the {@link org.springframework.data.domain.Limit limit parameter} or {@code null} if
289286
* the method does not declare a limit parameter.
290287
*/
291-
@Nullable
292-
public String getLimitParameterName() {
288+
public @Nullable String getLimitParameterName() {
293289
return getParameterName(queryMethod.getParameters().getLimitIndex());
294290
}
295291

296292
/**
297293
* @return the parameter name for the {@link org.springframework.data.domain.ScrollPosition scroll position parameter}
298294
* or {@code null} if the method does not declare a scroll position parameter.
299295
*/
300-
@Nullable
301-
public String getScrollPositionParameterName() {
296+
public @Nullable String getScrollPositionParameterName() {
302297
return getParameterName(queryMethod.getParameters().getScrollPositionIndex());
303298
}
304299

305300
/**
306301
* @return the parameter name for the {@link Class dynamic projection parameter} or {@code null} if the method does
307302
* not declare a dynamic projection parameter.
308303
*/
309-
@Nullable
310-
public String getDynamicProjectionParameterName() {
304+
public @Nullable String getDynamicProjectionParameterName() {
311305
return getParameterName(queryMethod.getParameters().getDynamicProjectionIndex());
312306
}
313307

308+
/**
309+
* @return the parameter name for the {@link org.springframework.data.domain.Vector vector parameter} or {@code null}
310+
* if the method does not declare a vector type parameter.
311+
*/
312+
public @Nullable String getVectorParameterName() {
313+
return getParameterName(queryMethod.getParameters().getVectorIndex());
314+
}
315+
316+
/**
317+
* @return the parameter name for the {@link org.springframework.data.domain.Score score parameter} or {@code null} if
318+
* the method does not declare a score type parameter.
319+
*/
320+
public @Nullable String getScoreParameterName() {
321+
return getParameterName(queryMethod.getParameters().getScoreIndex());
322+
}
323+
324+
/**
325+
* @return the parameter name for the {@link org.springframework.data.domain.Range score range parameter} or
326+
* {@code null} if the method does not declare a score range type parameter.
327+
*/
328+
public @Nullable String getScoreRangeParameterName() {
329+
return getParameterName(queryMethod.getParameters().getScoreRangeIndex());
330+
}
331+
314332
}

‎src/test/java/org/springframework/data/repository/aot/generate/AotQueryMethodGenerationContextUnitTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
import org.springframework.data.domain.Limit;
2626
import org.springframework.data.domain.Page;
2727
import org.springframework.data.domain.Pageable;
28+
import org.springframework.data.domain.Range;
29+
import org.springframework.data.domain.Score;
2830
import org.springframework.data.domain.ScrollPosition;
31+
import org.springframework.data.domain.SearchResults;
32+
import org.springframework.data.domain.Vector;
2933
import org.springframework.data.domain.Window;
3034
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
3135
import org.springframework.data.repository.Repository;
@@ -74,6 +78,19 @@ void returnsCorrectParameterNameForPageable() throws NoSuchMethodException {
7478
assertThat(ctx.getDynamicProjectionParameterName()).isNull();
7579
}
7680

81+
@Test // GH-3265
82+
void returnsCorrectParameterNamesForVectorSearch() throws NoSuchMethodException {
83+
84+
AotQueryMethodGenerationContext ctx = ctxFor("searchAllNearWithScore");
85+
86+
assertThat(ctx.getVectorParameterName()).isEqualTo("vEctOR");
87+
assertThat(ctx.getScoreParameterName()).isEqualTo("distance");
88+
89+
ctx = ctxFor("searchAllNearInRange");
90+
91+
assertThat(ctx.getScoreRangeParameterName()).isEqualTo("rDistance");
92+
}
93+
7794
AotQueryMethodGenerationContext ctxFor(String methodName) throws NoSuchMethodException {
7895

7996
Method target = null;
@@ -105,5 +122,9 @@ private interface DummyRepo extends Repository<String, Long> {
105122
<T> Window<T> limitScrollPositionDynamicProjection(Limit l, ScrollPosition sp, Class<T> projection);
106123

107124
Page<String> pageable(Pageable p);
125+
126+
SearchResults<String> searchAllNearWithScore(Vector vEctOR, Score distance, Limit limit);
127+
128+
SearchResults<String> searchAllNearInRange(Vector vEctOR, Range<Score> rDistance, Limit limit);
108129
}
109130
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /