From 3b7f59bd8d0f7fd1ab3751284a5dd21999746605 Mon Sep 17 00:00:00 2001 From: Luke Morfill Date: Sat, 20 Jul 2024 18:31:57 +0100 Subject: [PATCH] Set the correct length of parameters when constructing arguments --- .../redis/datasource/search/QueryArgs.java | 2 +- .../redis/datasource/SearchCommandsTest.java | 23 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java index 18f1b65106cb9..3656474dd588a 100644 --- a/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java +++ b/extensions/redis-client/runtime/src/main/java/io/quarkus/redis/datasource/search/QueryArgs.java @@ -545,7 +545,7 @@ public List toArgs(Codec encoder) { if (!params.isEmpty() || !byteArrayParams.isEmpty()) { list.add("PARAMS"); - list.add(Integer.toString(params.size() + byteArrayParams.size())); + list.add(Integer.toString((params.size() + byteArrayParams.size()) * 2)); for (Map.Entry entry : byteArrayParams.entrySet()) { list.add(entry.getKey()); list.add(entry.getValue()); diff --git a/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/SearchCommandsTest.java b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/SearchCommandsTest.java index cb3b5bbefa17e..7a2bde6375151 100644 --- a/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/SearchCommandsTest.java +++ b/extensions/redis-client/runtime/src/test/java/io/quarkus/redis/datasource/SearchCommandsTest.java @@ -736,6 +736,25 @@ void testTagVals() { assertThatThrownBy(() -> search.ftTagVals("idx:movie", "title")); } + @Test + void testParams() { + setupMovies(); + + QueryArgs queryArgs = new QueryArgs().param("GENRE", "Action").dialect(2); + var res = search.ftSearch("idx:movie", "@genre:{$GENRE}", queryArgs); + assertThat(res.count()).isEqualTo(2); + assertThat(res.documents()).allSatisfy(doc -> assertThat(doc.property("genre").asString()).isEqualTo("Action")); + + queryArgs = new QueryArgs().param("LOWEST_RATING", "8").param("HIGHEST_RATING", "9"); + queryArgs.dialect(2); + res = search.ftSearch("idx:movie", "@rating: [$LOWEST_RATING, $HIGHEST_RATING]", queryArgs); + assertThat(res.count()).isEqualTo(3); + assertThat(res.documents()).allSatisfy(doc -> { + assertThat(doc.property("rating").asDouble()).isGreaterThan(8.0); + assertThat(doc.property("rating").asDouble()).isLessThan(9.0); + }); + } + @Test void testDictAndSpellcheck() { search.ftCreate("my-index", new CreateArgs().prefixes("word:").indexedField("word", FieldType.TEXT)); @@ -875,7 +894,7 @@ void testKNearestNeighborsDouble() { QueryArgs args = new QueryArgs() .sortByAscending("vector_score") - .param("DIALECT", "2") + .dialect(2) .param("BLOB", queryVector); SearchQueryResponse response = ds.search().ftSearch("IDX:double", query, args); assertEquals(1, response.count()); @@ -906,7 +925,7 @@ void testKNearestNeighborsFloat() { String query = "*=>[ KNN 1 @vector $BLOB AS vector_score ]"; QueryArgs args = new QueryArgs() .sortByAscending("vector_score") - .param("DIALECT", "2") + .dialect(2) .param("BLOB", queryVector); SearchQueryResponse response = ds.search().ftSearch("IDX:float", query, args);