Skip to content

Commit

Permalink
Simplify condition check logic
Browse files Browse the repository at this point in the history
Signed-off-by: Junqiu Lei <[email protected]>
  • Loading branch information
junqiu-lei committed Jun 19, 2024
1 parent 26ec968 commit 067cdc6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,9 @@ protected Query doToQuery(QueryShardContext context) {
final String method = methodComponentContext != null ? methodComponentContext.getName() : null;
if (StringUtils.isNotBlank(method)) {
final EngineSpecificMethodContext engineSpecificMethodContext = knnEngine.getMethodContext(method);
KNNEngine finalKnnEngine = knnEngine;
QueryContext methodContext = () -> (vectorQueryType.isRadialSearch() && KNNEngine.LUCENE.equals(finalKnnEngine)) == false;
QueryContext queryContext = new QueryContext(vectorQueryType);
ValidationException validationException = validateParameters(
engineSpecificMethodContext.supportedMethodParameters(methodContext),
engineSpecificMethodContext.supportedMethodParameters(queryContext),
(Map<String, Object>) methodParameters
);
if (validationException != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public class LuceneHNSWContext implements EngineSpecificMethodContext {

@Override
public Map<String, Parameter<?>> supportedMethodParameters(QueryContext ctx) {
if (ctx.is_ef_search_parameter_supported()) {
// Return the supported method parameters for non-radial cases
return supportedMethodParameters;
if (ctx.queryType.isRadialSearch()) {
// return empty map if radial search is true
return Collections.emptyMap();
}
// return empty map if radial search is true
return Collections.emptyMap();
// Return the supported method parameters for non-radial cases
return supportedMethodParameters;
}
}
10 changes: 7 additions & 3 deletions src/main/java/org/opensearch/knn/index/util/QueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@

package org.opensearch.knn.index.util;

import lombok.AllArgsConstructor;
import org.opensearch.knn.index.VectorQueryType;

/**
* Context interface for query-specific information.
* Context class for query-specific information.
*/
public interface QueryContext {
boolean is_ef_search_parameter_supported();
@AllArgsConstructor
public class QueryContext {
VectorQueryType queryType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public ValidationException validate(KNNMethodContext knnMethodContext) {

public void testEngineSpecificMethods() {
String methodName1 = "test-method-1";
QueryContext engineSpecificMethodContext = () -> false;
QueryContext engineSpecificMethodContext = new QueryContext(VectorQueryType.K);
EngineSpecificMethodContext context = ctx -> ImmutableMap.of(
"myparameter",
new Parameter.BooleanParameter("myparameter", null, value -> true)
Expand Down

0 comments on commit 067cdc6

Please sign in to comment.