Skip to content

Commit

Permalink
Merge pull request #41838 from rubik-cube-man/redis-params
Browse files Browse the repository at this point in the history
Set the correct length of parameters when constructing the Redis arguments
  • Loading branch information
gastaldi authored Jul 20, 2024
2 parents bb4e226 + 3b7f59b commit c9d196c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ public List<Object> 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<String, byte[]> entry : byteArrayParams.entrySet()) {
list.add(entry.getKey());
list.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c9d196c

Please sign in to comment.