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

Set the correct length of parameters when constructing the Redis arguments #41838

Merged
merged 1 commit into from
Jul 20, 2024
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
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
Loading