Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow getting schema field name #3576

Merged
merged 1 commit into from
Oct 11, 2023
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
8 changes: 8 additions & 0 deletions src/main/java/redis/clients/jedis/search/FieldName.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public FieldName as(String attribute) {
return this;
}

public final String getName() {
return name;
}

public final String getAttribute() {
return attribute;
}

public int addCommandArguments(List<Object> args) {
args.add(name);
if (attribute == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ public SchemaField as(String attribute) {
fieldName.as(attribute);
return this;
}

public final FieldName getFieldName() {
return fieldName;
}

public final String getName() {
return fieldName.getName();
}
}
16 changes: 16 additions & 0 deletions src/test/java/redis/clients/jedis/modules/search/UtilTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package redis.clients.jedis.modules.search;

import static org.junit.Assert.assertEquals;

import org.junit.Assert;
import org.junit.Test;

import redis.clients.jedis.search.RediSearchUtil;

import redis.clients.jedis.search.schemafields.NumericField;
import redis.clients.jedis.search.schemafields.SchemaField;

public class UtilTest {

@Test
Expand All @@ -13,4 +19,14 @@ public void floatArrayToByteArray() {
byte[] expected = new byte[]{-51, -52, 76, 62};
Assert.assertArrayEquals(expected, bytes);
}

@Test
public void getSchemaFieldName() {
SchemaField field = NumericField.of("$.num").as("num");

assertEquals("$.num", field.getFieldName().getName());
assertEquals("num", field.getFieldName().getAttribute());

assertEquals("$.num", field.getName());
}
}
Loading