Skip to content

Commit

Permalink
Set the correct length of parameters when constructing arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rubik-cube-man committed Jul 20, 2024
1 parent 0109749 commit 3b7f59b
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 3b7f59b

Please sign in to comment.