Skip to content

Commit b3fb592

Browse files
HNSW index: add generic setParameter(float[]) method
1 parent c2c516b commit b3fb592

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

objectbox-java/src/main/java/io/objectbox/Property.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,12 @@
4040
import io.objectbox.query.PropertyQueryConditionImpl.StringCondition;
4141
import io.objectbox.query.PropertyQueryConditionImpl.StringCondition.Operation;
4242
import io.objectbox.query.PropertyQueryConditionImpl.StringStringCondition;
43+
import io.objectbox.query.Query;
4344
import io.objectbox.query.QueryBuilder.StringOrder;
4445

4546
/**
4647
* Meta data describing a Property of an ObjectBox Entity.
47-
* Properties are typically used when defining {@link io.objectbox.query.Query Query} conditions
48+
* Properties are typically used when defining {@link Query Query} conditions
4849
* using {@link io.objectbox.query.QueryBuilder QueryBuilder}.
4950
* Access properties using the generated underscore class of an entity (e.g. {@code Example_.id}).
5051
*/
@@ -315,6 +316,9 @@ public PropertyQueryCondition<ENTITY> between(double lowerBoundary, double upper
315316
* be used as the "ef" HNSW parameter to increase the search quality in combination with a query limit. For example,
316317
* use maxResultCount of 100 with a Query limit of 10 to have 10 results that are of potentially better quality than
317318
* just passing in 10 for maxResultCount (quality/performance tradeoff).
319+
* <p>
320+
* To change the given parameters after building the query, use {@link Query#setParameter(Property, float[])} and
321+
* {@link Query#setParameter(Property, long)} or their alias equivalent.
318322
*/
319323
public PropertyQueryCondition<ENTITY> nearestNeighbors(float[] queryVector, int maxResultCount) {
320324
return new NearestNeighborCondition<>(this, queryVector, maxResultCount);

objectbox-java/src/main/java/io/objectbox/query/Query.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,30 @@ public Query<T> setParameter(String alias, boolean value) {
655655
return setParameter(alias, value ? 1 : 0);
656656
}
657657

658+
/**
659+
* Changes the parameter of the query condition for {@code property} to a new {@code value}.
660+
*
661+
* @param property Property reference from generated entity underscore class, like {@code Example_.example}.
662+
* @param value The new {@code float[]} value to use for the query condition.
663+
*/
664+
public Query<T> setParameter(Property<?> property, float[] value) {
665+
checkOpen();
666+
nativeSetParameter(handle, property.getEntityId(), property.getId(), null, value);
667+
return this;
668+
}
669+
670+
/**
671+
* Changes the parameter of the query condition with the matching {@code alias} to a new {@code value}.
672+
*
673+
* @param alias as defined using {@link PropertyQueryCondition#alias(String)}.
674+
* @param value The new {@code float[]} value to use for the query condition.
675+
*/
676+
public Query<T> setParameter(String alias, float[] value) {
677+
checkOpen();
678+
nativeSetParameter(handle, 0, 0, alias, value);
679+
return this;
680+
}
681+
658682
/**
659683
* Sets a parameter previously given to the {@link QueryBuilder} to new values.
660684
*/
@@ -795,30 +819,6 @@ public Query<T> setParameter(String alias, byte[] value) {
795819
return this;
796820
}
797821

798-
/**
799-
* Sets parameters previously given to {@link Property#nearestNeighbors(float[], int)}.
800-
*
801-
* @param property Property reference from generated entity underscore class, like {@code Example_.example}.
802-
*/
803-
public Query<T> setParametersNearestNeighbors(Property<?> property, float[] queryVector, int maxResultCount) {
804-
checkOpen();
805-
nativeSetParameter(handle, property.getEntityId(), property.getId(), null, queryVector);
806-
nativeSetParameter(handle, property.getEntityId(), property.getId(), null, maxResultCount);
807-
return this;
808-
}
809-
810-
/**
811-
* Sets parameters previously given to {@link Property#nearestNeighbors(float[], int)}.
812-
*
813-
* @param alias as defined using {@link PropertyQueryCondition#alias(String)}.
814-
*/
815-
public Query<T> setParametersNearestNeighbors(String alias, float[] queryVector, int maxResultCount) {
816-
checkOpen();
817-
nativeSetParameter(handle, 0, 0, alias, queryVector);
818-
nativeSetParameter(handle, 0, 0, alias, maxResultCount);
819-
return this;
820-
}
821-
822822
/**
823823
* Removes (deletes) all Objects matching the query
824824
*

0 commit comments

Comments
 (0)