From f4b7208eeea60e63799ead17b05bf71bb0c70efd Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 5 Jun 2023 17:56:47 +0300 Subject: [PATCH 01/11] change the structure of AggregationRequest --- src/NRedisStack/Search/ISearchCommands.cs | 10 +++--- .../Search/ISearchCommandsAsync.cs | 10 +++--- .../Search/SearchCommandBuilder.cs | 20 +++++++---- src/NRedisStack/Search/SearchCommands.cs | 16 ++++----- src/NRedisStack/Search/SearchCommandsAsync.cs | 16 ++++----- tests/NRedisStack.Tests/Search/SearchTests.cs | 34 +++++++++++++++---- 6 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/NRedisStack/Search/ISearchCommands.cs b/src/NRedisStack/Search/ISearchCommands.cs index d931a040..33e746ff 100644 --- a/src/NRedisStack/Search/ISearchCommands.cs +++ b/src/NRedisStack/Search/ISearchCommands.cs @@ -146,19 +146,21 @@ public interface ISearchCommands /// Return the execution plan for a complex query /// /// The index name - /// The query to explain + /// The query to explain + /// Dialect version under which to execute the query /// String that representing the execution plan /// - string Explain(string indexName, Query q); + string Explain(string indexName, string query, int? dialect = null); /// /// Return the execution plan for a complex query /// /// The index name - /// The query to explain + /// The query to explain + /// Dialect version under which to execute the query /// An array reply with a string representing the execution plan /// - RedisResult[] ExplainCli(string indexName, Query q); + RedisResult[] ExplainCli(string indexName, string query, int? dialect = null); /// /// Return information and statistics on the index. diff --git a/src/NRedisStack/Search/ISearchCommandsAsync.cs b/src/NRedisStack/Search/ISearchCommandsAsync.cs index 7948459b..e335c10e 100644 --- a/src/NRedisStack/Search/ISearchCommandsAsync.cs +++ b/src/NRedisStack/Search/ISearchCommandsAsync.cs @@ -145,19 +145,21 @@ public interface ISearchCommandsAsync /// Return the execution plan for a complex query /// /// The index name - /// The query to explain + /// The query to explain + /// Dialect version under which to execute the query /// String that representing the execution plan /// - Task ExplainAsync(string indexName, Query q); + Task ExplainAsync(string indexName, string query, int? dialect = null); /// /// Return the execution plan for a complex query /// /// The index name - /// The query to explain + /// The query to explain + /// Dialect version under which to execute the query /// An array reply with a string representing the execution plan /// - Task ExplainCliAsync(string indexName, Query q); + Task ExplainCliAsync(string indexName, string query, int? dialect = null); /// /// Return information and statistics on the index. diff --git a/src/NRedisStack/Search/SearchCommandBuilder.cs b/src/NRedisStack/Search/SearchCommandBuilder.cs index 7899c24e..35d82136 100644 --- a/src/NRedisStack/Search/SearchCommandBuilder.cs +++ b/src/NRedisStack/Search/SearchCommandBuilder.cs @@ -126,17 +126,25 @@ public static SerializedCommand DropIndex(string indexName, bool dd = false) : new SerializedCommand(FT.DROPINDEX, indexName)); } - public static SerializedCommand Explain(string indexName, Query q) + public static SerializedCommand Explain(string indexName, string query, int? dialect) { - var args = new List { indexName }; - q.SerializeRedisArgs(args); + var args = new List { indexName, query }; + if (dialect != null) + { + args.Add("DIALECT"); + args.Add(dialect); + } return new SerializedCommand(FT.EXPLAIN, args); } - public static SerializedCommand ExplainCli(string indexName, Query q) + public static SerializedCommand ExplainCli(string indexName, string query, int? dialect) { - var args = new List { indexName }; - q.SerializeRedisArgs(args); + var args = new List { indexName, query }; + if (dialect != null) + { + args.Add("DIALECT"); + args.Add(dialect); + } return new SerializedCommand(FT.EXPLAINCLI, args); } diff --git a/src/NRedisStack/Search/SearchCommands.cs b/src/NRedisStack/Search/SearchCommands.cs index c6ca622e..ff9ed40a 100644 --- a/src/NRedisStack/Search/SearchCommands.cs +++ b/src/NRedisStack/Search/SearchCommands.cs @@ -130,23 +130,23 @@ public bool DropIndex(string indexName, bool dd = false) } /// - public string Explain(string indexName, Query q) + public string Explain(string indexName, string query, int? dialect = null) { - if (q.dialect == null && defaultDialect != null) + if (dialect == null && defaultDialect != null) { - q.Dialect((int)defaultDialect); + dialect = defaultDialect; } - return _db.Execute(SearchCommandBuilder.Explain(indexName, q)).ToString(); + return _db.Execute(SearchCommandBuilder.Explain(indexName, query, dialect)).ToString(); } /// - public RedisResult[] ExplainCli(string indexName, Query q) + public RedisResult[] ExplainCli(string indexName, string query, int? dialect = null) { - if (q.dialect == null && defaultDialect != null) + if (dialect == null && defaultDialect != null) { - q.Dialect((int)defaultDialect); + dialect = defaultDialect; } - return _db.Execute(SearchCommandBuilder.ExplainCli(indexName, q)).ToArray(); + return _db.Execute(SearchCommandBuilder.ExplainCli(indexName, query, dialect)).ToArray(); } /// diff --git a/src/NRedisStack/Search/SearchCommandsAsync.cs b/src/NRedisStack/Search/SearchCommandsAsync.cs index 90c1f1d4..d0de86b0 100644 --- a/src/NRedisStack/Search/SearchCommandsAsync.cs +++ b/src/NRedisStack/Search/SearchCommandsAsync.cs @@ -121,25 +121,25 @@ public async Task DropIndexAsync(string indexName, bool dd = false) } /// - public async Task ExplainAsync(string indexName, Query q) + public async Task ExplainAsync(string indexName, string query, int? dialect = null) { - if (q.dialect == null && defaultDialect != null) + if (dialect == null && defaultDialect != null) { - q.Dialect((int)defaultDialect); + dialect = defaultDialect; } - return (await _db.ExecuteAsync(SearchCommandBuilder.Explain(indexName, q))).ToString(); + return (await _db.ExecuteAsync(SearchCommandBuilder.Explain(indexName, query, dialect))).ToString(); } /// - public async Task ExplainCliAsync(string indexName, Query q) + public async Task ExplainCliAsync(string indexName, string query, int? dialect = null) { - if (q.dialect == null && defaultDialect != null) + if (dialect == null && defaultDialect != null) { - q.Dialect((int)defaultDialect); + dialect = defaultDialect; } - return (await _db.ExecuteAsync(SearchCommandBuilder.ExplainCli(indexName, q))).ToArray(); + return (await _db.ExecuteAsync(SearchCommandBuilder.ExplainCli(indexName, query, dialect))).ToArray(); } /// diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 6c49e877..b7ef854c 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1329,9 +1329,16 @@ public void TestExplain() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - string res = ft.Explain(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + string res = ft.Explain(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); Assert.NotNull(res); Assert.False(res.Length == 0); + + // Test with dialect: + res = ft.Explain(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 2); + Assert.NotNull(res); + Assert.False(res.Length == 0); + + } [Fact] @@ -1346,7 +1353,12 @@ public async Task TestExplainAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - string res = await ft.ExplainAsync(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + string res = await ft.ExplainAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + Assert.NotNull(res); + Assert.False(res.Length == 0); + + // Test with dialect: + res = await ft.ExplainAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 2); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1363,7 +1375,12 @@ public void TestExplainCli() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var res = ft.ExplainCli(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + var res = ft.ExplainCli(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + Assert.NotNull(res); + Assert.False(res.Length == 0); + + // Test with dialect (ovveride the dialect 2): + res = ft.ExplainCli(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 1); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1380,7 +1397,12 @@ public async Task TestExplainCliAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var res = await ft.ExplainCliAsync(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + var res = await ft.ExplainCliAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + Assert.NotNull(res); + Assert.False(res.Length == 0); + + // Test with dialect (ovveride the dialect 2): + res = await ft.ExplainCliAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 1); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1397,7 +1419,7 @@ public void TestExplainWithDefaultDialect() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - String res = ft.Explain(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + String res = ft.Explain(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1414,7 +1436,7 @@ public async Task TestExplainWithDefaultDialectAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - String res = await ft.ExplainAsync(index, new Query("@f3:f3_val @f2:f2_val @f1:f1_val")); + String res = await ft.ExplainAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); Assert.NotNull(res); Assert.False(res.Length == 0); } From 79669e4592e56d0439b79a65f6d227fd5df46324 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Wed, 14 Jun 2023 18:19:04 +0300 Subject: [PATCH 02/11] Fix Explain Commands --- src/NRedisStack/Search/AggregationRequest.cs | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index e5854f99..ee17d7b7 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -8,6 +8,10 @@ public class AggregationRequest private bool isWithCursor = false; // Parameters: +<<<<<<< HEAD +======= + private int? dialect = 2; // Set default value to DIACLECT 2 +>>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) private bool? verbatim = null; @@ -61,6 +65,18 @@ private void Verbatim() args.Add("VERBATIM"); } + public AggregationRequest Verbatim(bool verbatim = true) + { + this.verbatim = true; + return this; + } + + private void Verbatim() + { + if(verbatim == true) + args.Add("VERBATIM"); + } + public AggregationRequest Load(params FieldName[] fields) { this.fieldNames.AddRange(fields); @@ -83,17 +99,26 @@ private void Load() } else if (fieldNames.Count > 0) { +<<<<<<< HEAD args.Add("LOAD"); int loadCountIndex = args.Count; //args.Add(null); +======= + int loadCountIndex = args.Count; + args.Add(null); +>>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) int loadCount = 0; foreach (FieldName fn in fieldNames) { loadCount += fn.AddCommandArguments(args); } +<<<<<<< HEAD args.Insert(loadCountIndex, loadCount); // args[loadCountIndex] = loadCount.ToString(); +======= + args.Insert(loadCountIndex, loadCount.ToString()); +>>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) } } @@ -163,7 +188,11 @@ private void SortBy() foreach (SortedField field in sortedFields) { args.Add(field.FieldName); +<<<<<<< HEAD args.Add(field.Order.ToString()); +======= + args.Add(field.Order); +>>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) } if (max > 0) @@ -313,9 +342,15 @@ public void SerializeRedisArgs() Verbatim(); Load(); Timeout(); +<<<<<<< HEAD Apply(); GroupBy(); SortBy(); +======= + GroupBy(); + SortBy(); + Apply(); +>>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) Limit(); Filter(); Cursor(); From 8a88e165c65549e6272ad126b107594b5f2267c0 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 6 Jun 2023 16:03:38 +0300 Subject: [PATCH 03/11] fixes --- src/NRedisStack/Search/AggregationRequest.cs | 35 -------------------- 1 file changed, 35 deletions(-) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index ee17d7b7..e5854f99 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -8,10 +8,6 @@ public class AggregationRequest private bool isWithCursor = false; // Parameters: -<<<<<<< HEAD -======= - private int? dialect = 2; // Set default value to DIACLECT 2 ->>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) private bool? verbatim = null; @@ -65,18 +61,6 @@ private void Verbatim() args.Add("VERBATIM"); } - public AggregationRequest Verbatim(bool verbatim = true) - { - this.verbatim = true; - return this; - } - - private void Verbatim() - { - if(verbatim == true) - args.Add("VERBATIM"); - } - public AggregationRequest Load(params FieldName[] fields) { this.fieldNames.AddRange(fields); @@ -99,26 +83,17 @@ private void Load() } else if (fieldNames.Count > 0) { -<<<<<<< HEAD args.Add("LOAD"); int loadCountIndex = args.Count; //args.Add(null); -======= - int loadCountIndex = args.Count; - args.Add(null); ->>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) int loadCount = 0; foreach (FieldName fn in fieldNames) { loadCount += fn.AddCommandArguments(args); } -<<<<<<< HEAD args.Insert(loadCountIndex, loadCount); // args[loadCountIndex] = loadCount.ToString(); -======= - args.Insert(loadCountIndex, loadCount.ToString()); ->>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) } } @@ -188,11 +163,7 @@ private void SortBy() foreach (SortedField field in sortedFields) { args.Add(field.FieldName); -<<<<<<< HEAD args.Add(field.Order.ToString()); -======= - args.Add(field.Order); ->>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) } if (max > 0) @@ -342,15 +313,9 @@ public void SerializeRedisArgs() Verbatim(); Load(); Timeout(); -<<<<<<< HEAD Apply(); GroupBy(); SortBy(); -======= - GroupBy(); - SortBy(); - Apply(); ->>>>>>> ac447f1 (add SerializeRedisArgs for FT.AGGREGATE) Limit(); Filter(); Cursor(); From 16abf41197f79ba7deff6aabe304bdbf8da7399a Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 6 Jun 2023 16:20:01 +0300 Subject: [PATCH 04/11] dialect 2 --- tests/NRedisStack.Tests/Search/SearchTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index b7ef854c..6cbbc833 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1906,7 +1906,9 @@ public void TestQueryCommandBuilderReturnField() "txt", "RETURN", "1", - "txt"}; + "txt", + "DIALECT", + "2"}; Assert.Equal(expectedArgs.Count(), buildCommand.Args.Count()); for (int i = 0; i < buildCommand.Args.Count(); i++) From 5384655d75b0171b19fe2e3c6fb957c9161a6034 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Sun, 11 Jun 2023 17:35:13 +0300 Subject: [PATCH 05/11] default dialect --- src/NRedisStack/Search/Query.cs | 4 ++-- tests/NRedisStack.Tests/Search/SearchTests.cs | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/NRedisStack/Search/Query.cs b/src/NRedisStack/Search/Query.cs index 0fa42f6c..ce97017f 100644 --- a/src/NRedisStack/Search/Query.cs +++ b/src/NRedisStack/Search/Query.cs @@ -191,12 +191,12 @@ public HighlightTags(string open, string close) public string Scorer { get; set; } // public bool ExplainScore { get; set; } // TODO: Check if this is needed because Jedis doesn't have it - private Dictionary _params = new Dictionary(); + private Dictionary _params = new Dictionary(); public int? dialect { get; private set;} = null; private int _slop = -1; private long _timeout = -1; private bool _inOrder = false; - private string _expander = null; + private string? _expander = null; public Query() : this("*") { } diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 6cbbc833..b7ef854c 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1906,9 +1906,7 @@ public void TestQueryCommandBuilderReturnField() "txt", "RETURN", "1", - "txt", - "DIALECT", - "2"}; + "txt"}; Assert.Equal(expectedArgs.Count(), buildCommand.Args.Count()); for (int i = 0; i < buildCommand.Args.Count(); i++) From 8c6cb4291bd3cef419fe9201f298ccbdaab70ba7 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 12 Jun 2023 12:18:48 +0300 Subject: [PATCH 06/11] add tests --- tests/NRedisStack.Tests/Search/SearchTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index b7ef854c..f5aaa264 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -2297,4 +2297,4 @@ public void TestModulePrefixs1() conn.Dispose(); } } -} +} \ No newline at end of file From fd8a59b1843b9eb7c7e4b3cd35efe14e31c7a2cd Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 12 Jun 2023 15:40:00 +0300 Subject: [PATCH 07/11] Params > 1 for AggregationRequest --- tests/NRedisStack.Tests/Search/SearchTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index f5aaa264..1b445c90 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -340,6 +340,7 @@ public async Task TestAggregationRequestParamsDialectAsync() Dictionary parameters = new Dictionary(); parameters.Add("name", "abc"); + parameters.Add("count", "10"); AggregationRequest r = new AggregationRequest("$name") .GroupBy("@name", Reducers.Sum("@count").As("sum")) From 21f6a43579b7d62566c912fea59506851c17265c Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 12 Jun 2023 17:36:16 +0300 Subject: [PATCH 08/11] coverage --- tests/NRedisStack.Tests/Search/SearchTests.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 1b445c90..d8d98827 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -340,7 +340,6 @@ public async Task TestAggregationRequestParamsDialectAsync() Dictionary parameters = new Dictionary(); parameters.Add("name", "abc"); - parameters.Add("count", "10"); AggregationRequest r = new AggregationRequest("$name") .GroupBy("@name", Reducers.Sum("@count").As("sum")) @@ -384,6 +383,12 @@ public void TestAggregationRequestParamsWithDefaultDialect() .Params(parameters); // From documentation - To use PARAMS, DIALECT must be set to 2 // which is the default as we set in the constructor (FT(2)) + + // Add more parameters using params (more than 1 is also possible): + parameters = new Dictionary(); + parameters.Add("count", "10"); + r.Params(parameters); + AggregationResult res = ft.Aggregate(index, r); Assert.Equal(1, res.TotalResults); From ffb53d06cae332fe779a1bf1d13d8281a77f8bd0 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 13 Jun 2023 14:44:08 +0300 Subject: [PATCH 09/11] fix --- tests/NRedisStack.Tests/Search/SearchTests.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index d8d98827..f5aaa264 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -383,12 +383,6 @@ public void TestAggregationRequestParamsWithDefaultDialect() .Params(parameters); // From documentation - To use PARAMS, DIALECT must be set to 2 // which is the default as we set in the constructor (FT(2)) - - // Add more parameters using params (more than 1 is also possible): - parameters = new Dictionary(); - parameters.Add("count", "10"); - r.Params(parameters); - AggregationResult res = ft.Aggregate(index, r); Assert.Equal(1, res.TotalResults); From 0377e9e0cb1b816ed51990eefc6a5e98d09fcd62 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 15 Jun 2023 12:23:27 +0300 Subject: [PATCH 10/11] review --- tests/NRedisStack.Tests/Search/SearchTests.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index f5aaa264..0a2631d4 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1329,12 +1329,13 @@ public void TestExplain() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - string res = ft.Explain(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; + string res = ft.Explain(index, query); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect: - res = ft.Explain(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 2); + res = ft.Explain(index, query, 2); Assert.NotNull(res); Assert.False(res.Length == 0); @@ -1353,12 +1354,13 @@ public async Task TestExplainAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - string res = await ft.ExplainAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; + string res = await ft.ExplainAsync(index, query); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect: - res = await ft.ExplainAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 2); + res = await ft.ExplainAsync(index, query, 2); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1375,12 +1377,13 @@ public void TestExplainCli() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var res = ft.ExplainCli(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; + var res = ft.ExplainCli(index, query); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect (ovveride the dialect 2): - res = ft.ExplainCli(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 1); + res = ft.ExplainCli(index, query, 1); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1397,12 +1400,13 @@ public async Task TestExplainCliAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var res = await ft.ExplainCliAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val"); + var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; + var res = await ft.ExplainCliAsync(index, query); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect (ovveride the dialect 2): - res = await ft.ExplainCliAsync(index, "@f3:f3_val @f2:f2_val @f1:f1_val", 1); + res = await ft.ExplainCliAsync(index, query, 1); Assert.NotNull(res); Assert.False(res.Length == 0); } From f9d95d086ee33ccdc7140f4fb3d5f0f2729bd967 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 15 Jun 2023 13:04:53 +0300 Subject: [PATCH 11/11] generate explainQuery once --- tests/NRedisStack.Tests/Search/SearchTests.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 0a2631d4..34bce220 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -1317,6 +1317,7 @@ public async Task TestDictionaryAsync() Assert.Equal((await ft.DictDumpAsync("dict")).Length, 0); } + string explainQuery = "@f3:f3_val @f2:f2_val @f1:f1_val"; [Fact] public void TestExplain() { @@ -1329,13 +1330,12 @@ public void TestExplain() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; - string res = ft.Explain(index, query); + string res = ft.Explain(index, explainQuery); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect: - res = ft.Explain(index, query, 2); + res = ft.Explain(index, explainQuery, 2); Assert.NotNull(res); Assert.False(res.Length == 0); @@ -1354,13 +1354,13 @@ public async Task TestExplainAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; - string res = await ft.ExplainAsync(index, query); + + string res = await ft.ExplainAsync(index, explainQuery); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect: - res = await ft.ExplainAsync(index, query, 2); + res = await ft.ExplainAsync(index, explainQuery, 2); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1377,13 +1377,13 @@ public void TestExplainCli() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; - var res = ft.ExplainCli(index, query); + + var res = ft.ExplainCli(index, explainQuery); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect (ovveride the dialect 2): - res = ft.ExplainCli(index, query, 1); + res = ft.ExplainCli(index, explainQuery, 1); Assert.NotNull(res); Assert.False(res.Length == 0); } @@ -1400,13 +1400,13 @@ public async Task TestExplainCliAsync() .AddTextField("f3", 1.0); ft.Create(index, FTCreateParams.CreateParams(), sc); - var query = "@f3:f3_val @f2:f2_val @f1:f1_val"; - var res = await ft.ExplainCliAsync(index, query); + + var res = await ft.ExplainCliAsync(index, explainQuery); Assert.NotNull(res); Assert.False(res.Length == 0); // Test with dialect (ovveride the dialect 2): - res = await ft.ExplainCliAsync(index, query, 1); + res = await ft.ExplainCliAsync(index, explainQuery, 1); Assert.NotNull(res); Assert.False(res.Length == 0); }