Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions core/src/main/java/com/redis/vl/schema/NumericField.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,22 @@
@Getter
public class NumericField extends BaseField {

/** Un-normalized form - disable normalization for sorting (only applies when sortable=true) */
private final boolean unf;

/**
* Create a NumericField with just a name.
*
* @param name The field name
*/
public NumericField(String name) {
super(name);
this(name, null, true, false, false);
}

/** Create a NumericField with all properties */
private NumericField(String name, String alias, Boolean indexed, Boolean sortable) {
private NumericField(String name, String alias, Boolean indexed, Boolean sortable, Boolean unf) {
super(name, alias, indexed != null ? indexed : true, sortable != null ? sortable : false);
this.unf = unf != null ? unf : false;
}

/**
Expand Down Expand Up @@ -59,6 +63,9 @@ public SchemaField toJedisSchemaField() {

if (sortable) {
jedisField.sortable();
// NOTE: Jedis NumericField doesn't support sortableUNF() yet
// The unf flag is stored in this wrapper but cannot be passed to Redis via Jedis
// TODO: File issue with Jedis to add sortableUNF() support for NumericField
}

if (!indexed) {
Expand All @@ -74,6 +81,7 @@ public static class NumericFieldBuilder {
private String alias;
private Boolean indexed;
private Boolean sortable;
private Boolean unf;

private NumericFieldBuilder(String name) {
this.name = name;
Expand Down Expand Up @@ -144,6 +152,39 @@ public NumericFieldBuilder sortable() {
return this;
}

/**
* Set whether to use un-normalized form for sorting
*
* <p>UNF disables normalization when sorting, preserving original values. Only applies when
* sortable=true.
*
* <p>NOTE: Jedis doesn't support sortableUNF() for NumericField yet, so this flag is stored but
* not passed to Redis.
*
* @param unf True to disable normalization for sorting
* @return This builder for chaining
*/
public NumericFieldBuilder unf(boolean unf) {
this.unf = unf;
return this;
}

/**
* Use un-normalized form for sorting (equivalent to unf(true))
*
* <p>UNF disables normalization when sorting, preserving original values. Only applies when
* sortable=true.
*
* <p>NOTE: Jedis doesn't support sortableUNF() for NumericField yet, so this flag is stored but
* not passed to Redis.
*
* @return This builder for chaining
*/
public NumericFieldBuilder unf() {
this.unf = true;
return this;
}

/**
* Build the NumericField instance.
*
Expand All @@ -154,7 +195,7 @@ public NumericField build() {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Field name cannot be null or empty");
}
return new NumericField(name, alias, indexed, sortable);
return new NumericField(name, alias, indexed, sortable, unf);
}
}
}
46 changes: 42 additions & 4 deletions core/src/main/java/com/redis/vl/schema/TextField.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ public class TextField extends BaseField {
@JsonProperty("phonetic")
private final String phonetic;

/** Un-normalized form - disable normalization for sorting (only applies when sortable=true) */
@JsonProperty("unf")
private final boolean unf;

/**
* Create a TextField with just a name
*
* @param name Field name
*/
public TextField(String name) {
this(name, null, true, false, 1.0, false, null);
this(name, null, true, false, 1.0, false, null, false);
}

/** Create a TextField with all properties */
Expand All @@ -40,11 +44,13 @@ private TextField(
Boolean sortable,
Double weight,
Boolean noStem,
String phonetic) {
String phonetic,
Boolean unf) {
super(name, alias, indexed != null ? indexed : true, sortable != null ? sortable : false);
this.weight = weight != null ? weight : 1.0;
this.noStem = noStem != null ? noStem : false;
this.phonetic = phonetic;
this.unf = unf != null ? unf : false;
}

/**
Expand Down Expand Up @@ -80,7 +86,11 @@ public SchemaField toJedisSchemaField() {
jedisField.as(alias);
}

if (sortable) {
// Handle sortable with UNF support
// UNF only applies when sortable=true
if (sortable && unf) {
jedisField.sortableUNF();
} else if (sortable) {
jedisField.sortable();
}

Expand Down Expand Up @@ -112,6 +122,7 @@ public static class TextFieldBuilder {
private Double weight;
private Boolean noStem;
private String phonetic;
private Boolean unf;

private TextFieldBuilder(String name) {
this.name = name;
Expand Down Expand Up @@ -247,6 +258,33 @@ public TextFieldBuilder withPhonetic(String phonetic) {
return this;
}

/**
* Set whether to use un-normalized form for sorting
*
* <p>UNF disables normalization when sorting, preserving original character case. Only applies
* when sortable=true.
*
* @param unf True to disable normalization for sorting
* @return This builder
*/
public TextFieldBuilder unf(boolean unf) {
this.unf = unf;
return this;
}

/**
* Use un-normalized form for sorting (equivalent to unf(true))
*
* <p>UNF disables normalization when sorting, preserving original character case. Only applies
* when sortable=true.
*
* @return This builder
*/
public TextFieldBuilder unf() {
this.unf = true;
return this;
}

/**
* Build the TextField
*
Expand All @@ -256,7 +294,7 @@ public TextField build() {
if (name == null || name.trim().isEmpty()) {
throw new IllegalArgumentException("Field name cannot be null or empty");
}
return new TextField(name, alias, indexed, sortable, weight, noStem, phonetic);
return new TextField(name, alias, indexed, sortable, weight, noStem, phonetic, unf);
}
}
}
Loading