From e14fadefc8e2fc8767e0085eaf4c04f4dc8c9a13 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 29 Feb 2024 10:55:32 +0200 Subject: [PATCH 01/10] change aggregationRequest builder --- src/NRedisStack/Search/AggregationRequest.cs | 227 ++++-------------- tests/NRedisStack.Tests/Search/SearchTests.cs | 7 +- 2 files changed, 57 insertions(+), 177 deletions(-) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index 29eee63c..acf75573 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -7,38 +7,6 @@ public class AggregationRequest private List args = new List(); // Check if Readonly private bool isWithCursor = false; - // Parameters: - - private bool? verbatim = null; - - // Load - private List fieldNames = new List(); // TODO: Check if the new list suposed to be here - private bool? loadAll = null; - - private long? timeout = null; - - // GroupBy: - private List groups = new List(); - - // SotrBy: - private List sortedFields = new List(); - private int? max = null; - - // Apply: - private List> apply = new List>(); - - // Limit: - private int? offset = null; - private int? num = null; - - private string? filter = null; - - // WithCursor: - private int? count = null; - private long? maxIdle = null; - - // Params: - private Dictionary nameValue = new Dictionary(); public int? dialect { get; private set; } = null; public AggregationRequest(string query, int? defaultDialect = null) @@ -49,45 +17,21 @@ public AggregationRequest(string query, int? defaultDialect = null) public AggregationRequest() : this("*") { } - public AggregationRequest Verbatim(bool verbatim = true) + public AggregationRequest Verbatim() { - this.verbatim = true; + args.Add("VERBATIM"); return this; } - private void Verbatim() - { - if (verbatim == true) - args.Add("VERBATIM"); - } - public AggregationRequest Load(params FieldName[] fields) { - this.fieldNames.AddRange(fields); - return this; - } - - public AggregationRequest LoadAll() - { - loadAll = true; - return this; - } - - private void Load() - { - if (loadAll == true) - { - args.Add("LOAD"); - args.Add("*"); - return; - } - else if (fieldNames.Count > 0) + if (fields.Length > 0) { args.Add("LOAD"); int loadCountIndex = args.Count; //args.Add(null); int loadCount = 0; - foreach (FieldName fn in fieldNames) + foreach (FieldName fn in fields) { loadCount += fn.AddCommandArguments(args); } @@ -95,21 +39,28 @@ private void Load() args.Insert(loadCountIndex, loadCount); // args[loadCountIndex] = loadCount.ToString(); } + return this; + } + + public AggregationRequest LoadAll() + { + args.Add("LOAD"); + args.Add("*"); + return this; } public AggregationRequest Timeout(long timeout) { - this.timeout = timeout; + args.Add("TIMEOUT"); + args.Add(timeout); return this; } - private void Timeout() + + + public AggregationRequest GroupBy(string field, params Reducer[] reducers) { - if (timeout != null) - { - args.Add("TIMEOUT"); - args.Add(timeout); - } + return GroupBy(new string[] { field }, reducers); } public AggregationRequest GroupBy(IList fields, IList reducers) @@ -123,44 +74,25 @@ public AggregationRequest GroupBy(IList fields, IList reducers) return this; } - public AggregationRequest GroupBy(string field, params Reducer[] reducers) - { - return GroupBy(new string[] { field }, reducers); - } - public AggregationRequest GroupBy(Group group) { - this.groups.Add(group); + args.Add("GROUPBY"); + group.SerializeRedisArgs(args); return this; } - private void GroupBy() - { - if (groups.Count > 0) - { - args.Add("GROUPBY"); - foreach (Group group in groups) - { - group.SerializeRedisArgs(args); - } - } - } - public AggregationRequest SortBy(string property) => SortBy(SortedField.Asc(property)); - public AggregationRequest SortBy(params SortedField[] fields) - { - this.sortedFields.AddRange(fields); - return this; - } + public AggregationRequest SortBy(params SortedField[] fields) => SortBy(-1, fields); - private void SortBy() + + public AggregationRequest SortBy(int max, params SortedField[] fields) // TODO: check if it should be params { - if (sortedFields.Count > 0) + if (fields.Length > 0) { args.Add("SORTBY"); - args.Add(sortedFields.Count * 2); - foreach (SortedField field in sortedFields) + args.Add(fields.Length * 2); + foreach (SortedField field in fields) { args.Add(field.FieldName); args.Add(field.Order.ToString()); @@ -172,109 +104,53 @@ private void SortBy() args.Add(max); } } - } - - public AggregationRequest SortBy(int max, params SortedField[] fields) - { - this.max = max; - SortBy(fields); return this; } public AggregationRequest Apply(string projection, string alias) { - apply.Add(new Tuple(projection, alias)); + args.Add("APPLY"); + args.Add(projection); + args.Add("AS"); + args.Add(alias); return this; } - private void Apply() - { - if (apply.Count > 0) - { - foreach (Tuple tuple in apply) - { - args.Add("APPLY"); - args.Add(tuple.Item1); - args.Add("AS"); - args.Add(tuple.Item2); - } - } - } - public AggregationRequest Limit(int count) => Limit(0, count); public AggregationRequest Limit(int offset, int count) { - this.offset = offset; - this.num = count; - + new Limit(offset, count).SerializeRedisArgs(args); return this; } - private void Limit() - { - if (offset != null && num != null) - { - new Limit(offset.Value, num.Value).SerializeRedisArgs(args); - } - } - public AggregationRequest Filter(string filter) { - this.filter = filter; + args.Add(SearchArgs.FILTER); + args.Add(filter!); return this; } - private void Filter() - { - if (filter != null) - { - args.Add(SearchArgs.FILTER); - args.Add(filter!); - } - - } - public AggregationRequest Cursor(int? count = null, long? maxIdle = null) { isWithCursor = true; - if (count != null) - this.count = count; - if (maxIdle != null) - this.maxIdle = maxIdle; - return this; - } + args.Add("WITHCURSOR"); - private void Cursor() - { - if (isWithCursor) + if (count != null) { - args.Add("WITHCURSOR"); - - if (count != null) - { - args.Add("COUNT"); - args.Add(count); - } - - if (maxIdle != null && maxIdle < long.MaxValue && maxIdle >= 0) - { - args.Add("MAXIDLE"); - args.Add(maxIdle); - } + args.Add("COUNT"); + args.Add(count); } - } - public AggregationRequest Params(Dictionary nameValue) - { - foreach (var entry in nameValue) + if (maxIdle != null && maxIdle < long.MaxValue && maxIdle >= 0) { - this.nameValue.Add(entry.Key, entry.Value); + args.Add("MAXIDLE"); + args.Add(maxIdle); } return this; } - private void Params() + public AggregationRequest Params(Dictionary nameValue) { if (nameValue.Count > 0) { @@ -286,6 +162,7 @@ private void Params() args.Add(entry.Value); } } + return this; } public AggregationRequest Dialect(int dialect) @@ -310,16 +187,16 @@ public List GetArgs() public void SerializeRedisArgs() { - Verbatim(); - Load(); - Timeout(); - Apply(); - GroupBy(); - SortBy(); - Limit(); - Filter(); - Cursor(); - Params(); + // Verbatim(); + // Load(); + // Timeout(); + // Apply(); + // GroupBy(); + // SortBy(); + // Limit(); + // Filter(); + // Cursor(); + // Params(); Dialect(); } diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 7ab708d1..4d9099a5 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -338,9 +338,12 @@ public async Task TestAggregationRequestParamsDialectAsync() .Dialect(2); // From documentation - To use PARAMS, DIALECT must be set to 2 // Add more parameters using params (more than 1 is also possible): - parameters.Clear(); + // parameters.Clear(); parameters.Add("count", "10"); - r.Params(parameters); + r = new AggregationRequest("$name") + .GroupBy("@name", Reducers.Sum("@count").As("sum")) + .Params(parameters) + .Dialect(2); AggregationResult res = await ft.AggregateAsync(index, r); Assert.Equal(1, res.TotalResults); From f978025df7195b5afe0c7362eb0ad5677943fbc9 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 29 Feb 2024 11:10:16 +0200 Subject: [PATCH 02/10] add args to SearchArgs --- src/NRedisStack/Search/AggregationRequest.cs | 28 +++--- .../Search/Literals/CommandArgs.cs | 97 ++++++++++--------- 2 files changed, 66 insertions(+), 59 deletions(-) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index acf75573..89530999 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -19,7 +19,7 @@ public AggregationRequest() : this("*") { } public AggregationRequest Verbatim() { - args.Add("VERBATIM"); + args.Add(SearchArgs.VERBATIM); return this; } @@ -27,7 +27,7 @@ public AggregationRequest Load(params FieldName[] fields) { if (fields.Length > 0) { - args.Add("LOAD"); + args.Add(SearchArgs.LOAD); int loadCountIndex = args.Count; //args.Add(null); int loadCount = 0; @@ -44,14 +44,14 @@ public AggregationRequest Load(params FieldName[] fields) public AggregationRequest LoadAll() { - args.Add("LOAD"); + args.Add(SearchArgs.LOAD); args.Add("*"); return this; } public AggregationRequest Timeout(long timeout) { - args.Add("TIMEOUT"); + args.Add(SearchArgs.TIMEOUT); args.Add(timeout); return this; } @@ -76,7 +76,7 @@ public AggregationRequest GroupBy(IList fields, IList reducers) public AggregationRequest GroupBy(Group group) { - args.Add("GROUPBY"); + args.Add(SearchArgs.GROUPBY); group.SerializeRedisArgs(args); return this; } @@ -90,7 +90,7 @@ public AggregationRequest GroupBy(Group group) { if (fields.Length > 0) { - args.Add("SORTBY"); + args.Add(SearchArgs.SORTBY); args.Add(fields.Length * 2); foreach (SortedField field in fields) { @@ -100,7 +100,7 @@ public AggregationRequest GroupBy(Group group) if (max > 0) { - args.Add("MAX"); + args.Add(SearchArgs.MAX); args.Add(max); } } @@ -109,9 +109,9 @@ public AggregationRequest GroupBy(Group group) public AggregationRequest Apply(string projection, string alias) { - args.Add("APPLY"); + args.Add(SearchArgs.APPLY); args.Add(projection); - args.Add("AS"); + args.Add(SearchArgs.AS); args.Add(alias); return this; } @@ -134,17 +134,17 @@ public AggregationRequest Filter(string filter) public AggregationRequest Cursor(int? count = null, long? maxIdle = null) { isWithCursor = true; - args.Add("WITHCURSOR"); + args.Add(SearchArgs.WITHCURSOR); if (count != null) { - args.Add("COUNT"); + args.Add(SearchArgs.COUNT); args.Add(count); } if (maxIdle != null && maxIdle < long.MaxValue && maxIdle >= 0) { - args.Add("MAXIDLE"); + args.Add(SearchArgs.MAXIDLE); args.Add(maxIdle); } return this; @@ -154,7 +154,7 @@ public AggregationRequest Params(Dictionary nameValue) { if (nameValue.Count > 0) { - args.Add("PARAMS"); + args.Add(SearchArgs.PARAMS); args.Add(nameValue.Count * 2); foreach (var entry in nameValue) { @@ -175,7 +175,7 @@ private void Dialect() { if (dialect != null) { - args.Add("DIALECT"); + args.Add(SearchArgs.DIALECT); args.Add(dialect); } } diff --git a/src/NRedisStack/Search/Literals/CommandArgs.cs b/src/NRedisStack/Search/Literals/CommandArgs.cs index fb957db7..c847d972 100644 --- a/src/NRedisStack/Search/Literals/CommandArgs.cs +++ b/src/NRedisStack/Search/Literals/CommandArgs.cs @@ -2,60 +2,67 @@ namespace NRedisStack.Search.Literals { internal class SearchArgs { - public const string ON_HASH = "ON HASH"; - public const string JSON = "JSON"; - public const string PREFIX = "PREFIX"; + public const string AGGREGATE = "AGGREGATE"; + public const string APPLY = "APPLY"; + public const string AS = "AS"; + public const string ASC = "ASC"; + public const string COUNT = "COUNT"; + public const string DESC = "DESC"; + public const string DIALECT = "DIALECT"; + public const string DISTANCE = "DISTANCE"; + public const string EXCLUDE = "EXCLUDE"; + public const string EXPANDER = "EXPANDER"; + public const string FIELDS = "FIELDS"; public const string FILTER = "FILTER"; + public const string FRAGS = "FRAGS"; + public const string FUZZY = "FUZZY"; + public const string GROUPBY = "GROUPBY"; + public const string HIGHLIGHT = "HIGHLIGHT"; + public const string INCLUDE = "INCLUDE"; + public const string INCR = "INCR"; + public const string INFIELDS = "INFIELDS"; + public const string INKEYS = "INKEYS"; + public const string INORDER = "INORDER"; + public const string JSON = "JSON"; public const string LANGUAGE = "LANGUAGE"; public const string LANGUAGE_FIELD = "LANGUAGE_FIELD"; - public const string SCORE = "SCORE"; - public const string SCORE_FIELD = "SCORE_FIELD"; - public const string PAYLOAD_FIELD = "PAYLOAD_FIELD"; + public const string LEN = "LEN"; + public const string LIMIT = "LIMIT"; + public const string LIMITED = "LIMITED"; + public const string LOAD = "LOAD"; + public const string MAX = "MAX"; + public const string MAXIDLE = "MAXIDLE"; public const string MAXTEXTFIELDS = "MAXTEXTFIELDS"; - public const string TEMPORARY = "TEMPORARY"; - public const string NOOFFSETS = "NOOFFSETS"; - public const string NOHL = "NOHL"; + public const string NOCONTENT = "NOCONTENT"; public const string NOFIELDS = "NOFIELDS"; public const string NOFREQS = "NOFREQS"; - public const string STOPWORDS = "STOPWORDS"; - public const string SKIPINITIALSCAN = "SKIPINITIALSCAN"; - public const string INCLUDE = "INCLUDE"; - public const string EXCLUDE = "EXCLUDE"; - public const string DIALECT = "DIALECT"; - public const string TERMS = "TERMS"; - public const string DISTANCE = "DISTANCE"; - public const string INCR = "INCR"; - public const string PAYLOAD = "PAYLOAD"; - public const string FUZZY = "FUZZY"; - public const string WITHSCORES = "WITHSCORES"; - public const string WITHPAYLOADS = "WITHPAYLOADS"; - public const string MAX = "MAX"; - public const string VERBATIM = "VERBATIM"; - public const string NOCONTENT = "NOCONTENT"; + public const string NOHL = "NOHL"; + public const string NOOFFSETS = "NOOFFSETS"; public const string NOSTOPWORDS = "NOSTOPWORDS"; + public const string ON_HASH = "ON HASH"; + public const string PARAMS = "PARAMS"; + public const string PAYLOAD = "PAYLOAD"; + public const string PAYLOAD_FIELD = "PAYLOAD_FIELD"; + public const string PREFIX = "PREFIX"; + public const string QUERY = "QUERY"; + public const string RETURN = "RETURN"; + public const string SCORE = "SCORE"; + public const string SCORE_FIELD = "SCORE_FIELD"; public const string SCORER = "SCORER"; - public const string INFIELDS = "INFIELDS"; - public const string SORTBY = "SORTBY"; - public const string ASC = "ASC"; - public const string DESC = "DESC"; - public const string LIMIT = "LIMIT"; - public const string HIGHLIGHT = "HIGHLIGHT"; - public const string FIELDS = "FIELDS"; - public const string TAGS = "TAGS"; - public const string SUMMARIZE = "SUMMARIZE"; - public const string FRAGS = "FRAGS"; - public const string LEN = "LEN"; + public const string SEARCH = "SEARCH"; public const string SEPARATOR = "SEPARATOR"; - public const string INKEYS = "INKEYS"; - public const string RETURN = "RETURN"; - public const string PARAMS = "PARAMS"; + public const string SKIPINITIALSCAN = "SKIPINITIALSCAN"; public const string SLOP = "SLOP"; + public const string SORTBY = "SORTBY"; + public const string STOPWORDS = "STOPWORDS"; + public const string SUMMARIZE = "SUMMARIZE"; + public const string TAGS = "TAGS"; + public const string TEMPORARY = "TEMPORARY"; + public const string TERMS = "TERMS"; public const string TIMEOUT = "TIMEOUT"; - public const string INORDER = "INORDER"; - public const string EXPANDER = "EXPANDER"; - public const string SEARCH = "SEARCH"; - public const string AGGREGATE = "AGGREGATE"; - public const string LIMITED = "LIMITED"; - public const string QUERY = "QUERY"; + public const string VERBATIM = "VERBATIM"; + public const string WITHCURSOR = "WITHCURSOR"; + public const string WITHPAYLOADS = "WITHPAYLOADS"; + public const string WITHSCORES = "WITHSCORES"; } -} \ No newline at end of file +} From 6f84ec6889b1a7c7f954360f6c7c6e858423a390 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 29 Feb 2024 14:26:01 +0200 Subject: [PATCH 03/10] check issue 230 --- tests/NRedisStack.Tests/Search/SearchTests.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 4d9099a5..f7224ba3 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -2984,4 +2984,16 @@ public async Task GeoShapeFilterFlatAsync() Assert.Equal(2, res.TotalResults); Assert.Equal(2, res.Documents.Count); } + + [Fact] + public void Issue230() + { + var request = new AggregationRequest("*", 3).Filter("@StatusId==1") + .GroupBy("@CreatedDay", Reducers.CountDistinct("@UserId"), Reducers.Count().As("count")); + + var buildCommand = SearchCommandBuilder.Aggregate("idx:users", request); + // expected: FT.AGGREGATE idx:users * FILTER @StatusId==1 GROUPBY 1 @CreatedDay REDUCE COUNT_DISTINCT 1 @UserId REDUCE COUNT 0 AS count DIALECT 3 + Assert.Equal("FT.AGGREGATE", buildCommand.Command); + Assert.Equal(new object[] { "idx:users", "*", "FILTER", "@StatusId==1", "GROUPBY", 1, "@CreatedDay", "REDUCE", "COUNT_DISTINCT", 1, "@UserId", "REDUCE", "COUNT", 0, "AS", "count", "DIALECT", 3 }, buildCommand.Args); + } } From 36bd2d9ec914890af391564e6de21bccacfca7cb Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 29 Feb 2024 16:40:50 +0200 Subject: [PATCH 04/10] use SearchArgs in Schema --- .../Search/Literals/CommandArgs.cs | 7 + src/NRedisStack/Search/Schema.cs | 158 +++++++++--------- 2 files changed, 86 insertions(+), 79 deletions(-) diff --git a/src/NRedisStack/Search/Literals/CommandArgs.cs b/src/NRedisStack/Search/Literals/CommandArgs.cs index c847d972..7910bc53 100644 --- a/src/NRedisStack/Search/Literals/CommandArgs.cs +++ b/src/NRedisStack/Search/Literals/CommandArgs.cs @@ -6,6 +6,7 @@ internal class SearchArgs public const string APPLY = "APPLY"; public const string AS = "AS"; public const string ASC = "ASC"; + public const string CASESENSITIVE = "CASESENSITIVE"; public const string COUNT = "COUNT"; public const string DESC = "DESC"; public const string DIALECT = "DIALECT"; @@ -37,12 +38,15 @@ internal class SearchArgs public const string NOFIELDS = "NOFIELDS"; public const string NOFREQS = "NOFREQS"; public const string NOHL = "NOHL"; + public const string NOINDEX = "NOINDEX"; public const string NOOFFSETS = "NOOFFSETS"; + public const string NOSTEM = "NOSTEM"; public const string NOSTOPWORDS = "NOSTOPWORDS"; public const string ON_HASH = "ON HASH"; public const string PARAMS = "PARAMS"; public const string PAYLOAD = "PAYLOAD"; public const string PAYLOAD_FIELD = "PAYLOAD_FIELD"; + public const string PHONETIC = "PHONETIC"; public const string PREFIX = "PREFIX"; public const string QUERY = "QUERY"; public const string RETURN = "RETURN"; @@ -60,9 +64,12 @@ internal class SearchArgs public const string TEMPORARY = "TEMPORARY"; public const string TERMS = "TERMS"; public const string TIMEOUT = "TIMEOUT"; + public const string UNF = "UNF"; public const string VERBATIM = "VERBATIM"; + public const string WEIGHT = "WEIGHT"; public const string WITHCURSOR = "WITHCURSOR"; public const string WITHPAYLOADS = "WITHPAYLOADS"; public const string WITHSCORES = "WITHSCORES"; + public const string WITHSUFFIXTRIE = "WITHSUFFIXTRIE"; } } diff --git a/src/NRedisStack/Search/Schema.cs b/src/NRedisStack/Search/Schema.cs index 8aaabd08..92cb8eef 100644 --- a/src/NRedisStack/Search/Schema.cs +++ b/src/NRedisStack/Search/Schema.cs @@ -88,20 +88,20 @@ public TextField(string name, double weight = 1.0, bool noStem = false, internal override void AddFieldTypeArgs(List args) { - if (NoStem) args.Add("NOSTEM"); - if (NoIndex) args.Add("NOINDEX"); + if (NoStem) args.Add(SearchArgs.NOSTEM); + if (NoIndex) args.Add(SearchArgs.NOINDEX); AddPhonetic(args); AddWeight(args); - if (WithSuffixTrie) args.Add("WITHSUFFIXTRIE"); + if (WithSuffixTrie) args.Add(SearchArgs.WITHSUFFIXTRIE); if (Sortable) args.Add(AttributeOptions.SORTABLE); - if (Unf) args.Add("UNF"); + if (Unf) args.Add(SearchArgs.UNF); } private void AddWeight(List args) { if (Weight != 1.0) { - args.Add("WEIGHT"); + args.Add(SearchArgs.WEIGHT); args.Add(Weight); } } @@ -110,7 +110,7 @@ private void AddPhonetic(List args) { if (Phonetic != null) { - args.Add("PHONETIC"); + args.Add(SearchArgs.PHONETIC); args.Add(this.Phonetic); } } @@ -145,17 +145,17 @@ internal TagField(string name, bool sortable = false, bool unf = false, internal override void AddFieldTypeArgs(List args) { - if (NoIndex) args.Add("NOINDEX"); - if (WithSuffixTrie) args.Add("WITHSUFFIXTRIE"); + if (NoIndex) args.Add(SearchArgs.NOINDEX); + if (WithSuffixTrie) args.Add(SearchArgs.WITHSUFFIXTRIE); if (Separator != ",") { - args.Add("SEPARATOR"); + args.Add(SearchArgs.SEPARATOR); args.Add(Separator); } - if (CaseSensitive) args.Add("CASESENSITIVE"); + if (CaseSensitive) args.Add(SearchArgs.CASESENSITIVE); if (Sortable) args.Add(AttributeOptions.SORTABLE); - if (Unf) args.Add("UNF"); + if (Unf) args.Add(SearchArgs.UNF); } } @@ -175,7 +175,7 @@ internal GeoField(string name, bool sortable = false, bool noIndex = false) internal override void AddFieldTypeArgs(List args) { - if (NoIndex) args.Add("NOINDEX"); + if (NoIndex) args.Add(SearchArgs.NOINDEX); if (Sortable) args.Add(AttributeOptions.SORTABLE); } @@ -228,7 +228,7 @@ internal NumericField(string name, bool sortable = false, bool noIndex = false) internal override void AddFieldTypeArgs(List args) { - if (NoIndex) args.Add("NOINDEX"); + if (NoIndex) args.Add(SearchArgs.NOINDEX); if (Sortable) args.Add(AttributeOptions.SORTABLE); } @@ -274,8 +274,8 @@ internal override void AddFieldTypeArgs(List args) /// /// Add a field to the schema. /// - /// The to add. - /// The object. + /// The to add. + /// The object. public Schema AddField(Field field) { Fields.Add(field ?? throw new ArgumentNullException(nameof(field))); @@ -285,16 +285,16 @@ public Schema AddField(Field field) /// /// Add a Text field to the schema. /// - /// The field's name. - /// Its weight, a positive floating point number. - /// If true, the text field can be sorted. - /// Disable stemming when indexing its values. - /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// Set this to true to prevent the indexer from sorting on the normalized form. + /// The field's name. + /// Its weight, a positive floating point number. + /// If true, the text field can be sorted. + /// Disable stemming when indexing its values. + /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// Keeps a suffix trie with all terms which match the suffix. + /// The object. public Schema AddTextField(string name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) { @@ -305,16 +305,16 @@ public Schema AddTextField(string name, double weight = 1.0, bool sortable = fal /// /// Add a Text field to the schema. /// - /// The field's name. - /// Its weight, a positive floating point number. - /// If true, the text field can be sorted. - /// Disable stemming when indexing its values. - /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// Set this to true to prevent the indexer from sorting on the normalized form. + /// The field's name. + /// Its weight, a positive floating point number. + /// If true, the text field can be sorted. + /// Disable stemming when indexing its values. + /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// Keeps a suffix trie with all terms which match the suffix. + /// The object. public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) { @@ -325,9 +325,9 @@ public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = /// /// Add a GeoShape field to the schema. /// - /// The field's name. - /// The coordinate system to use. - /// The object. + /// The field's name. + /// The coordinate system to use. + /// The object. public Schema AddGeoShapeField(string name, CoordinateSystem system) { Fields.Add(new GeoShapeField(name, system)); @@ -337,9 +337,9 @@ public Schema AddGeoShapeField(string name, CoordinateSystem system) /// /// Add a GeoShape field to the schema. /// - /// The field's name. - /// The coordinate system to use. - /// The object. + /// The field's name. + /// The coordinate system to use. + /// The object. public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) { Fields.Add(new GeoShapeField(name, system)); @@ -349,10 +349,10 @@ public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) /// /// Add a Geo field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The object. public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = false) { Fields.Add(new GeoField(name, sortable, noIndex)); @@ -362,10 +362,10 @@ public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = /// /// Add a Geo field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The object. public Schema AddGeoField(string name, bool sortable = false, bool noIndex = false) { Fields.Add(new GeoField(name, sortable, noIndex)); @@ -375,10 +375,10 @@ public Schema AddGeoField(string name, bool sortable = false, bool noIndex = fal /// /// Add a Numeric field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The object. public Schema AddNumericField(FieldName name, bool sortable = false, bool noIndex = false) { Fields.Add(new NumericField(name, sortable, noIndex)); @@ -388,10 +388,10 @@ public Schema AddNumericField(FieldName name, bool sortable = false, bool noInde /// /// Add a Numeric field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The object. public Schema AddNumericField(string name, bool sortable = false, bool noIndex = false) { Fields.Add(new NumericField(name, sortable, noIndex)); @@ -401,15 +401,15 @@ public Schema AddNumericField(string name, bool sortable = false, bool noIndex = /// /// Add a Tag field to the schema. /// - /// The field's name. - /// If true, the field can be sorted. - /// Set this to true to prevent the indexer from sorting on the normalized form. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The tag separator. - /// If true, Keeps the original letter cases of the tags. + /// The field's name. + /// If true, the field can be sorted. + /// Set this to true to prevent the indexer from sorting on the normalized form. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The tag separator. + /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// Keeps a suffix trie with all terms which match the suffix. + /// The object. public Schema AddTagField(FieldName name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", bool caseSensitive = false, bool withSuffixTrie = false) @@ -421,15 +421,15 @@ public Schema AddTagField(FieldName name, bool sortable = false, bool unf = fals /// /// Add a Tag field to the schema. /// - /// The field's name. - /// If true, the field can be sorted. - /// Set this to true to prevent the indexer from sorting on the normalized form. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The tag separator. - /// If true, Keeps the original letter cases of the tags. + /// The field's name. + /// If true, the field can be sorted. + /// Set this to true to prevent the indexer from sorting on the normalized form. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The tag separator. + /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// Keeps a suffix trie with all terms which match the suffix. + /// The object. public Schema AddTagField(string name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", bool caseSensitive = false, bool withSuffixTrie = false) @@ -441,10 +441,10 @@ public Schema AddTagField(string name, bool sortable = false, bool unf = false, /// /// Add a Vector field to the schema. /// - /// The field's name. - /// The vector similarity algorithm to use. - /// The algorithm attributes for the creation of the vector index. - /// The object. + /// The field's name. + /// The vector similarity algorithm to use. + /// The algorithm attributes for the creation of the vector index. + /// The object. public Schema AddVectorField(FieldName name, VectorAlgo algorithm, Dictionary? attributes = null) { Fields.Add(new VectorField(name, algorithm, attributes)); @@ -454,10 +454,10 @@ public Schema AddVectorField(FieldName name, VectorAlgo algorithm, Dictionary /// Add a Vector field to the schema. /// - /// The field's name. - /// The vector similarity algorithm to use. - /// The algorithm attributes for the creation of the vector index. - /// The object. + /// The field's name. + /// The vector similarity algorithm to use. + /// The algorithm attributes for the creation of the vector index. + /// The object. public Schema AddVectorField(string name, VectorAlgo algorithm, Dictionary? attributes = null) { Fields.Add(new VectorField(name, algorithm, attributes)); From fe5e9a9bad16298b83518f4246191b5a38ac9d87 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Sun, 3 Mar 2024 14:30:37 +0200 Subject: [PATCH 05/10] comment deletions --- src/NRedisStack/Search/AggregationRequest.cs | 23 -------------------- 1 file changed, 23 deletions(-) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index 89530999..4e194a12 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -29,7 +29,6 @@ public AggregationRequest Load(params FieldName[] fields) { args.Add(SearchArgs.LOAD); int loadCountIndex = args.Count; - //args.Add(null); int loadCount = 0; foreach (FieldName fn in fields) { @@ -37,7 +36,6 @@ public AggregationRequest Load(params FieldName[] fields) } args.Insert(loadCountIndex, loadCount); - // args[loadCountIndex] = loadCount.ToString(); } return this; } @@ -85,7 +83,6 @@ public AggregationRequest GroupBy(Group group) public AggregationRequest SortBy(params SortedField[] fields) => SortBy(-1, fields); - public AggregationRequest SortBy(int max, params SortedField[] fields) // TODO: check if it should be params { if (fields.Length > 0) @@ -187,29 +184,9 @@ public List GetArgs() public void SerializeRedisArgs() { - // Verbatim(); - // Load(); - // Timeout(); - // Apply(); - // GroupBy(); - // SortBy(); - // Limit(); - // Filter(); - // Cursor(); - // Params(); Dialect(); } - // public string getArgsstring() - // { - // StringBuilder sj = new StringBuilder(" "); - // foreach (var s in GetArgs()) - // { - // sj.Add(s.ToString()); - // } - // return sj.tostring(); - // } - public bool IsWithCursor() { return isWithCursor; From 92ace203c5c41b1e669efa2226b18d2a83705306 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Mon, 4 Mar 2024 17:34:27 +0200 Subject: [PATCH 06/10] fix SortBy --- src/NRedisStack/Search/AggregationRequest.cs | 27 ++++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/NRedisStack/Search/AggregationRequest.cs b/src/NRedisStack/Search/AggregationRequest.cs index 4e194a12..705b1b66 100644 --- a/src/NRedisStack/Search/AggregationRequest.cs +++ b/src/NRedisStack/Search/AggregationRequest.cs @@ -83,24 +83,23 @@ public AggregationRequest GroupBy(Group group) public AggregationRequest SortBy(params SortedField[] fields) => SortBy(-1, fields); - public AggregationRequest SortBy(int max, params SortedField[] fields) // TODO: check if it should be params + public AggregationRequest SortBy(int max, params SortedField[] fields) { - if (fields.Length > 0) + args.Add(SearchArgs.SORTBY); + args.Add(fields.Length * 2); + + foreach (SortedField field in fields) { - args.Add(SearchArgs.SORTBY); - args.Add(fields.Length * 2); - foreach (SortedField field in fields) - { - args.Add(field.FieldName); - args.Add(field.Order.ToString()); - } + args.Add(field.FieldName); + args.Add(field.Order.ToString()); + } - if (max > 0) - { - args.Add(SearchArgs.MAX); - args.Add(max); - } + if (max > 0) + { + args.Add(SearchArgs.MAX); + args.Add(max); } + return this; } From bd810258b78d496906725daf6ac57d5e6cc1044a Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 5 Mar 2024 17:27:21 +0200 Subject: [PATCH 07/10] fix accident change --- src/NRedisStack/Search/Schema.cs | 106 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/src/NRedisStack/Search/Schema.cs b/src/NRedisStack/Search/Schema.cs index 92cb8eef..02bc3d6e 100644 --- a/src/NRedisStack/Search/Schema.cs +++ b/src/NRedisStack/Search/Schema.cs @@ -274,7 +274,7 @@ internal override void AddFieldTypeArgs(List args) /// /// Add a field to the schema. /// - /// The to add. + /// The to add. /// The object. public Schema AddField(Field field) { @@ -285,15 +285,15 @@ public Schema AddField(Field field) /// /// Add a Text field to the schema. /// - /// The field's name. - /// Its weight, a positive floating point number. - /// If true, the text field can be sorted. - /// Disable stemming when indexing its values. - /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// Set this to true to prevent the indexer from sorting on the normalized form. + /// The field's name. + /// Its weight, a positive floating point number. + /// If true, the text field can be sorted. + /// Disable stemming when indexing its values. + /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. + /// Keeps a suffix trie with all terms which match the suffix. /// The object. public Schema AddTextField(string name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) @@ -305,15 +305,15 @@ public Schema AddTextField(string name, double weight = 1.0, bool sortable = fal /// /// Add a Text field to the schema. /// - /// The field's name. - /// Its weight, a positive floating point number. - /// If true, the text field can be sorted. - /// Disable stemming when indexing its values. - /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// Set this to true to prevent the indexer from sorting on the normalized form. + /// The field's name. + /// Its weight, a positive floating point number. + /// If true, the text field can be sorted. + /// Disable stemming when indexing its values. + /// Declaring a text attribute as PHONETIC will perform phonetic matching on it in searches by default. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. + /// Keeps a suffix trie with all terms which match the suffix. /// The object. public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) @@ -325,8 +325,8 @@ public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = /// /// Add a GeoShape field to the schema. /// - /// The field's name. - /// The coordinate system to use. + /// The field's name. + /// The coordinate system to use. /// The object. public Schema AddGeoShapeField(string name, CoordinateSystem system) { @@ -337,8 +337,8 @@ public Schema AddGeoShapeField(string name, CoordinateSystem system) /// /// Add a GeoShape field to the schema. /// - /// The field's name. - /// The coordinate system to use. + /// The field's name. + /// The coordinate system to use. /// The object. public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) { @@ -349,9 +349,9 @@ public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) /// /// Add a Geo field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. /// The object. public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = false) { @@ -362,9 +362,9 @@ public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = /// /// Add a Geo field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. /// The object. public Schema AddGeoField(string name, bool sortable = false, bool noIndex = false) { @@ -375,9 +375,9 @@ public Schema AddGeoField(string name, bool sortable = false, bool noIndex = fal /// /// Add a Numeric field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. /// The object. public Schema AddNumericField(FieldName name, bool sortable = false, bool noIndex = false) { @@ -388,9 +388,9 @@ public Schema AddNumericField(FieldName name, bool sortable = false, bool noInde /// /// Add a Numeric field to the schema. /// - /// The field's name. - /// If true, the text field can be sorted. - /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The field's name. + /// If true, the text field can be sorted. + /// Attributes can have the NOINDEX option, which means they will not be indexed. /// The object. public Schema AddNumericField(string name, bool sortable = false, bool noIndex = false) { @@ -401,14 +401,14 @@ public Schema AddNumericField(string name, bool sortable = false, bool noIndex = /// /// Add a Tag field to the schema. /// - /// The field's name. - /// If true, the field can be sorted. - /// Set this to true to prevent the indexer from sorting on the normalized form. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The tag separator. - /// If true, Keeps the original letter cases of the tags. + /// The field's name. + /// If true, the field can be sorted. + /// Set this to true to prevent the indexer from sorting on the normalized form. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The tag separator. + /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. + /// Keeps a suffix trie with all terms which match the suffix. /// The object. public Schema AddTagField(FieldName name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", @@ -421,14 +421,14 @@ public Schema AddTagField(FieldName name, bool sortable = false, bool unf = fals /// /// Add a Tag field to the schema. /// - /// The field's name. - /// If true, the field can be sorted. - /// Set this to true to prevent the indexer from sorting on the normalized form. - /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The tag separator. - /// If true, Keeps the original letter cases of the tags. + /// The field's name. + /// If true, the field can be sorted. + /// Set this to true to prevent the indexer from sorting on the normalized form. + /// Attributes can have the NOINDEX option, which means they will not be indexed. + /// The tag separator. + /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed - /// Keeps a suffix trie with all terms which match the suffix. + /// Keeps a suffix trie with all terms which match the suffix. /// The object. public Schema AddTagField(string name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", @@ -441,9 +441,9 @@ public Schema AddTagField(string name, bool sortable = false, bool unf = false, /// /// Add a Vector field to the schema. /// - /// The field's name. - /// The vector similarity algorithm to use. - /// The algorithm attributes for the creation of the vector index. + /// The field's name. + /// The vector similarity algorithm to use. + /// The algorithm attributes for the creation of the vector index. /// The object. public Schema AddVectorField(FieldName name, VectorAlgo algorithm, Dictionary? attributes = null) { @@ -454,9 +454,9 @@ public Schema AddVectorField(FieldName name, VectorAlgo algorithm, Dictionary /// Add a Vector field to the schema. /// - /// The field's name. - /// The vector similarity algorithm to use. - /// The algorithm attributes for the creation of the vector index. + /// The field's name. + /// The vector similarity algorithm to use. + /// The algorithm attributes for the creation of the vector index. /// The object. public Schema AddVectorField(string name, VectorAlgo algorithm, Dictionary? attributes = null) { From 7c134e5d828df8b7cd9d3dd86cfd6608a962d968 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 5 Mar 2024 17:52:53 +0200 Subject: [PATCH 08/10] fix Regex mistakes --- src/NRedisStack/Search/Schema.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/NRedisStack/Search/Schema.cs b/src/NRedisStack/Search/Schema.cs index 02bc3d6e..b0d379ee 100644 --- a/src/NRedisStack/Search/Schema.cs +++ b/src/NRedisStack/Search/Schema.cs @@ -274,8 +274,8 @@ internal override void AddFieldTypeArgs(List args) /// /// Add a field to the schema. /// - /// The to add. - /// The object. + /// The to add. + /// The object. public Schema AddField(Field field) { Fields.Add(field ?? throw new ArgumentNullException(nameof(field))); @@ -294,7 +294,7 @@ public Schema AddField(Field field) /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// The object. public Schema AddTextField(string name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) { @@ -314,7 +314,7 @@ public Schema AddTextField(string name, double weight = 1.0, bool sortable = fal /// Set this to true to prevent the indexer from sorting on the normalized form. /// Normalied form is the field sent to lower case with all diaretics removed /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// The object. public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = false, bool unf = false, bool noStem = false, string? phonetic = null, bool noIndex = false, bool withSuffixTrie = false) { @@ -327,7 +327,7 @@ public Schema AddTextField(FieldName name, double weight = 1.0, bool sortable = /// /// The field's name. /// The coordinate system to use. - /// The object. + /// The object. public Schema AddGeoShapeField(string name, CoordinateSystem system) { Fields.Add(new GeoShapeField(name, system)); @@ -339,7 +339,7 @@ public Schema AddGeoShapeField(string name, CoordinateSystem system) /// /// The field's name. /// The coordinate system to use. - /// The object. + /// The object. public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) { Fields.Add(new GeoShapeField(name, system)); @@ -352,7 +352,7 @@ public Schema AddGeoShapeField(FieldName name, CoordinateSystem system) /// The field's name. /// If true, the text field can be sorted. /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The object. public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = false) { Fields.Add(new GeoField(name, sortable, noIndex)); @@ -365,7 +365,7 @@ public Schema AddGeoField(FieldName name, bool sortable = false, bool noIndex = /// The field's name. /// If true, the text field can be sorted. /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The object. public Schema AddGeoField(string name, bool sortable = false, bool noIndex = false) { Fields.Add(new GeoField(name, sortable, noIndex)); @@ -378,7 +378,7 @@ public Schema AddGeoField(string name, bool sortable = false, bool noIndex = fal /// The field's name. /// If true, the text field can be sorted. /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The object. public Schema AddNumericField(FieldName name, bool sortable = false, bool noIndex = false) { Fields.Add(new NumericField(name, sortable, noIndex)); @@ -391,7 +391,7 @@ public Schema AddNumericField(FieldName name, bool sortable = false, bool noInde /// The field's name. /// If true, the text field can be sorted. /// Attributes can have the NOINDEX option, which means they will not be indexed. - /// The object. + /// The object. public Schema AddNumericField(string name, bool sortable = false, bool noIndex = false) { Fields.Add(new NumericField(name, sortable, noIndex)); @@ -409,7 +409,7 @@ public Schema AddNumericField(string name, bool sortable = false, bool noIndex = /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// The object. public Schema AddTagField(FieldName name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", bool caseSensitive = false, bool withSuffixTrie = false) @@ -429,7 +429,7 @@ public Schema AddTagField(FieldName name, bool sortable = false, bool unf = fals /// If true, Keeps the original letter cases of the tags. /// Normalied form is the field sent to lower case with all diaretics removed /// Keeps a suffix trie with all terms which match the suffix. - /// The object. + /// The object. public Schema AddTagField(string name, bool sortable = false, bool unf = false, bool noIndex = false, string separator = ",", bool caseSensitive = false, bool withSuffixTrie = false) @@ -444,7 +444,7 @@ public Schema AddTagField(string name, bool sortable = false, bool unf = false, /// The field's name. /// The vector similarity algorithm to use. /// The algorithm attributes for the creation of the vector index. - /// The object. + /// The object. public Schema AddVectorField(FieldName name, VectorAlgo algorithm, Dictionary? attributes = null) { Fields.Add(new VectorField(name, algorithm, attributes)); @@ -457,7 +457,7 @@ public Schema AddVectorField(FieldName name, VectorAlgo algorithm, DictionaryThe field's name. /// The vector similarity algorithm to use. /// The algorithm attributes for the creation of the vector index. - /// The object. + /// The object. public Schema AddVectorField(string name, VectorAlgo algorithm, Dictionary? attributes = null) { Fields.Add(new VectorField(name, algorithm, attributes)); From 8e4ae88c3cc0b4ec5ea4f6c0f1fd9bd26732c123 Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 7 Mar 2024 13:22:10 +0200 Subject: [PATCH 09/10] delete unnessesary definition --- tests/NRedisStack.Tests/Search/SearchTests.cs | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index f7224ba3..423e7199 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -331,20 +331,14 @@ 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")) .Params(parameters) .Dialect(2); // From documentation - To use PARAMS, DIALECT must be set to 2 - // Add more parameters using params (more than 1 is also possible): - // parameters.Clear(); - parameters.Add("count", "10"); - r = new AggregationRequest("$name") - .GroupBy("@name", Reducers.Sum("@count").As("sum")) - .Params(parameters) - .Dialect(2); - AggregationResult res = await ft.AggregateAsync(index, r); Assert.Equal(1, res.TotalResults); @@ -2996,4 +2990,16 @@ public void Issue230() Assert.Equal("FT.AGGREGATE", buildCommand.Command); Assert.Equal(new object[] { "idx:users", "*", "FILTER", "@StatusId==1", "GROUPBY", 1, "@CreatedDay", "REDUCE", "COUNT_DISTINCT", 1, "@UserId", "REDUCE", "COUNT", 0, "AS", "count", "DIALECT", 3 }, buildCommand.Args); } + + [Fact] + public void CheckLoad() + { + var req = new AggregationRequest("*").Load(new FieldName("t1"), new FieldName("t2"), new FieldName("t3")); + var buildCommand = SearchCommandBuilder.Aggregate("idx:users", req); + // expected: FT.AGGREGATE idx:users * LOAD 3 @t1 @t2 @t3 DIALECT 3 + Assert.Equal("FT.AGGREGATE", buildCommand.Command); + Assert.Equal(new object[] { "idx:users", "*", "LOAD", 3, "@t1", "@t2", "@t3", "DIALECT", 3 }, buildCommand.Args); + + + } } From 7ad95fef01fb48cfa81d060c5b696a0f51e9d3ba Mon Sep 17 00:00:00 2001 From: shacharPash Date: Thu, 7 Mar 2024 13:27:38 +0200 Subject: [PATCH 10/10] deleted a test that was slipped in by mistake --- tests/NRedisStack.Tests/Search/SearchTests.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/NRedisStack.Tests/Search/SearchTests.cs b/tests/NRedisStack.Tests/Search/SearchTests.cs index 423e7199..0376a54c 100644 --- a/tests/NRedisStack.Tests/Search/SearchTests.cs +++ b/tests/NRedisStack.Tests/Search/SearchTests.cs @@ -2990,16 +2990,4 @@ public void Issue230() Assert.Equal("FT.AGGREGATE", buildCommand.Command); Assert.Equal(new object[] { "idx:users", "*", "FILTER", "@StatusId==1", "GROUPBY", 1, "@CreatedDay", "REDUCE", "COUNT_DISTINCT", 1, "@UserId", "REDUCE", "COUNT", 0, "AS", "count", "DIALECT", 3 }, buildCommand.Args); } - - [Fact] - public void CheckLoad() - { - var req = new AggregationRequest("*").Load(new FieldName("t1"), new FieldName("t2"), new FieldName("t3")); - var buildCommand = SearchCommandBuilder.Aggregate("idx:users", req); - // expected: FT.AGGREGATE idx:users * LOAD 3 @t1 @t2 @t3 DIALECT 3 - Assert.Equal("FT.AGGREGATE", buildCommand.Command); - Assert.Equal(new object[] { "idx:users", "*", "LOAD", 3, "@t1", "@t2", "@t3", "DIALECT", 3 }, buildCommand.Args); - - - } }