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

Support RediSearch DIALECT 5 #3831

Merged
merged 4 commits into from
Jun 13, 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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ start: stunnel cleanup compile-module
echo "$$REDIS_UDS" | redis-server -
echo "$$REDIS_UNAVAILABLE_CONF" | redis-server -
redis-cli -a cluster --cluster create 127.0.0.1:7479 127.0.0.1:7480 127.0.0.1:7481 --cluster-yes
docker run -p 6479:6379 --name jedis-stack -d redis/redis-stack-server:edge
docker run -p 6479:6379 --name jedis-stack -d redis/redis-stack-server:7.4.0-rc1

cleanup:
- rm -vf /tmp/redis_cluster_node*.conf 2>/dev/null
Expand Down
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
Loading