From 0c0a239bb7045d6e3d2cd3b84dfc17ff77a724b4 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Thu, 12 Oct 2023 00:33:06 +0600 Subject: [PATCH] Allow getting schema field name --- .../redis/clients/jedis/search/FieldName.java | 8 ++++++++ .../jedis/search/schemafields/SchemaField.java | 8 ++++++++ .../clients/jedis/modules/search/UtilTest.java | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/src/main/java/redis/clients/jedis/search/FieldName.java b/src/main/java/redis/clients/jedis/search/FieldName.java index 452b0b8d61f..9a0a9329db0 100644 --- a/src/main/java/redis/clients/jedis/search/FieldName.java +++ b/src/main/java/redis/clients/jedis/search/FieldName.java @@ -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 args) { args.add(name); if (attribute == null) { diff --git a/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java b/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java index 473baea4726..8678780da25 100644 --- a/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java +++ b/src/main/java/redis/clients/jedis/search/schemafields/SchemaField.java @@ -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(); + } } diff --git a/src/test/java/redis/clients/jedis/modules/search/UtilTest.java b/src/test/java/redis/clients/jedis/modules/search/UtilTest.java index efd9ff4726b..830b52565af 100644 --- a/src/test/java/redis/clients/jedis/modules/search/UtilTest.java +++ b/src/test/java/redis/clients/jedis/modules/search/UtilTest.java @@ -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 @@ -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()); + } }