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

Move SORTABLE to the end of the build command #176

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
{
@@ -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)
@@ -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 != ",")
@@ -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");
}
}

@@ -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);
}

}
@@ -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);
}

}
31 changes: 25 additions & 6 deletions tests/NRedisStack.Tests/Search/SearchTests.cs
Original file line number Diff line number Diff line change
@@ -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",
@@ -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));
}
}