Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion .code-samples.meilisearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ typo_tolerance_guide_4: |-
TwoTypos = 10
}
};

typo_tolerance_guide_5: |-
var typoTolerance = new TypoTolerance {
DisableOnNumbers = true
};
await client.Index("movies").UpdateTypoToleranceAsync(typoTolerance);
get_all_tasks_paginating_1: |-
ResourceResults<TaskInfo> taskResult = await client.GetTasksAsync(new TasksQuery { Limit = 2, From = 10 });
Expand Down
6 changes: 6 additions & 0 deletions src/Meilisearch/TypoTolerance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class TypoTolerance
[JsonPropertyName("minWordSizeForTypos")]
public TypoSize MinWordSizeForTypos { get; set; }

/// <summary>
/// Disable the typo tolerance feature for numbers.
/// </summary>
[JsonPropertyName("disableOnNumbers")]
public bool DisableOnNumbers { get; set; }

public class TypoSize
{
/// <summary>
Expand Down
126 changes: 53 additions & 73 deletions tests/Meilisearch.Tests/SettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,7 @@ public SettingsTests(TFixture fixture)

_defaultSettings = new Settings
{
RankingRules = new string[]
{
"words",
"typo",
"proximity",
"attribute",
"sort",
"exactness",
},
RankingRules = new string[] { "words", "typo", "proximity", "attribute", "sort", "exactness", },
DistinctAttribute = null,
SearchableAttributes = new string[] { "*" },
DisplayedAttributes = new string[] { "*" },
Expand All @@ -46,30 +38,23 @@ public SettingsTests(TFixture fixture)
Enabled = true,
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = Array.Empty<string>(),
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
OneTypo = 5,
TwoTypos = 9
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { OneTypo = 5, TwoTypos = 9 },
DisableOnNumbers = false
},
Faceting = new Faceting
{
MaxValuesPerFacet = 100,
SortFacetValuesBy = new Dictionary<string, SortFacetValuesByType>()
{
["*"] = SortFacetValuesByType.Alpha
}
SortFacetValuesBy =
new Dictionary<string, SortFacetValuesByType>() { ["*"] = SortFacetValuesByType.Alpha }
},
Pagination = new Pagination
{
MaxTotalHits = 1000
}
Pagination = new Pagination { MaxTotalHits = 1000 }
};
}

private delegate Task<TValue> IndexGetMethod<TValue>(CancellationToken cancellationToken = default);

private delegate Task<TaskInfo> IndexUpdateMethod<TValue>(TValue newValue, CancellationToken cancellationToken = default);
private delegate Task<TaskInfo> IndexUpdateMethod<TValue>(TValue newValue,
CancellationToken cancellationToken = default);

private delegate Task<TaskInfo> IndexResetMethod(CancellationToken cancellationToken = default);

Expand Down Expand Up @@ -99,8 +84,10 @@ public async Task UpdateSettings()
SearchCutoffMs = 1000,
};
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings);
await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync, SettingsWithDefaultedNullFields(newSettings, _defaultSettings));
await AssertGetInequality(_index.GetSettingsAsync,
newSettings); // fields omitted in newSettings shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync,
SettingsWithDefaultedNullFields(newSettings, _defaultSettings));
}

[Fact]
Expand All @@ -113,26 +100,24 @@ public async Task TwoStepUpdateSettings()
DistinctAttribute = "name",
Synonyms = new Dictionary<string, IEnumerable<string>>
{
{ "hp", new string[] { "harry potter" } },
{ "harry potter", new string[] { "hp" } },
{ "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } },
},
Dictionary = new string[] { "dictionary" }
};
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettingsOne);

var expectedSettingsOne = SettingsWithDefaultedNullFields(newSettingsOne, _defaultSettings);
await AssertGetInequality(_index.GetSettingsAsync, newSettingsOne); // fields omitted in newSettingsOne shouldn't have changed
await AssertGetInequality(_index.GetSettingsAsync,
newSettingsOne); // fields omitted in newSettingsOne shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync, expectedSettingsOne);

// Second update: this one should not overwritten StopWords and DistinctAttribute.
var newSettingsTwo = new Settings
{
SearchableAttributes = new string[] { "name" },
};
var newSettingsTwo = new Settings { SearchableAttributes = new string[] { "name" }, };
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettingsTwo);

var expectedSettingsTwo = SettingsWithDefaultedNullFields(newSettingsTwo, expectedSettingsOne);
await AssertGetInequality(_index.GetSettingsAsync, newSettingsTwo); // fields omitted in newSettingsTwo shouldn't have changed
await AssertGetInequality(_index.GetSettingsAsync,
newSettingsTwo); // fields omitted in newSettingsTwo shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync, expectedSettingsTwo);
}

