forked from tombatron/RediSearchClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Supporting the creation of a JSON index from a given generic type.
- Loading branch information
1 parent
bd8f836
commit 999322a
Showing
20 changed files
with
532 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
namespace RediSearchClient.SampleData.TestingTypes | ||
{ | ||
public class Dimensions | ||
{ | ||
public float Length { get; set; } | ||
|
||
public float Width { get; set; } | ||
|
||
public float Height { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using RediSearchClient.Attributes; | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace RediSearchClient.SampleData.TestingTypes | ||
{ | ||
[DefaultNoIndex] | ||
public class Product | ||
{ | ||
[Tag] | ||
[Index] | ||
[Alias("id")] | ||
public string Identifier { get; set; } | ||
|
||
[Sortable] | ||
public decimal Price { get; set; } | ||
|
||
public string Meta { get; set; } | ||
|
||
[SchemaIgnore] | ||
public int Count { get; set; } | ||
|
||
public Dimensions Dimensions { get; set; } | ||
|
||
public ICollection<Seller> Sellers { get; set; } | ||
|
||
public Product RelatedProduct { get; set; } //Will be ignored to avoid recursion | ||
|
||
public DateTime DateAdded { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace RediSearchClient.SampleData.TestingTypes | ||
{ | ||
public class Seller | ||
{ | ||
public string Name { get; set; } | ||
|
||
public IEnumerable<Product> SoldProducts { get; set; } //Will be ignored to avoid recursion | ||
|
||
public IEnumerable<string> Locations { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class AliasAttribute : Attribute | ||
{ | ||
public string Name { get; private set; } | ||
|
||
public AliasAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
/// <summary> | ||
/// All properties are indexable by default. This attribute will specify that properties on a type that is used to create a RediSearch JSON Schema are non-indexable by default, use [Index] on target properties to override this behavior | ||
/// </summary> | ||
public sealed class DefaultNoIndexAttribute : Attribute | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
/// <summary> | ||
/// Use to specify if a property is indexable, defaults to true | ||
/// </summary> | ||
public sealed class IndexAttribute : Attribute | ||
{ | ||
public bool Value { get; private set; } | ||
|
||
public IndexAttribute(bool value) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public IndexAttribute() | ||
{ | ||
Value = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class NonStemmableAttribute : Attribute | ||
{ | ||
public NonStemmableAttribute() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using RediSearchClient.Indexes; | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class PhoneticAttribute : Attribute | ||
{ | ||
public Language Language { get; private set; } | ||
|
||
public PhoneticAttribute(Language language) | ||
{ | ||
Language = language; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class SchemaIgnoreAttribute : Attribute | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class SortableAttribute : Attribute | ||
{ | ||
public SortableAttribute() | ||
{ | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class TagAttribute : Attribute | ||
{ | ||
public string Separator { get; private set; } = ","; | ||
|
||
public TagAttribute(string separator) | ||
{ | ||
Separator = separator; | ||
} | ||
|
||
public TagAttribute() | ||
{ | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
|
||
namespace RediSearchClient.Attributes | ||
{ | ||
public sealed class WeightAttribute : Attribute | ||
{ | ||
public int Weight { get; private set; } | ||
|
||
public WeightAttribute(int weight) | ||
{ | ||
Weight = weight; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RediSearchClient.Converters | ||
{ | ||
/// <summary> | ||
/// RediSearch does not natively support DateTime types, therefore we need to convert DateTimes to numerics in this case | ||
/// </summary> | ||
internal sealed class DateTimeToNumericConverter : JsonConverter<DateTime> | ||
{ | ||
public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) | ||
{ | ||
writer.WriteNumberValue((value - DateTime.MinValue).TotalSeconds); | ||
} | ||
} | ||
} |
Oops, something went wrong.