Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kderusso committed Dec 2, 2024
1 parent a1c3e66 commit bcb93c3
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class InferenceQueryBuilderService {
}

public AbstractQueryBuilder<?> getDefaultInferenceQueryBuilder(String fieldName, String query, boolean throwOnUnsupportedQueries) {
return defaultInferenceQueryBuilder.apply(fieldName, query, throwOnUnsupportedQueries);
return defaultInferenceQueryBuilder != null
? defaultInferenceQueryBuilder.apply(fieldName, query, throwOnUnsupportedQueries)
: null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ public InferenceQueryBuilderService build() {
}
}

if (definedInferenceQueryBuilders.isEmpty()) {
// Backwards compatibility
return new InferenceQueryBuilderService(null);
}

if (definedInferenceQueryBuilders.size() != 1) {
throw new IllegalStateException(
"Expected exactly one default inference query builder, but found " + definedInferenceQueryBuilders.size()
"Expected a single default inference query builder, but found " + definedInferenceQueryBuilders.size()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,12 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) throws
}

private QueryBuilder createInferenceSubQuery(InferenceQueryBuilderService inferenceQueryBuilderService, String indexName) {
QueryBuilder inferenceClause = inferenceQueryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString(), false);
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(inferenceQueryBuilderService.getDefaultInferenceQueryBuilder(fieldName, value.toString(), false));
boolQueryBuilder.filter(new TermQueryBuilder(IndexFieldMapper.NAME, indexName));
if (inferenceClause != null) {
boolQueryBuilder.must(inferenceClause);
boolQueryBuilder.filter(new TermQueryBuilder(IndexFieldMapper.NAME, indexName));
}
return boolQueryBuilder;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ public InferenceFieldMetadata getMetadata(Set<String> sourcePaths) {
String[] copyFields = sourcePaths.toArray(String[]::new);
// ensure consistent order
Arrays.sort(copyFields);
return new InferenceFieldMetadata(fullPath(), fieldType().inferenceId, fieldType().searchInferenceId, copyFields);
return new InferenceFieldMetadata(fullPath(), fieldType().getInferenceId(), fieldType().getSearchInferenceId(), copyFields);
}

@Override
Expand Down Expand Up @@ -441,7 +441,7 @@ public SemanticTextFieldType(
) {
super(name, true, false, false, TextSearchInfo.NONE, meta);
this.inferenceId = inferenceId;
this.searchInferenceId = searchInferenceId == null ? inferenceId : searchInferenceId;
this.searchInferenceId = searchInferenceId;
;
this.modelSettings = modelSettings;
this.inferenceField = inferenceField;
Expand All @@ -458,7 +458,7 @@ public String getInferenceId() {
}

public String getSearchInferenceId() {
return searchInferenceId;
return searchInferenceId == null ? inferenceId : searchInferenceId;
}

public SemanticTextField.ModelSettings getModelSettings() {
Expand Down

0 comments on commit bcb93c3

Please sign in to comment.