Expand All @@ -150,8 +135,10 @@ public async Task ResetSettings()
Dictionary = new string[] { "dictionary" }
};
await AssertUpdateSuccess(_index.UpdateSettingsAsync, newSettings);
await AssertGetInequality(_index.GetSettingsAsync, newSettings); // fields omitted in newSettings shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync, SettingsWithDefaultedNullFields(newSettings, _defaultSettings));
await AssertGetInequality(_index.GetSettingsAsync,
newSettings); // fields omitted in newSettings shouldn't have changed
await AssertGetEquality(_index.GetSettingsAsync,
SettingsWithDefaultedNullFields(newSettings, _defaultSettings));

await AssertResetSuccess(_index.ResetSettingsAsync);
await AssertGetEquality(_index.GetSettingsAsync, _defaultSettings);
Expand Down Expand Up @@ -393,8 +380,7 @@ public async Task UpdateSynonyms()
{
var newSynonyms = new Dictionary<string, IEnumerable<string>>
{
{ "hp", new string[] { "harry potter" } },
{ "harry potter", new string[] { "hp" } },
{ "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } },
};
await AssertUpdateSuccess(_index.UpdateSynonymsAsync, newSynonyms);
await AssertGetEquality(_index.GetSynonymsAsync, newSynonyms);
Expand All @@ -405,8 +391,7 @@ public async Task ResetSynonyms()
{
var newSynonyms = new Dictionary<string, IEnumerable<string>>
{
{ "hp", new string[] { "harry potter" } },
{ "harry potter", new string[] { "hp" } },
{ "hp", new string[] { "harry potter" } }, { "harry potter", new string[] { "hp" } },
};
await AssertUpdateSuccess(_index.UpdateSynonymsAsync, newSynonyms);
await AssertGetEquality(_index.GetSynonymsAsync, newSynonyms);
Expand All @@ -427,51 +412,58 @@ public async Task UpdateTypoTolerance()
var newTypoTolerance = new TypoTolerance
{
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
TwoTypos = 12
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 }
};

var returnedTypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
TwoTypos = 12,
OneTypo = 5
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 }
};

await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance);
await AssertGetEquality(_index.GetTypoToleranceAsync, returnedTypoTolerance);
}


[Fact]
public async Task UpdateTypoTolerancePartially()
public async Task UpdateTypoToleranceForDisableOnNumbers()
{
var newTypoTolerance = new TypoTolerance
{
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 },
DisableOnNumbers = true
};

var otherUpdateTypoTolerance = new TypoTolerance
var returnedTypoTolerance = new TypoTolerance
{
DisableOnAttributes = new string[] { "title" },
Enabled = true,
DisableOnAttributes = new string[] { },
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 },
DisableOnNumbers = true
};

await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance);
await AssertGetEquality(_index.GetTypoToleranceAsync, returnedTypoTolerance);
}

[Fact]
public async Task UpdateTypoTolerancePartially()
{
var newTypoTolerance = new TypoTolerance { DisableOnWords = new string[] { "harry", "potter" }, };

var otherUpdateTypoTolerance = new TypoTolerance { DisableOnAttributes = new string[] { "title" }, };

var returnedTypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = new string[] { "title" },
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
TwoTypos = 9,
OneTypo = 5
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 9, OneTypo = 5 }
};

await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance);
Expand All @@ -485,22 +477,15 @@ public async Task ResetTypoTolerance()
var newTypoTolerance = new TypoTolerance
{
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
TwoTypos = 12
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12 }
};

var returnedTypoTolerance = new TypoTolerance
{
Enabled = true,
DisableOnAttributes = Array.Empty<string>(),
DisableOnWords = new string[] { "harry", "potter" },
MinWordSizeForTypos = new TypoTolerance.TypoSize
{
TwoTypos = 12,
OneTypo = 5
}
MinWordSizeForTypos = new TypoTolerance.TypoSize { TwoTypos = 12, OneTypo = 5 }
};

await AssertUpdateSuccess(_index.UpdateTypoToleranceAsync, newTypoTolerance);
Expand All @@ -510,6 +495,7 @@ public async Task ResetTypoTolerance()
await AssertGetEquality(_index.GetTypoToleranceAsync, _defaultSettings.TypoTolerance);
}


[Fact]
public async Task GetFaceting()
{
Expand Down Expand Up @@ -560,10 +546,7 @@ public async Task GetPagination()
[Fact]
public async Task UpdatePagination()
{
var newPagination = new Pagination
{
MaxTotalHits = 20
};
var newPagination = new Pagination { MaxTotalHits = 20 };

await AssertUpdateSuccess(_index.UpdatePaginationAsync, newPagination);
await AssertGetEquality(_index.GetPaginationAsync, newPagination);
Expand All @@ -572,10 +555,7 @@ public async Task UpdatePagination()
[Fact]
public async Task ResetPagination()
{
var newPagination = new Pagination
{
MaxTotalHits = 30
};
var newPagination = new Pagination { MaxTotalHits = 30 };

await AssertUpdateSuccess(_index.UpdatePaginationAsync, newPagination);
await AssertGetEquality(_index.GetPaginationAsync, newPagination);
Expand Down
Loading