Skip to content

Commit

Permalink
Move SORTABLE to the end of the build command (#176)
Browse files Browse the repository at this point in the history
* fix Issue

* delete comments & cover TEXT also
  • Loading branch information
shacharPash authored Aug 20, 2023
1 parent 80ec286 commit c99124b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
15 changes: 8 additions & 7 deletions src/NRedisStack/Search/Schema.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using static NRedisStack.Search.Schema.VectorField;
using NRedisStack.Search.Literals;
using static NRedisStack.Search.Schema.VectorField;

namespace NRedisStack.Search
{
Expand Down Expand Up @@ -84,13 +85,13 @@ public TextField(string name, double weight = 1.0, bool noStem = false,

internal override void AddFieldTypeArgs(List<object> args)
{
if (Sortable) args.Add("SORTABLE");
if (Unf) args.Add("UNF");
if (NoStem) args.Add("NOSTEM");
if (NoIndex) args.Add("NOINDEX");
AddPhonetic(args);
AddWeight(args);
if (WithSuffixTrie) args.Add("WITHSUFFIXTRIE");
if (Sortable) args.Add(AttributeOptions.SORTABLE);
if (Unf) args.Add("UNF");
}

private void AddWeight(List<object> args)
Expand Down Expand Up @@ -141,8 +142,6 @@ internal TagField(string name, bool sortable = false, bool unf = false,

internal override void AddFieldTypeArgs(List<object> args)
{
if (Sortable) args.Add("SORTABLE");
if (Unf) args.Add("UNF");
if (NoIndex) args.Add("NOINDEX");
if (WithSuffixTrie) args.Add("WITHSUFFIXTRIE");
if (Separator != ",")
Expand All @@ -152,6 +151,8 @@ internal override void AddFieldTypeArgs(List<object> args)
args.Add(Separator);
}
if (CaseSensitive) args.Add("CASESENSITIVE");
if (Sortable) args.Add(AttributeOptions.SORTABLE);
if (Unf) args.Add("UNF");
}
}

Expand All @@ -171,8 +172,8 @@ internal GeoField(string name, bool sortable = false, bool noIndex = false)

internal override void AddFieldTypeArgs(List<object> args)
{
if (Sortable) args.Add("SORTABLE");
if (NoIndex) args.Add("NOINDEX");
if (Sortable) args.Add(AttributeOptions.SORTABLE);
}

}
Expand All @@ -193,8 +194,8 @@ internal NumericField(string name, bool sortable = false, bool noIndex = false)

internal override void AddFieldTypeArgs(List<object> args)
{
if (Sortable) args.Add("SORTABLE");
if (NoIndex) args.Add("NOINDEX");
if (Sortable) args.Add(AttributeOptions.SORTABLE);
}

}
Expand Down
31 changes: 25 additions & 6 deletions tests/NRedisStack.Tests/Search/SearchTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1962,30 +1962,30 @@ public void TestFieldsCommandBuilder()
"SCHEMA",
"txt",
"TEXT",
"SORTABLE",
"UNF",
"NOSTEM",
"NOINDEX",
"PHONETIC",
"dm:en",
"WITHSUFFIXTRIE",
"SORTABLE",
"UNF",
"num",
"NUMERIC",
"SORTABLE",
"NOINDEX",
"SORTABLE",
"loc",
"GEO",
"SORTABLE",
"NOINDEX",
"SORTABLE",
"tag",
"TAG",
"SORTABLE",
"UNF",
"NOINDEX",
"WITHSUFFIXTRIE",
"SEPARATOR",
";",
"CASESENSITIVE",
"SORTABLE",
"UNF",
"vec",
"VECTOR",
"FLAT",
Expand Down Expand Up @@ -2752,4 +2752,23 @@ public void TestProfileCommandBuilder()
Assert.Equal(new object[] { "index", "SEARCH", "LIMITED", "QUERY", "*" }, search.Args);
Assert.Equal(new object[] { "index", "AGGREGATE", "LIMITED", "QUERY", "*" }, aggregate.Args);
}

[Fact]
public void Issue175()
{
ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost:6379");
IDatabase db = redis.GetDatabase();
db.Execute("FLUSHALL");

SearchCommands ft = db.FT();

var sortable = true;
var ftParams = new FTCreateParams()
.On(IndexDataType.JSON)
.Prefix("doc:");
var schema = new Schema().AddTagField("tag", sortable, false, false, "|")
.AddTextField("text", 1, sortable);

Assert.True(ft.Create("myIndex", ftParams, schema));
}
}

0 comments on commit c99124b

Please sign in to comment.