Skip to content

Commit d48818b

Browse files
committed
fix HC unit tests
1 parent f775add commit d48818b

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

src/NRedisStack/Search/HybridSearchQuery.Command.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using NRedisStack.Search.Aggregation;
3+
using StackExchange.Redis;
34

45
namespace NRedisStack.Search;
56

@@ -318,17 +319,25 @@ static void AddApply(in ApplyExpression expr, List<object> args)
318319
foreach (var entry in typed) // avoid allocating enumerator
319320
{
320321
args.Add(entry.Key);
321-
args.Add(entry.Value is VectorData vec ? vec.GetSingleArg() : entry.Value);
322+
args.Add(Wrap(entry.Value));
322323
}
323324
}
324325
else
325326
{
326327
foreach (var entry in parameters)
327328
{
328329
args.Add(entry.Key);
329-
args.Add(entry.Value is VectorData vec ? vec.GetSingleArg() : entry.Value);
330+
args.Add(Wrap(entry.Value));
330331
}
331332
}
333+
334+
static object Wrap(object value)
335+
=> value switch
336+
{
337+
VectorData vec => vec.GetSingleArg(),
338+
ReadOnlyMemory<byte> raw => (RedisValue)raw,
339+
_ => value,
340+
};
332341
}
333342

334343
if (_explainScore) args.Add("EXPLAINSCORE");

tests/NRedisStack.Tests/Search/HybridSearchIntegrationTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ public enum Scenario
138138
{
139139
Simple,
140140
NoSort,
141-
[Broken] ExplainScore,
141+
ExplainScore,
142142
Apply,
143143
LinearNoScore,
144144
LinearWithScore,
145145
RrfNoScore,
146146
RrfWithScore,
147-
[Broken] PostFilterByTag,
147+
PostFilterByTag,
148148
PostFilterByNumber,
149149
LimitFirstPage,
150150
LimitSecondPage,
@@ -159,23 +159,23 @@ public enum Scenario
159159
GroupByNoReduce,
160160
SearchWithAlias,
161161
SearchWithSimpleScorer,
162-
[Broken] SearchWithComplexScorer,
162+
SearchWithComplexScorer,
163163
VectorWithAlias,
164164
VectorWithRange,
165-
[Broken] VectorWithRangeAndDistanceAlias,
165+
VectorWithRangeAndDistanceAlias,
166166
VectorWithRangeAndEpsilon,
167167
VectorWithTagFilter,
168168
VectorWithNumericFilter,
169169
VectorWithNearest,
170170
VectorWithNearestCount,
171-
[Broken] VectorWithNearestDistAlias,
171+
VectorWithNearestDistAlias,
172172
VectorWithNearestMaxCandidates,
173173
PreFilterByTag,
174174
PreFilterByNumeric,
175-
[Broken] ParamPostFilter,
175+
ParamPostFilter,
176176
ParamSearch,
177177
ParamVsim,
178-
[Broken] ParamMultiPostFilter,
178+
ParamMultiPostFilter,
179179
ParamPreFilter,
180180
ParamMultiPreFilter
181181
}

tests/NRedisStack.Tests/Search/HybridSearchUnitTests.cs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Text;
21
using NRedisStack.Search;
32
using NRedisStack.Search.Aggregation;
43
using Xunit;
@@ -285,7 +284,7 @@ public void Combine_DefaultLinear()
285284
{
286285
HybridSearchQuery query = new();
287286
query.Combine(HybridSearchQuery.Combiner.Linear());
288-
object[] expected = [Index, "COMBINE", "LINEAR", 0];
287+
object[] expected = [Index, "COMBINE", "LINEAR", 4, "ALPHA", 0.3, "BETA", 0.7];
289288
Assert.Equivalent(expected, GetArgs(query));
290289
}
291290

@@ -304,7 +303,7 @@ public void Combine_DefaultRrf_WithAlias()
304303
{
305304
HybridSearchQuery query = new();
306305
query.Combine(HybridSearchQuery.Combiner.ReciprocalRankFusion(), "my_combined_alias");
307-
object[] expected = [Index, "COMBINE", "RRF", 0, "YIELD_SCORE_AS", "my_combined_alias"];
306+
object[] expected = [Index, "COMBINE", "RRF", 2, "WINDOW", 20, "YIELD_SCORE_AS", "my_combined_alias"];
308307
Assert.Equivalent(expected, GetArgs(query));
309308
}
310309

@@ -317,11 +316,7 @@ public void Combine_NonDefaultRrf(int? window, double? constant)
317316
{
318317
HybridSearchQuery query = new();
319318
query.Combine(HybridSearchQuery.Combiner.ReciprocalRankFusion(window, constant));
320-
object[] expected = [Index, "COMBINE", "RRF", (window is not null ? 2 : 0) + (constant is not null ? 2 : 0)];
321-
if (window is not null)
322-
{
323-
expected = [.. expected, "WINDOW", window];
324-
}
319+
object[] expected = [Index, "COMBINE", "RRF", 2 + (constant is not null ? 2 : 0), "WINDOW", window ?? 20];
325320

326321
if (constant is not null)
327322
{
@@ -627,15 +622,18 @@ public void ParameterizedQuery()
627622
IReadOnlyDictionary<string, object> args = new Dictionary<string, object>
628623
{
629624
{ "s", "abc"},
630-
{"v", VectorData.Create(SomeRandomDataHere) }
625+
{ "v", VectorData.Create(SomeRandomDataHere) }
631626
};
632627
object[] expected = [Index, "SEARCH", "$s", "VSIM", "@field", "$v", "PARAMS", 4, "s", "abc", "v", SomeRandomVectorValue];
628+
var idx = Array.IndexOf(expected, "abc");
629+
Assert.True(idx >= 0);
633630
Assert.Equivalent(expected, GetArgs(query, args));
634631

635632
// issue a second query against the same "query" instance, with different parameter values, this time from an object
636-
args = Parameters.From(new { s = "def", v = SomeRandomDataHere });
637-
expected[8] = "def"; // update our expectations
638-
expected[10] = SomeRandomVectorValue;
633+
args = Parameters.From(new { s = "def", v = VectorData.Create(SomeRandomDataHere) });
634+
635+
expected[idx] = "def"; // update our expectations
636+
expected[idx + 2] = SomeRandomVectorValue;
639637
Assert.Equivalent(expected, GetArgs(query, args));
640638
}
641639

@@ -672,7 +670,7 @@ public void MakeMeOneWithEverything()
672670
"QUANTILE", 2, "@field3", 0.5, "AS", "reducer_alias", "APPLY", "@field1 + @field2", "AS", "apply_alias",
673671
"SORTBY", 3, "field1", "field2", "DESC", "FILTER", "@field1:bar", "LIMIT", 12, 54,
674672
"PARAMS", 4, "x", 42, "y", "abc",
675-
"EXPLAINSCORE", "TIMEOUT",
673+
"EXPLAINSCORE", "TIMEOUT", 1000,
676674
"WITHCURSOR", "COUNT", 10, "MAXIDLE", 10000
677675
];
678676

0 commit comments

Comments
 (0)