Skip to content

Commit

Permalink
Switch type of expandNested from boolean to Boolean (#2333)
Browse files Browse the repository at this point in the history
Signed-off-by: Heemin Kim <[email protected]>
  • Loading branch information
heemin32 authored Dec 14, 2024
1 parent 8005bbf commit aa6936a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static class CreateQueryRequest {
private QueryBuilder filter;
private QueryShardContext context;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Optional<QueryBuilder> getFilter() {
return Optional.ofNullable(filter);
Expand All @@ -63,6 +63,10 @@ public Optional<QueryShardContext> getContext() {
public Optional<RescoreContext> getRescoreContext() {
return Optional.ofNullable(rescoreContext);
}

public Optional<Boolean> getExpandNested() {
return Optional.ofNullable(expandNested);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class KNNQueryBuilder extends AbstractQueryBuilder<KNNQueryBuilder> {
@Getter
private RescoreContext rescoreContext;
@Getter
private boolean expandNested;
private Boolean expandNested;

/**
* Constructs a new query with the given field name and vector
Expand Down Expand Up @@ -151,7 +151,7 @@ public static class Builder {
private String queryName;
private float boost = DEFAULT_BOOST;
private RescoreContext rescoreContext;
private boolean expandNested;
private Boolean expandNested;

public Builder() {}

Expand Down Expand Up @@ -210,7 +210,7 @@ public Builder rescoreContext(RescoreContext rescoreContext) {
return this;
}

public Builder expandNested(boolean expandNested) {
public Builder expandNested(Boolean expandNested) {
this.expandNested = expandNested;
return this;
}
Expand Down Expand Up @@ -330,7 +330,7 @@ public KNNQueryBuilder(String fieldName, float[] vector, int k, QueryBuilder fil
this.maxDistance = null;
this.minScore = null;
this.rescoreContext = null;
this.expandNested = false;
this.expandNested = null;
}

public static void initialize(ModelDao modelDao) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static Query create(CreateQueryRequest createQueryRequest) {
final Map<String, ?> methodParameters = createQueryRequest.getMethodParameters();
final RescoreContext rescoreContext = createQueryRequest.getRescoreContext().orElse(null);
final KNNEngine knnEngine = createQueryRequest.getKnnEngine();
final boolean expandNested = createQueryRequest.isExpandNested();
final boolean expandNested = createQueryRequest.getExpandNested().orElse(false);
BitSetProducer parentFilter = null;
if (createQueryRequest.getContext().isPresent()) {
QueryShardContext context = createQueryRequest.getContext().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static KNNQueryBuilder.Builder streamInput(StreamInput in, Function<Strin
}

if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
builder.expandNested(in.readBoolean());
builder.expandNested(in.readOptionalBoolean());
}

return builder;
Expand Down Expand Up @@ -169,7 +169,7 @@ public static void streamOutput(StreamOutput out, KNNQueryBuilder builder, Funct
RescoreParser.streamOutput(out, builder.getRescoreContext());
}
if (minClusterVersionCheck.apply(EXPAND_NESTED)) {
out.writeBoolean(builder.isExpandNested());
out.writeOptionalBoolean(builder.getExpandNested());
}
}

Expand Down Expand Up @@ -245,8 +245,8 @@ public static void toXContent(XContentBuilder builder, ToXContent.Params params,
if (knnQueryBuilder.queryName() != null) {
builder.field(NAME_FIELD.getPreferredName(), knnQueryBuilder.queryName());
}
if (knnQueryBuilder.isExpandNested()) {
builder.field(EXPAND_NESTED, knnQueryBuilder.isExpandNested());
if (knnQueryBuilder.getExpandNested() != null) {
builder.field(EXPAND_NESTED, knnQueryBuilder.getExpandNested());
}

builder.endObject();
Expand Down

0 comments on commit aa6936a

Please sign in to comment.