Skip to content

Commit 00752f0

Browse files
authored
Merge branch 'main' into create-snapshot-501
2 parents 4f10ba8 + 81fd8a3 commit 00752f0

File tree

5 files changed

+123
-33
lines changed

5 files changed

+123
-33
lines changed

.code-samples.meilisearch.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ update_settings_1: |-
166166
OneTypo = 8,
167167
TwoTypos = 10
168168
}
169-
}
169+
},
170+
SearchCutoffMs = 150
170171
};
171172
TaskInfo task = await client.Index("movies").UpdateSettingsAsync(newFilters);
172173
reset_settings_1: |-
@@ -814,6 +815,12 @@ reset_dictionary_1: |-
814815
await client.Index("books").ResetDictionaryAsync();
815816
create_snapshot_1: |-
816817
await client.CreateSnapshotAsync();
818+
get_search_cutoff_1: |-
819+
var searchCutoff = await client.Index("movies").GetSearchCutoffMsAsync();
820+
update_search_cutoff_1: |-
821+
await client.Index("movies").UpdateSearchCutoffMsAsync(150);
822+
reset_search_cutoff_1: |-
823+
await client.Index("movies").ResetSearchCutoffMsAsync();
817824
facet_search_2: |-
818825
var newFaceting = new Faceting
819826
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Net.Http.Json;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
5+
namespace Meilisearch
6+
{
7+
public partial class Index
8+
{
9+
10+
/// <summary>
11+
/// Gets the search cutoff in milliseconds.
12+
/// </summary>
13+
/// <returns>Returns the search cutoff in milliseconds.</returns>
14+
public async Task<int?> GetSearchCutoffMsAsync(CancellationToken cancellationToken = default)
15+
{
16+
return await _http.GetFromJsonAsync<int?>($"indexes/{Uid}/settings/search-cutoff-ms", cancellationToken: cancellationToken)
17+
.ConfigureAwait(false);
18+
}
19+
/// <summary>
20+
/// Sets the search cutoff in milliseconds.
21+
/// </summary>
22+
/// <param name="searchCutoffMs">The search cutoff in milliseconds.</param>
23+
/// <param name="cancellationToken">The cancellation token for this call.</param>
24+
/// <returns>Returns the task info of the asynchronous task.</returns>
25+
public async Task<TaskInfo> UpdateSearchCutoffMsAsync(int searchCutoffMs, CancellationToken cancellationToken = default)
26+
{
27+
var responseMessage =
28+
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/search-cutoff-ms", searchCutoffMs, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
29+
.ConfigureAwait(false);
30+
31+
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken)
32+
.ConfigureAwait(false);
33+
}
34+
35+
/// <summary>
36+
/// Resets the search cutoff in milliseconds. (default: 1500)
37+
/// </summary>
38+
/// <param name="cancellationToken">The cancellation token for this call.</param>
39+
/// <returns>Returns the task info of the asynchronous task.</returns>
40+
public async Task<TaskInfo> ResetSearchCutoffMsAsync(CancellationToken cancellationToken = default)
41+
{
42+
var responseMessage = await _http.DeleteAsync($"indexes/{Uid}/settings/search-cutoff-ms", cancellationToken)
43+
.ConfigureAwait(false);
44+
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
45+
}
46+
}
47+
}

src/Meilisearch/Meilisearch.csproj

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
</PropertyGroup>
2222

2323
<ItemGroup>
24-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
25-
<PackageReference Include="System.Net.Http.Json" Version="6.0.2" />
24+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
25+
<PackageReference Include="System.Net.Http.Json" Version="6.0.2" />
2626
</ItemGroup>
2727

2828
<ItemGroup>
29-
<None Include="../../README.md" Pack="true" PackagePath="\" />
30-
<None Include="../../assets/logo.png" Pack="true" Visible="false" PackagePath="" />
29+
<None Include="../../README.md" Pack="true" PackagePath="\" />
30+
<None Include="../../assets/logo.png" Pack="true" Visible="false" PackagePath="" />
3131
</ItemGroup>
3232

