Skip to content

Commit

Permalink
Support RediSearch DIALECT 5 (#3831)
Browse files Browse the repository at this point in the history
- [x] Avoid escaping at query time
- [ ] Alias for tag fields (EXACT)
- [x] Avoid repeating for numeral equality
- [x] New dialect (5)
  • Loading branch information
sazzad16 authored Jun 13, 2024
1 parent 92c09f3 commit 33d4771
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ public static RangeValue between(int from, int to) {
return new LongRangeValue(from, to);
}

// TODO: change to simpler [d] available since RedisStack 7.4.0-rc1;
// currently kept for backward compatibility
public static RangeValue eq(double d) {
return new DoubleRangeValue(d, d);
}

// TODO: change to simpler [i] available since RedisStack 7.4.0-rc1;
// currently kept for backward compatibility
public static RangeValue eq(int i) {
return new LongRangeValue(i, i);
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/redis/clients/jedis/modules/search/SearchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ public void testQueryParams() {

Query query = new Query("@numval:[$min $max]").addParam("min", 1).addParam("max", 2).dialect(2);
assertEquals(2, client.ftSearch(index, query).getTotalResults());

query = new Query("@numval:[$eq]").addParam("eq", 2).dialect(5);
assertEquals(1, client.ftSearch(index, query).getTotalResults());
}

@Test
Expand Down Expand Up @@ -532,6 +535,14 @@ public void testJsonWithAlias() {
res = client.ftSearch(index, new Query("@num:[0 10]"));
assertEquals(1, res.getTotalResults());
assertEquals("king:2", res.getDocuments().get(0).getId());

res = client.ftSearch(index, new Query("@num:[42 42]"));
assertEquals(1, res.getTotalResults());
assertEquals("king:1", res.getDocuments().get(0).getId());

res = client.ftSearch(index, new Query("@num:[42]").dialect(5));
assertEquals(1, res.getTotalResults());
assertEquals("king:1", res.getDocuments().get(0).getId());
}

@Test
Expand Down Expand Up @@ -773,6 +784,7 @@ public void getTagField() {
assertEquals(1, client.ftSearch(index, new Query("@category:{yellow}")).getTotalResults());
assertEquals(0, client.ftSearch(index, new Query("@category:{purple}")).getTotalResults());
assertEquals(1, client.ftSearch(index, new Query("@category:{orange\\;purple}")).getTotalResults());
assertEquals(1, client.ftSearch(index, new Query("@category:{orange;purple}").dialect(5)).getTotalResults());
assertEquals(4, client.ftSearch(index, new Query("hello")).getTotalResults());

assertEquals(new HashSet<>(Arrays.asList("red", "blue", "green", "yellow", "orange;purple")),
Expand Down Expand Up @@ -814,6 +826,7 @@ public void testGetTagFieldWithNonDefaultSeparator() {
assertEquals(1, client.ftSearch(index, new Query("hello @category:{yellow}")).getTotalResults());
assertEquals(0, client.ftSearch(index, new Query("@category:{purple}")).getTotalResults());
assertEquals(1, client.ftSearch(index, new Query("@category:{orange\\,purple}")).getTotalResults());
assertEquals(1, client.ftSearch(index, new Query("@category:{orange,purple}").dialect(5)).getTotalResults());
assertEquals(4, client.ftSearch(index, new Query("hello")).getTotalResults());

assertEquals(new HashSet<>(Arrays.asList("red", "blue", "green", "yellow", "orange,purple")),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ public void testQueryParams() {
assertEquals(2, client.ftSearch(index, "@numval:[$min $max]",
FTSearchParams.searchParams().params(paramValues)
.dialect(2)).getTotalResults());

assertEquals(1, client.ftSearch(index, "@numval:[$eq]",
FTSearchParams.searchParams().addParam("eq", 2).dialect(5)).getTotalResults());
}

@Test
Expand Down Expand Up @@ -574,6 +577,14 @@ public void testJsonWithAlias() {
res = client.ftSearch(index, "@num:[0 10]");
assertEquals(1, res.getTotalResults());
assertEquals("king:2", res.getDocuments().get(0).getId());

res = client.ftSearch(index, "@num:[42 42]", FTSearchParams.searchParams());
assertEquals(1, res.getTotalResults());
assertEquals("king:1", res.getDocuments().get(0).getId());

res = client.ftSearch(index, "@num:[42]", FTSearchParams.searchParams().dialect(5));
assertEquals(1, res.getTotalResults());
assertEquals("king:1", res.getDocuments().get(0).getId());
}

@Test
Expand Down Expand Up @@ -777,6 +788,8 @@ public void getTagField() {
assertEquals(1, client.ftSearch(index, "@category:{yellow}").getTotalResults());
assertEquals(0, client.ftSearch(index, "@category:{purple}").getTotalResults());
assertEquals(1, client.ftSearch(index, "@category:{orange\\;purple}").getTotalResults());
assertEquals(1, client.ftSearch(index, "@category:{orange;purple}",
FTSearchParams.searchParams().dialect(5)).getTotalResults());
assertEquals(4, client.ftSearch(index, "hello").getTotalResults());

assertEquals(new HashSet<>(Arrays.asList("red", "blue", "green", "yellow", "orange;purple")),
Expand Down Expand Up @@ -816,6 +829,8 @@ public void testGetTagFieldWithNonDefaultSeparator() {
assertEquals(1, client.ftSearch(index, "hello @category:{yellow}").getTotalResults());
assertEquals(0, client.ftSearch(index, "@category:{purple}").getTotalResults());
assertEquals(1, client.ftSearch(index, "@category:{orange\\,purple}").getTotalResults());
assertEquals(1, client.ftSearch(index, "@category:{orange,purple}",
FTSearchParams.searchParams().dialect(5)).getTotalResults());
assertEquals(4, client.ftSearch(index, "hello").getTotalResults());

assertEquals(new HashSet<>(Arrays.asList("red", "blue", "green", "yellow", "orange,purple")),
Expand Down

0 comments on commit 33d4771

Please sign in to comment.