Skip to content

Commit

Permalink
Merge #594
Browse files Browse the repository at this point in the history
594: Add searchCutoffMs setting support r=curquiza a=danFbach

# Pull Request

## Related issue
Fixes #536

## What does this PR do?
- implements searchCutoffMs

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?


Co-authored-by: Dan Fehrenbach <[email protected]>
Co-authored-by: Clémentine <[email protected]>
  • Loading branch information
3 people authored Jan 8, 2025
2 parents 34885f6 + 9e6e385 commit 81fd8a3
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 33 deletions.
9 changes: 8 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ update_settings_1: |-
OneTypo = 8,
TwoTypos = 10
}
}
},
SearchCutoffMs = 150
};
TaskInfo task = await client.Index("movies").UpdateSettingsAsync(newFilters);
reset_settings_1: |-
Expand Down Expand Up @@ -812,6 +813,12 @@ update_dictionary_1: |-
await client.Index("books").UpdateDictionaryAsync(newDictionary);
reset_dictionary_1: |-
await client.Index("books").ResetDictionaryAsync();
get_search_cutoff_1: |-
var searchCutoff = await client.Index("movies").GetSearchCutoffMsAsync();
update_search_cutoff_1: |-
await client.Index("movies").UpdateSearchCutoffMsAsync(150);
reset_search_cutoff_1: |-
await client.Index("movies").ResetSearchCutoffMsAsync();
facet_search_2: |-
var newFaceting = new Faceting
{
Expand Down
47 changes: 47 additions & 0 deletions src/Meilisearch/Index.SearchCutoffMs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System.Net.Http.Json;
using System.Threading;
using System.Threading.Tasks;

namespace Meilisearch
{
public partial class Index
{

/// <summary>
/// Gets the search cutoff in milliseconds.
/// </summary>
/// <returns>Returns the search cutoff in milliseconds.</returns>
public async Task<int?> GetSearchCutoffMsAsync(CancellationToken cancellationToken = default)
{
return await _http.GetFromJsonAsync<int?>($"indexes/{Uid}/settings/search-cutoff-ms", cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
/// <summary>
/// Sets the search cutoff in milliseconds.
/// </summary>
/// <param name="searchCutoffMs">The search cutoff in milliseconds.</param>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns the task info of the asynchronous task.</returns>
public async Task<TaskInfo> UpdateSearchCutoffMsAsync(int searchCutoffMs, CancellationToken cancellationToken = default)
{
var responseMessage =
await _http.PutAsJsonAsync($"indexes/{Uid}/settings/search-cutoff-ms", searchCutoffMs, Constants.JsonSerializerOptionsRemoveNulls, cancellationToken: cancellationToken)
.ConfigureAwait(false);

return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken)
.ConfigureAwait(false);
}

/// <summary>
/// Resets the search cutoff in milliseconds. (default: 1500)
/// </summary>
/// <param name="cancellationToken">The cancellation token for this call.</param>
/// <returns>Returns the task info of the asynchronous task.</returns>
public async Task<TaskInfo> ResetSearchCutoffMsAsync(CancellationToken cancellationToken = default)
{
var responseMessage = await _http.DeleteAsync($"indexes/{Uid}/settings/search-cutoff-ms", cancellationToken)
.ConfigureAwait(false);
return await responseMessage.Content.ReadFromJsonAsync<TaskInfo>(cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
65 changes: 34 additions & 31 deletions src/Meilisearch/Meilisearch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.2" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.2" />
</ItemGroup>

<ItemGroup>
<None Include="../../README.md" Pack="true" PackagePath="\" />
<None Include="../../assets/logo.png" Pack="true" Visible="false" PackagePath="" />
<None Include="../../README.md" Pack="true" PackagePath="\" />
<None Include="../../assets/logo.png" Pack="true" Visible="false" PackagePath="" />
</ItemGroup>

<ItemGroup>
Expand All @@ -36,32 +36,35 @@
</AssemblyAttribute>
</ItemGroup>
<ItemGroup>
<Compile Update="Index.Documents.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Dictionary.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Tasks.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.StopWords.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Attributes.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Synonyms.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.RankingRules.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Settings.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.TypoTolerance.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Documents.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Dictionary.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Tasks.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.StopWords.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Attributes.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Synonyms.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.RankingRules.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.Settings.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.TypoTolerance.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
<Compile Update="Index.SearchCutoffMs.cs">
<DependentUpon>Index.cs</DependentUpon>
</Compile>
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions src/Meilisearch/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,11 @@ public class Settings
/// </summary>
[JsonPropertyName("proximityPrecision")]
public string ProximityPrecision { get; set; }

/// <summary>
/// Gets or sets the searchCutoffMs attribute.
/// </summary>
[JsonPropertyName("searchCutoffMs")]
public int? SearchCutoffMs { get; set; }
}
}
29 changes: 28 additions & 1 deletion tests/Meilisearch.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ public async Task UpdateSettings()
SearchableAttributes = new string[] { "name", "genre" },
StopWords = new string[] { "of", "the" },
DistinctAttribute = "name",
Dictionary = new string[] { "dictionary" }
Dictionary = new string[] { "dictionary" },
SearchCutoffMs = 1000,
};
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings);
await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed
Expand Down Expand Up @@ -638,6 +639,31 @@ public async Task ResetDictionaryAsync()
await AssertGetEquality(_index.GetDictionaryAsync, _defaultSettings.Dictionary);
}

[Fact]
public async Task GetSearchCutoffMsAsync()
{
await AssertGetEquality(_index.GetSearchCutoffMsAsync, _defaultSettings.SearchCutoffMs);
}

[Fact]
public async Task UpdateSearchCutoffMsAsync()
{
var newSearchCutoffMs = 2000;
await AssertUpdateSuccess(_index.UpdateSearchCutoffMsAsync, newSearchCutoffMs);
await AssertGetEquality(_index.GetSearchCutoffMsAsync, newSearchCutoffMs);
}

[Fact]
public async Task ResetSearchCutoffMsAsync()
{
var newSearchCutoffMs = 2000;
await AssertUpdateSuccess(_index.UpdateSearchCutoffMsAsync, newSearchCutoffMs);
await AssertGetEquality(_index.GetSearchCutoffMsAsync, newSearchCutoffMs);

await AssertResetSuccess(_index.ResetSearchCutoffMsAsync);
await AssertGetEquality(_index.GetSearchCutoffMsAsync, _defaultSettings.SearchCutoffMs);
}

private static Settings SettingsWithDefaultedNullFields(Settings inputSettings, Settings defaultSettings)
{
return new Settings
Expand All @@ -657,6 +683,7 @@ private static Settings SettingsWithDefaultedNullFields(Settings inputSettings,
Pagination = inputSettings.Pagination ?? defaultSettings.Pagination,
ProximityPrecision = inputSettings.ProximityPrecision ?? defaultSettings.ProximityPrecision,
Dictionary = inputSettings.Dictionary ?? defaultSettings.Dictionary,
SearchCutoffMs = inputSettings.SearchCutoffMs ?? defaultSettings.SearchCutoffMs
};
}

Expand Down

0 comments on commit 81fd8a3

Please sign in to comment.