3333
<ItemGroup>
@@ -36,32 +36,35 @@
3636
</AssemblyAttribute>
3737
</ItemGroup>
3838
<ItemGroup>
39-
<Compile Update="Index.Documents.cs">
40-
<DependentUpon>Index.cs</DependentUpon>
41-
</Compile>
42-
<Compile Update="Index.Dictionary.cs">
43-
<DependentUpon>Index.cs</DependentUpon>
44-
</Compile>
45-
<Compile Update="Index.Tasks.cs">
46-
<DependentUpon>Index.cs</DependentUpon>
47-
</Compile>
48-
<Compile Update="Index.StopWords.cs">
49-
<DependentUpon>Index.cs</DependentUpon>
50-
</Compile>
51-
<Compile Update="Index.Attributes.cs">
52-
<DependentUpon>Index.cs</DependentUpon>
53-
</Compile>
54-
<Compile Update="Index.Synonyms.cs">
55-
<DependentUpon>Index.cs</DependentUpon>
56-
</Compile>
57-
<Compile Update="Index.RankingRules.cs">
58-
<DependentUpon>Index.cs</DependentUpon>
59-
</Compile>
60-
<Compile Update="Index.Settings.cs">
61-
<DependentUpon>Index.cs</DependentUpon>
62-
</Compile>
63-
<Compile Update="Index.TypoTolerance.cs">
64-
<DependentUpon>Index.cs</DependentUpon>
65-
</Compile>
39+
<Compile Update="Index.Documents.cs">
40+
<DependentUpon>Index.cs</DependentUpon>
41+
</Compile>
42+
<Compile Update="Index.Dictionary.cs">
43+
<DependentUpon>Index.cs</DependentUpon>
44+
</Compile>
45+
<Compile Update="Index.Tasks.cs">
46+
<DependentUpon>Index.cs</DependentUpon>
47+
</Compile>
48+
<Compile Update="Index.StopWords.cs">
49+
<DependentUpon>Index.cs</DependentUpon>
50+
</Compile>
51+
<Compile Update="Index.Attributes.cs">
52+
<DependentUpon>Index.cs</DependentUpon>
53+
</Compile>
54+
<Compile Update="Index.Synonyms.cs">
55+
<DependentUpon>Index.cs</DependentUpon>
56+
</Compile>
57+
<Compile Update="Index.RankingRules.cs">
58+
<DependentUpon>Index.cs</DependentUpon>
59+
</Compile>
60+
<Compile Update="Index.Settings.cs">
61+
<DependentUpon>Index.cs</DependentUpon>
62+
</Compile>
63+
<Compile Update="Index.TypoTolerance.cs">
64+
<DependentUpon>Index.cs</DependentUpon>
65+
</Compile>
66+
<Compile Update="Index.SearchCutoffMs.cs">
67+
<DependentUpon>Index.cs</DependentUpon>
68+
</Compile>
6669
</ItemGroup>
6770
</Project>

src/Meilisearch/Settings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,11 @@ public class Settings
9797
/// </summary>
9898
[JsonPropertyName("proximityPrecision")]
9999
public string ProximityPrecision { get; set; }
100+
101+
/// <summary>
102+
/// Gets or sets the searchCutoffMs attribute.
103+
/// </summary>
104+
[JsonPropertyName("searchCutoffMs")]
105+
public int? SearchCutoffMs { get; set; }
100106
}
101107
}

tests/Meilisearch.Tests/SettingsTests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public async Task UpdateSettings()
9696
SearchableAttributes = new string[] { "name", "genre" },
9797
StopWords = new string[] { "of", "the" },
9898
DistinctAttribute = "name",
99-
Dictionary = new string[] { "dictionary" }
99+
Dictionary = new string[] { "dictionary" },
100+
SearchCutoffMs = 1000,
100101
};
101102
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings);
102103
await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed
@@ -638,6 +639,31 @@ public async Task ResetDictionaryAsync()
638639
await AssertGetEquality(_index.GetDictionaryAsync, _defaultSettings.Dictionary);
639640
}
640641

642+
[Fact]
643+
public async Task GetSearchCutoffMsAsync()
644+
{
645+
await AssertGetEquality(_index.GetSearchCutoffMsAsync, _defaultSettings.SearchCutoffMs);
646+
}
647+
648+
[Fact]
649+
public async Task UpdateSearchCutoffMsAsync()
650+
{
651+
var newSearchCutoffMs = 2000;
652+
await AssertUpdateSuccess(_index.UpdateSearchCutoffMsAsync, newSearchCutoffMs);
653+
await AssertGetEquality(_index.GetSearchCutoffMsAsync, newSearchCutoffMs);
654+
}
655+
656+
[Fact]
657+
public async Task ResetSearchCutoffMsAsync()
658+
{
659+
var newSearchCutoffMs = 2000;
660+
await AssertUpdateSuccess(_index.UpdateSearchCutoffMsAsync, newSearchCutoffMs);
661+
await AssertGetEquality(_index.GetSearchCutoffMsAsync, newSearchCutoffMs);
662+
663+
await AssertResetSuccess(_index.ResetSearchCutoffMsAsync);
664+
await AssertGetEquality(_index.GetSearchCutoffMsAsync, _defaultSettings.SearchCutoffMs);
665+
}
666+
641667
private static Settings SettingsWithDefaultedNullFields(Settings inputSettings, Settings defaultSettings)
642668
{
643669
return new Settings
@@ -657,6 +683,7 @@ private static Settings SettingsWithDefaultedNullFields(Settings inputSettings,
657683
Pagination = inputSettings.Pagination ?? defaultSettings.Pagination,
658684
ProximityPrecision = inputSettings.ProximityPrecision ?? defaultSettings.ProximityPrecision,
659685
Dictionary = inputSettings.Dictionary ?? defaultSettings.Dictionary,
686+
SearchCutoffMs = inputSettings.SearchCutoffMs ?? defaultSettings.SearchCutoffMs
660687
};
661688
}
662689

0 commit comments

Comments
 (0)