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

Test with 8.0-M04-pre #4069

Merged
merged 12 commits into from
Jan 30, 2025
Prev Previous commit
Next Next commit
Update testAggregationBuilderAddScores test to match change in SEARCH…
… module replacing default SCORER from TF-IDF to BM25.
ggivo committed Jan 29, 2025
commit a1ce66462711de4033a3d7dcc5dc0358a565bd61
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@
import redis.clients.jedis.search.aggr.FtAggregateIteration;
import redis.clients.jedis.search.schemafields.NumericField;
import redis.clients.jedis.search.schemafields.TextField;
import redis.clients.jedis.util.RedisConditions;

@RunWith(Parameterized.class)
public class AggregationTest extends RedisModuleCommandsTestBase {
@@ -215,8 +216,15 @@ public void testAggregationBuilderAddScores() {
.apply("@__score * 100", "normalized_score").dialect(3);

AggregationResult res = client.ftAggregate(index, r);
assertEquals(2, res.getRow(0).getLong("__score"));
assertEquals(200, res.getRow(0).getLong("normalized_score"));
if (RedisConditions.of(client).moduleVersionIsGreatherThan("SEARCH", 79900)) {
// Default scorer is BM25
assertEquals(0.6931, res.getRow(0).getDouble("__score"),0.0001);
assertEquals(69.31, res.getRow(0).getDouble("normalized_score"),0.01);
} else {
// Default scorer is TF-IDF
assertEquals(2, res.getRow(0).getLong("__score"));
assertEquals(200, res.getRow(0).getLong("normalized_score"));
}
}

@Test
70 changes: 70 additions & 0 deletions src/test/java/redis/clients/jedis/util/RedisConditions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package redis.clients.jedis.util;

import io.redis.test.utils.RedisVersion;
import redis.clients.jedis.BuilderFactory;
import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.CommandObject;

import redis.clients.jedis.Module;
import redis.clients.jedis.Protocol.Keyword;
import redis.clients.jedis.UnifiedJedis;
import redis.clients.jedis.resps.CommandInfo;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import static redis.clients.jedis.Protocol.Command.COMMAND;
import static redis.clients.jedis.Protocol.Command.MODULE;

public class RedisConditions {

private Map<String, Integer> modules;
private Map<String, CommandInfo> commands;

private RedisConditions(Map< String, CommandInfo> commands, Map<String, Integer> modules) {
this.commands = commands;
this.modules = modules;
}

public static RedisConditions of(UnifiedJedis jedis) {
RedisVersion version = RedisVersionUtil.getRedisVersion(jedis);

CommandObject<Map<String, CommandInfo>> commandInfoCmd = new CommandObject<>(new CommandArguments(COMMAND), CommandInfo.COMMAND_INFO_RESPONSE);
Map<String, CommandInfo> commands = jedis.executeCommand(commandInfoCmd);

CommandObject<List<Module>> moduleListCmd = new CommandObject<>(new CommandArguments(MODULE).add(
Keyword.LIST), BuilderFactory.MODULE_LIST);

Map<String, Integer> modules = jedis.executeCommand(moduleListCmd)
.stream()
.collect(Collectors.toMap((m)-> m.getName().toUpperCase(), Module::getVersion));

return new RedisConditions(commands, modules);
}

/**
* @param command
* @return {@code true} if the command is present.
*/
public boolean hasCommand(String command) {
return commands.containsKey(command.toUpperCase());
}

/**
* @param module
* @return {@code true} if the module is present.
*/
public boolean hasModule(String module) {
return modules.containsKey(module.toUpperCase());
}

/**
* @param module
* @return {@code true} if the module is present.
*/
public boolean moduleVersionIsGreatherThan(String module, int version) {
Integer moduleVersion = modules.get(module.toUpperCase());
return moduleVersion != null && moduleVersion > version;
}
}