├── icon.png
├── .gitignore
├── src
└── Typesense
│ ├── ImportType.cs
│ ├── DeleteKeyResponse.cs
│ ├── HttpContents
│ ├── Bytes.cs
│ ├── StreamStringLinesHttpContent.cs
│ └── StreamJsonLinesHttpContent.cs
│ ├── HealthResponse.cs
│ ├── DeleteSynonymResponse.cs
│ ├── SnapshotResponse.cs
│ ├── CompactDiskResponse.cs
│ ├── DeleteSearchOverrideResponse.cs
│ ├── FilterUpdateResponse.cs
│ ├── FilterDeleteResponse.cs
│ ├── TruncateCollectionResponse.cs
│ ├── ExportParameters.cs
│ ├── ListKeysResponse.cs
│ ├── UpdateCollectionResponse.cs
│ ├── ListSynonymsResponse.cs
│ ├── CollectionAliasResponse.cs
│ ├── ListSearchOverridesResponse.cs
│ ├── ListCollectionAliasesResponse.cs
│ ├── CollectionAlias.cs
│ ├── SynonymSchema.cs
│ ├── Setup
│ ├── Config.cs
│ ├── TypesenseExtension.cs
│ └── Node.cs
│ ├── ImportResponse.cs
│ ├── Converter
│ ├── UnixEpochDateTimeConverter.cs
│ ├── VectorQueryConverter.cs
│ ├── UnixEpochDateTimeLongConverter.cs
│ ├── GroupKeyConverter.cs
│ ├── MatchedTokenConverter.cs
│ └── JsonStringEnumConverter.cs
│ ├── SynonymSchemaResponse.cs
│ ├── FieldType.cs
│ ├── Key.cs
│ ├── Typesense.csproj
│ ├── KeyResponse.cs
│ ├── AutoEmbeddingConfig.cs
│ ├── Schema.cs
│ ├── CollectionResponse.cs
│ ├── SearchOverrideResponse.cs
│ ├── StatsResponse.cs
│ ├── UpdateSchema.cs
│ ├── TypesenseApiException.cs
│ ├── SearchOverride.cs
│ ├── MetricsResponse.cs
│ ├── Field.cs
│ ├── VectorSearchQuery.cs
│ ├── SearchResult.cs
│ ├── SearchParameters.cs
│ └── TypesenseClient.cs
├── examples
└── Example
│ ├── Address.cs
│ ├── Example.csproj
│ └── Program.cs
├── test
└── Typesense.Tests
│ ├── Typesense.Tests.csproj
│ ├── PriorityOrderer.cs
│ ├── TypesenseFixture.cs
│ └── TypesenseConverterTests.cs
├── LICENSE
├── .editorconfig
├── .circleci
└── config.yml
├── typesense-dotnet.sln
└── README.md
/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/DAXGRID/typesense-dotnet/HEAD/icon.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ### DotnetCore ###
2 | # .NET Core build folders
3 | bin/
4 | obj/
5 | .vscode
6 | .cache
7 | .vs
--------------------------------------------------------------------------------
/src/Typesense/ImportType.cs:
--------------------------------------------------------------------------------
1 | namespace Typesense;
2 |
3 | public enum ImportType
4 | {
5 | Create,
6 | Upsert,
7 | Update,
8 | Emplace
9 | }
10 |
--------------------------------------------------------------------------------
/src/Typesense/DeleteKeyResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record DeleteKeyResponse
6 | {
7 | [JsonPropertyName("id")]
8 | public int Id { get; set; }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Typesense/HttpContents/Bytes.cs:
--------------------------------------------------------------------------------
1 | namespace Typesense.HttpContents;
2 | /// To avoid warnings in the generic class
3 | public static class Bytes
4 | {
5 | public static readonly byte[] NewLine = { (byte)'\n' };
6 | }
--------------------------------------------------------------------------------
/examples/Example/Address.cs:
--------------------------------------------------------------------------------
1 | namespace Example;
2 |
3 | class Address
4 | {
5 | public string Id { get; set; }
6 | public int HouseNumber { get; set; }
7 | public string AccessAddress { get; set; }
8 | public string MetadataNotes { get; set; }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Typesense/HealthResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public sealed record HealthResponse
6 | {
7 | [JsonPropertyName("ok")]
8 | public bool Ok { get; init; }
9 |
10 | [JsonConstructor]
11 | public HealthResponse(bool ok)
12 | {
13 | Ok = ok;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/DeleteSynonymResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record DeleteSynonymResponse
6 | {
7 | [JsonPropertyName("id")]
8 | public string Id { get; init; }
9 |
10 | [JsonConstructor]
11 | public DeleteSynonymResponse(string id)
12 | {
13 | Id = id;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/SnapshotResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record SnapshotResponse
6 | {
7 | [JsonPropertyName("success")]
8 | public bool Success { get; init; }
9 |
10 | [JsonConstructor]
11 | public SnapshotResponse(bool success)
12 | {
13 | Success = success;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Typesense/CompactDiskResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record CompactDiskResponse
6 | {
7 | [JsonPropertyName("success")]
8 | public bool Success { get; init; }
9 |
10 | [JsonConstructor]
11 | public CompactDiskResponse(bool success)
12 | {
13 | Success = success;
14 | }
15 | }
--------------------------------------------------------------------------------
/src/Typesense/DeleteSearchOverrideResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record DeleteSearchOverrideResponse
6 | {
7 | [JsonPropertyName("id")]
8 | public string Id { get; init; }
9 |
10 | [JsonConstructor]
11 | public DeleteSearchOverrideResponse(string id)
12 | {
13 | Id = id;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/FilterUpdateResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record FilterUpdateResponse
6 | {
7 | [JsonPropertyName("num_updated")]
8 | public int NumberUpdated { get; init; }
9 |
10 | [JsonConstructor]
11 | public FilterUpdateResponse(int numberUpdated)
12 | {
13 | NumberUpdated = numberUpdated;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/FilterDeleteResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record FilterDeleteResponse
6 | {
7 | [JsonPropertyName("num_deleted")]
8 | public int NumberOfDeleted { get; init; }
9 |
10 | [JsonConstructor]
11 | public FilterDeleteResponse(int numberOfDeleted)
12 | {
13 | NumberOfDeleted = numberOfDeleted;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/TruncateCollectionResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record TruncateCollectionResponse
6 | {
7 | [JsonPropertyName("num_deleted")]
8 | public int NumDeleted { get; init; }
9 |
10 | [JsonConstructor]
11 | public TruncateCollectionResponse(int numDeleted)
12 | {
13 | NumDeleted = numDeleted;
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/ExportParameters.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record ExportParameters
6 | {
7 | [JsonPropertyName("filter_by")]
8 | public string? FilterBy { get; set; }
9 |
10 | [JsonPropertyName("include_fields")]
11 | public string? IncludeFields { get; set; }
12 |
13 | [JsonPropertyName("exclude_fields")]
14 | public string? ExcludeFields { get; set; }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Typesense/ListKeysResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record ListKeysResponse
7 | {
8 | [JsonPropertyName("keys")]
9 | public IReadOnlyCollection Keys { get; init; }
10 |
11 | [JsonConstructor]
12 | public ListKeysResponse(IReadOnlyCollection keys)
13 | {
14 | Keys = keys;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Typesense/UpdateCollectionResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record UpdateCollectionResponse
7 | {
8 | [JsonPropertyName("fields")]
9 | public IReadOnlyList Fields { get; init; }
10 |
11 | [JsonConstructor]
12 | public UpdateCollectionResponse(IReadOnlyList fields)
13 | {
14 | Fields = fields;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/examples/Example/Example.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 | Exe
13 | net8.0
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Typesense/ListSynonymsResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record ListSynonymsResponse
7 | {
8 | [JsonPropertyName("synonyms")]
9 | public IReadOnlyCollection Synonyms { get; init; }
10 |
11 | [JsonConstructor]
12 | public ListSynonymsResponse(IReadOnlyCollection synonyms)
13 | {
14 | Synonyms = synonyms;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Typesense/CollectionAliasResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record CollectionAliasResponse
6 | {
7 | [JsonPropertyName("collection_name")]
8 | public string CollectionName { get; init; }
9 |
10 | [JsonPropertyName("name")]
11 | public string Name { get; init; }
12 |
13 | [JsonConstructor]
14 | public CollectionAliasResponse(string collectionName, string name)
15 | {
16 | CollectionName = collectionName;
17 | Name = name;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Typesense/ListSearchOverridesResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record ListSearchOverridesResponse
7 | {
8 | [JsonPropertyName("overrides")]
9 | public IReadOnlyCollection SearchOverrides { get; init; }
10 |
11 | [JsonConstructor]
12 | public ListSearchOverridesResponse(IReadOnlyCollection searchOverrides)
13 | {
14 | SearchOverrides = searchOverrides;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Typesense/ListCollectionAliasesResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record ListCollectionAliasesResponse
7 | {
8 | [JsonPropertyName("aliases")]
9 | public IReadOnlyCollection CollectionAliases { get; init; }
10 |
11 | [JsonConstructor]
12 | public ListCollectionAliasesResponse(IReadOnlyCollection collectionAliases)
13 | {
14 | CollectionAliases = collectionAliases;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Typesense/CollectionAlias.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record CollectionAlias
7 | {
8 | [JsonPropertyName("collection_name")]
9 | public string CollectionName { get; init; }
10 |
11 | public CollectionAlias(string collectionName)
12 | {
13 | if (string.IsNullOrWhiteSpace(collectionName))
14 | throw new ArgumentException(
15 | $"{nameof(collectionName)} cannot be null, empty or whitespace.");
16 | CollectionName = collectionName;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Typesense/SynonymSchema.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record SynonymSchema
7 | {
8 | [JsonPropertyName("synonyms")]
9 | public IEnumerable Synonyms { get; init; }
10 |
11 | [JsonPropertyName("root")]
12 | public string? Root { get; init; }
13 |
14 | [JsonPropertyName("symbols_to_index")]
15 | public IEnumerable? SymbolsToIndex { get; init; }
16 |
17 | public SynonymSchema(IEnumerable synonyms)
18 | {
19 | Synonyms = synonyms;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Typesense/Setup/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text.Json;
4 |
5 | namespace Typesense.Setup;
6 |
7 | public record Config
8 | {
9 | public IReadOnlyCollection Nodes { get; set; }
10 | public string ApiKey { get; set; }
11 | public JsonSerializerOptions? JsonSerializerOptions { get; set; }
12 |
13 | [Obsolete("Use multi-arity constructor instead.")]
14 | public Config()
15 | {
16 | Nodes = new List();
17 | ApiKey = "";
18 | }
19 |
20 | public Config(IReadOnlyCollection nodes, string apiKey)
21 | {
22 | Nodes = nodes;
23 | ApiKey = apiKey;
24 | }
25 | }
--------------------------------------------------------------------------------
/src/Typesense/ImportResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Text.Json.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public record ImportResponse
6 | {
7 | [JsonPropertyName("success")]
8 | public bool Success { get; init; }
9 |
10 | [JsonPropertyName("error")]
11 | public string? Error { get; init; }
12 |
13 | [JsonPropertyName("document")]
14 | public string? Document { get; init; }
15 |
16 | [JsonPropertyName("id")]
17 | public string? Id { get; init; }
18 |
19 | [JsonConstructor]
20 | public ImportResponse(bool success, string? error = null, string? document = null, string? id = null)
21 | {
22 | Success = success;
23 | Error = error;
24 | Document = document;
25 | Id = id;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/src/Typesense/Converter/UnixEpochDateTimeConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Text.Json;
4 | using System.Text.Json.Serialization;
5 |
6 | namespace Typesense.Converter;
7 |
8 | public class UnixEpochDateTimeConverter : JsonConverter
9 | {
10 | public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
11 | {
12 | return DateTime.UnixEpoch.AddSeconds(reader.GetInt64());
13 | }
14 |
15 | public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
16 | {
17 | ArgumentNullException.ThrowIfNull(writer);
18 | writer.WriteStringValue((value - DateTime.UnixEpoch).TotalSeconds.ToString(CultureInfo.InvariantCulture));
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Typesense/SynonymSchemaResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record SynonymSchemaResponse
7 | {
8 | [JsonPropertyName("id")]
9 | public string Id { get; init; }
10 |
11 | [JsonPropertyName("synonyms")]
12 | public IReadOnlyCollection Synonyms { get; init; }
13 |
14 | [JsonPropertyName("root")]
15 | public string Root { get; init; }
16 |
17 | [JsonPropertyName("symbols_to_index")]
18 | public IReadOnlyCollection SymbolsToIndex { get; init; }
19 |
20 | [JsonConstructor]
21 | public SynonymSchemaResponse(string id,
22 | IReadOnlyCollection synonyms,
23 | string root,
24 | IReadOnlyCollection symbolsToIndex)
25 | {
26 | Id = id;
27 | Synonyms = synonyms;
28 | Root = root;
29 | SymbolsToIndex = symbolsToIndex;
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Typesense/Converter/VectorQueryConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.Json;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace Typesense.Converter;
6 |
7 | public class VectorQueryJsonConverter : JsonConverter
8 | {
9 | public override bool CanConvert(Type typeToConvert)
10 | {
11 | return typeToConvert == typeof(VectorQuery);
12 | }
13 |
14 | public override VectorQuery Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
15 | {
16 | var jsonValue = reader.GetString() ?? string.Empty;
17 | return !String.IsNullOrEmpty(jsonValue) ? new VectorQuery(jsonValue) : null!;
18 | }
19 |
20 | public override void Write(Utf8JsonWriter writer, VectorQuery value, JsonSerializerOptions options)
21 | {
22 | ArgumentNullException.ThrowIfNull(writer);
23 | ArgumentNullException.ThrowIfNull(value);
24 |
25 | writer.WriteStringValue(value.ToQuery());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/test/Typesense.Tests/Typesense.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | runtime; build; native; contentfiles; analyzers; buildtransitive
15 | all
16 |
17 |
18 | runtime; build; native; contentfiles; analyzers; buildtransitive
19 | all
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 DAX
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/Typesense/Converter/UnixEpochDateTimeLongConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Text.Json;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace Typesense.Converter;
6 |
7 | ///
8 | /// Converts between nullable DateTime and Unix epoch seconds as a long integer value.
9 | ///
10 | public class UnixEpochDateTimeLongConverter : JsonConverter
11 | {
12 | public override DateTime? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
13 | {
14 | if (reader.TokenType == JsonTokenType.Null)
15 | return null;
16 |
17 | return DateTime.UnixEpoch.AddSeconds(reader.GetInt64());
18 | }
19 |
20 | public override void Write(Utf8JsonWriter writer, DateTime? value, JsonSerializerOptions options)
21 | {
22 | ArgumentNullException.ThrowIfNull(writer);
23 |
24 | if (value == null)
25 | {
26 | writer.WriteNullValue();
27 | return;
28 | }
29 |
30 | writer.WriteNumberValue(Convert.ToInt64((value.Value - DateTime.UnixEpoch).TotalSeconds));
31 | }
32 | }
--------------------------------------------------------------------------------
/src/Typesense/FieldType.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.Serialization;
2 |
3 | namespace Typesense;
4 |
5 | public enum FieldType
6 | {
7 | [EnumMember(Value = "string")]
8 | String,
9 |
10 | [EnumMember(Value = "string[]")]
11 | StringArray,
12 |
13 | [EnumMember(Value = "int32")]
14 | Int32,
15 |
16 | [EnumMember(Value = "int32[]")]
17 | Int32Array,
18 |
19 | [EnumMember(Value = "int64")]
20 | Int64,
21 |
22 | [EnumMember(Value = "int64[]")]
23 | Int64Array,
24 |
25 | [EnumMember(Value = "float")]
26 | Float,
27 |
28 | [EnumMember(Value = "float[]")]
29 | FloatArray,
30 |
31 | [EnumMember(Value = "bool")]
32 | Bool,
33 |
34 | [EnumMember(Value = "bool[]")]
35 | BoolArray,
36 |
37 | [EnumMember(Value = "geopoint")]
38 | GeoPoint,
39 |
40 | [EnumMember(Value = "geopoint[]")]
41 | GeoPointArray,
42 |
43 | [EnumMember(Value = "object")]
44 | Object,
45 |
46 | [EnumMember(Value = "object[]")]
47 | ObjectArray,
48 |
49 | [EnumMember(Value = "string*")]
50 | AutoString,
51 |
52 | [EnumMember(Value = "auto")]
53 | Auto,
54 |
55 | [EnumMember(Value = "image")]
56 | Image,
57 | }
58 |
--------------------------------------------------------------------------------
/src/Typesense/Key.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace Typesense;
6 |
7 | public record Key
8 | {
9 | [JsonPropertyName("actions")]
10 | public IReadOnlyCollection Actions { get; init; }
11 |
12 | [JsonPropertyName("description")]
13 | public string Description { get; init; }
14 |
15 | [JsonPropertyName("collections")]
16 | public IReadOnlyCollection Collections { get; init; }
17 |
18 | [JsonPropertyName("value")]
19 | public string? Value { get; init; }
20 |
21 | [JsonPropertyName("expires_at")]
22 | public long? ExpiresAt { get; init; }
23 |
24 | [JsonPropertyName("autodelete")]
25 | public bool? AutoDelete { get; set; }
26 |
27 | [Obsolete("Use multi-arity constructor instead.")]
28 | public Key()
29 | {
30 | Actions = new List();
31 | Description = string.Empty;
32 | Collections = new List();
33 | }
34 |
35 | public Key(
36 | string description,
37 | IReadOnlyCollection actions,
38 | IReadOnlyCollection collections)
39 | {
40 | Actions = actions;
41 | Description = description;
42 | Collections = collections;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Typesense/Typesense.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net8.0;net7.0;net6.0;
5 | true
6 | true
7 | All
8 | enable
9 |
10 | Typesense
11 | .NET HTTP client for Typesense.
12 | typesense;search;search-engine;fuzzy-search;instant-search
13 | icon.png
14 | git
15 | https://github.com/DAXGRID/typesense-dotnet
16 | MIT
17 | true
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/src/Typesense/KeyResponse.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record KeyResponse
7 | {
8 | [JsonPropertyName("id")]
9 | public int Id { get; init; }
10 |
11 | [JsonPropertyName("value")]
12 | public string Value { get; init; }
13 |
14 | [JsonPropertyName("value_prefix")]
15 | public string ValuePrefix { get; init; }
16 |
17 | [JsonPropertyName("description")]
18 | public string? Description { get; init; }
19 |
20 | [JsonPropertyName("actions")]
21 | public IReadOnlyCollection? Actions { get; init; }
22 |
23 | [JsonPropertyName("collections")]
24 | public IReadOnlyCollection? Collections { get; init; }
25 |
26 | [JsonPropertyName("expires_at")]
27 | public long ExpiresAt { get; init; }
28 |
29 | [JsonConstructor]
30 | public KeyResponse(
31 | int id,
32 | string value,
33 | string valuePrefix,
34 | long expiresAt,
35 | string? description = null,
36 | IReadOnlyCollection? actions = null,
37 | IReadOnlyCollection? collections = null)
38 | {
39 | Id = id;
40 | Value = value;
41 | ValuePrefix = valuePrefix;
42 | ExpiresAt = expiresAt;
43 | Description = description;
44 | Actions = actions;
45 | Collections = collections;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.cs]
2 | #dotnet_analyzer_diagnostic.severity = error
3 |
4 | # IDE0007 and IDE0008 'var' preferences
5 | csharp_style_var_for_built_in_types = true
6 | csharp_style_var_when_type_is_apparent = true
7 | csharp_style_var_elsewhere = true
8 |
9 | # IDE0011 Add braces
10 | csharp_prefer_braces = false
11 |
12 | # IDE0022 Use expression body for methods
13 | csharp_style_expression_bodied_methods = when_on_single_line
14 |
15 | # IDE0160: Convert to file-scoped namespace
16 | csharp_style_namespace_declarations = file_scoped:error
17 |
18 | # IDE0058: Expression value is never used
19 | dotnet_diagnostic.CA1707.severity = silent
20 |
21 | # CA1014: Mark assemblies with CLSCompliantAttribute
22 | dotnet_diagnostic.CA1014.severity = none
23 |
24 | # CA2007: Do not directly await a Task
25 | dotnet_diagnostic.CA2007.severity = silent
26 |
27 | # CA1720: Identifiers should not contain type names
28 | dotnet_diagnostic.CA1720.severity = silent
29 |
30 | # CA1724: Type names should not match namespaces
31 | dotnet_diagnostic.CA1724.severity = silent
32 |
33 | # CA1711: Identifiers should not have incorrect suffix
34 | dotnet_diagnostic.CA1711.severity = silent
35 |
36 | # CA1308: Normalize strings to uppercase
37 | dotnet_diagnostic.CA1308.severity = silent
38 |
39 | # CA2234: Pass System.Uri objects instead of strings
40 | dotnet_diagnostic.CA2234.severity = silent
41 |
42 |
43 | # CS1591: Ignored for now, until we decide to have comments on everything
44 | dotnet_diagnostic.CS1591.severity = silent
45 |
46 | [test/**.cs]
47 | # IDE0058 Remove unnecessary expression value
48 | dotnet_diagnostic.IDE0058.severity = silent
49 |
--------------------------------------------------------------------------------
/src/Typesense/Converter/GroupKeyConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Globalization;
4 | using System.Linq;
5 | using System.Text.Json;
6 | using System.Text.Json.Serialization;
7 |
8 | namespace Typesense.Converter;
9 |
10 | public class GroupKeyConverter : JsonConverter>
11 | {
12 | public override IReadOnlyList? Read(ref Utf8JsonReader reader, Type typeToConvert,
13 | JsonSerializerOptions options)
14 | {
15 | var jsonDocument = JsonDocument.ParseValue(ref reader);
16 |
17 | return jsonDocument.RootElement.EnumerateArray().Select(StringifyJsonElement).ToList();
18 | }
19 |
20 | private static string StringifyJsonElement(JsonElement element)
21 | {
22 | var elementValue = element.ValueKind switch
23 | {
24 | JsonValueKind.String => element.GetString(),
25 | JsonValueKind.False => "false",
26 | JsonValueKind.True => "true",
27 | JsonValueKind.Number => element.GetDecimal().ToString(CultureInfo.CreateSpecificCulture("en-US")),
28 | JsonValueKind.Array => string.Join(", ", element.EnumerateArray().Select(StringifyJsonElement)),
29 | _ => null
30 | };
31 |
32 | if (elementValue is null)
33 | throw new InvalidOperationException($"{nameof(elementValue)} being null is invalid.");
34 |
35 | return elementValue;
36 | }
37 |
38 | public override void Write(Utf8JsonWriter writer, IReadOnlyList value, JsonSerializerOptions options)
39 | {
40 | JsonSerializer.Serialize(writer, value);
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Typesense/AutoEmbeddingConfig.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.ObjectModel;
2 | using System.Text.Json.Serialization;
3 |
4 | namespace Typesense;
5 |
6 | public record AutoEmbeddingConfig
7 | {
8 | [JsonPropertyName("from")]
9 | public Collection From { get; init; }
10 |
11 | [JsonPropertyName("model_config")]
12 | public ModelConfig ModelConfig { get; init; }
13 |
14 | public AutoEmbeddingConfig(Collection from, ModelConfig modelConfig)
15 | {
16 | From = from;
17 | ModelConfig = modelConfig;
18 | }
19 | }
20 |
21 | public record ModelConfig
22 | {
23 | [JsonPropertyName("model_name")]
24 | public string ModelName { get; init; }
25 |
26 | [JsonPropertyName("api_key")]
27 | public string? ApiKey { get; init; }
28 |
29 | [JsonPropertyName("url")]
30 | public string? Url { get; init; }
31 |
32 | [JsonPropertyName("access_token")]
33 | public string? AccessToken { get; init; }
34 |
35 | [JsonPropertyName("refresh_token")]
36 | public string? RefreshToken { get; init; }
37 |
38 | [JsonPropertyName("client_id")]
39 | public string? ClientId { get; init; }
40 |
41 | [JsonPropertyName("client_secret")]
42 | public string? ClientSecret { get; init; }
43 |
44 | [JsonPropertyName("project_id")]
45 | public string? ProjectId { get; init; }
46 |
47 | [JsonPropertyName("indexing_prefix")]
48 | public string? IndexingPrefix { get; init; }
49 |
50 | [JsonPropertyName("query_prefix")]
51 | public string? QueryPrefix { get; init; }
52 |
53 | public ModelConfig(string modelName)
54 | {
55 | ModelName = modelName;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/Typesense/Schema.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text.Json.Serialization;
4 |
5 | namespace Typesense;
6 |
7 | public record Schema
8 | {
9 | [JsonPropertyName("name")]
10 | public string Name { get; init; }
11 |
12 | [JsonPropertyName("fields")]
13 | public IEnumerable Fields { get; init; }
14 |
15 | [JsonPropertyName("default_sorting_field")]
16 | public string? DefaultSortingField { get; init; }
17 |
18 | [JsonPropertyName("token_separators")]
19 | public IEnumerable? TokenSeparators { get; init; }
20 |
21 | [JsonPropertyName("symbols_to_index")]
22 | public IEnumerable? SymbolsToIndex { get; init; }
23 |
24 | [JsonPropertyName("enable_nested_fields")]
25 | public bool? EnableNestedFields { get; init; }
26 |
27 | [JsonPropertyName("metadata")]
28 | public IDictionary? Metadata { get; init; }
29 |
30 | [Obsolete("Use multi-arity constructor instead.")]
31 | public Schema()
32 | {
33 | Name = "";
34 | Fields = new List();
35 | }
36 |
37 | public Schema(string name, IEnumerable fields)
38 | {
39 | if (string.IsNullOrWhiteSpace(name))
40 | throw new ArgumentNullException(nameof(name));
41 |
42 | Name = name;
43 | Fields = fields;
44 | }
45 |
46 | public Schema(string name, IEnumerable fields, string defaultSortingField)
47 | {
48 | if (string.IsNullOrWhiteSpace(name))
49 | throw new ArgumentNullException(name);
50 |
51 | Name = name;
52 | Fields = fields;
53 | DefaultSortingField = defaultSortingField;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/test/Typesense.Tests/PriorityOrderer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Xunit.Abstractions;
5 | using Xunit.Sdk;
6 |
7 | namespace Typesense.Tests;
8 |
9 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
10 | public class TestPriorityAttribute : Attribute
11 | {
12 | public int Priority { get; private set; }
13 |
14 | public TestPriorityAttribute(int priority) => Priority = priority;
15 | }
16 |
17 | public class PriorityOrderer : ITestCaseOrderer
18 | {
19 | public IEnumerable OrderTestCases(
20 | IEnumerable testCases) where TTestCase : ITestCase
21 | {
22 | string assemblyName = typeof(TestPriorityAttribute).AssemblyQualifiedName!;
23 | var sortedMethods = new SortedDictionary>();
24 | foreach (TTestCase testCase in testCases)
25 | {
26 | int priority = testCase.TestMethod.Method
27 | .GetCustomAttributes(assemblyName)
28 | .FirstOrDefault()
29 | ?.GetNamedArgument(nameof(TestPriorityAttribute.Priority)) ?? 0;
30 |
31 | GetOrCreate(sortedMethods, priority).Add(testCase);
32 | }
33 |
34 | foreach (TTestCase testCase in
35 | sortedMethods.Keys.SelectMany(
36 | priority => sortedMethods[priority].OrderBy(
37 | testCase => testCase.TestMethod.Method.Name)))
38 | {
39 | yield return testCase;
40 | }
41 | }
42 |
43 | private static TValue GetOrCreate(
44 | IDictionary dictionary, TKey key)
45 | where TKey : struct
46 | where TValue : new() =>
47 | dictionary.TryGetValue(key, out TValue result)
48 | ? result
49 | : (dictionary[key] = new TValue());
50 | }
51 |
--------------------------------------------------------------------------------
/src/Typesense/Converter/MatchedTokenConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text.Json;
4 | using System.Text.Json.Serialization;
5 |
6 | namespace Typesense.Converter;
7 |
8 | public class MatchedTokenConverter : JsonConverter>
9 | {
10 | public override IReadOnlyList