-
Notifications
You must be signed in to change notification settings - Fork 72
Open
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers
Description
Description
When typo tolerance in disabled on an attribute, exact matching queries do not work.
To Reproduce
- Stand-up a basic meilisearch instance in docker:
version: "3.8"
services:
meilisearch:
image: getmeili/meilisearch:v1.12
container_name: meilisearch
ports:
- "7701:7700"
environment:
MEILI_NO_ANALYTICS: "true"
MEILI_ENV: "development"
volumes:
- meili_data:/meili_data
volumes:
meili_data:
- run:
docker-compose up -d
- generate a basic dotnet CLI that creates documents, sets searchable attributes, and turns off typo tolerance for a particular attribute.
dotnet new console -n TypoToleranceBugProject
dotnet add package Meilisearch --version 0.16.0
dotnet add package Polly
Program.cs:
using Meilisearch;
using Polly;
using System.Text.Json.Serialization;
var client = new MeilisearchClient("http://localhost:7701");
// 0. Delete index
try
{
Console.WriteLine("Deleting existing 'products' index if present...");
var deleteTask = await client.Index("products").DeleteAsync();
await WaitForTaskAsync(client, deleteTask.TaskUid);
}
catch (MeilisearchApiError)
{
// Eat exception
}
// 1. Create index
Console.WriteLine("Creating 'products' index...");
var indexTask = await client.CreateIndexAsync("products", primaryKey: "id");
await WaitForTaskAsync(client, indexTask.TaskUid);
// 2. Configure attibute settings
Console.WriteLine("Configuring index settings...");
var attributes = new List<string> { "name", "serialNumber" };
var settingsTask = await client.Index("products").UpdateSettingsAsync(new Settings
{
SearchableAttributes = attributes,
FilterableAttributes = attributes,
SortableAttributes = attributes
});
await WaitForTaskAsync(client, settingsTask.TaskUid);
// 3. Disable typo tolerance for serial number attribute
Console.WriteLine("Disabling typo tolerance for serialNumber...");
var typoSettingsTask = await client.Index("products").UpdateSettingsAsync(new Settings
{
TypoTolerance = new TypoTolerance
{
DisableOnAttributes = ["serialNumber"]
}
});
await WaitForTaskAsync(client, typoSettingsTask.TaskUid);
// 4. Add some dummy products
Console.WriteLine("Inserting dummy products...");
var products = new[]
{
new Product { Id = Guid.NewGuid(), Name = "Widget Alpha", SerialNumber = "SN12345" },
new Product { Id = Guid.NewGuid(), Name = "Widget Beta", SerialNumber = "SN12346" },
new Product { Id = Guid.NewGuid(), Name = "Widget Gamma", SerialNumber = "SN12347" }
};
var addTask = await client.Index("products").AddDocumentsAsync(products);
await WaitForTaskAsync(client, addTask.TaskUid);
Console.WriteLine("All tasks completed successfully.");
static async Task WaitForTaskAsync(MeilisearchClient client, int taskUid)
{
var policy = Policy
.HandleResult<TaskResource>(t => t.Status != TaskInfoStatus.Succeeded)
.WaitAndRetryAsync(
retryCount: 5,
sleepDurationProvider: retryCount => TimeSpan.FromMilliseconds(500 * Math.Pow(2, retryCount)),
onRetry: (result, ts) => { Console.WriteLine("Retrying action..."); });
await policy.ExecuteAsync(async () => await client.GetTaskAsync(taskUid));
}
public record Product
{
[JsonPropertyName("id")] public Guid Id { get; init; }
[JsonPropertyName("name")] public string Name { get; init; } = "";
[JsonPropertyName("serialNumber")] public string SerialNumber { get; init; } = "";
}
Expected behavior
When an exact match string value is provided to the query, the matching document is returned.
Actual behavior
Verify serial number values:
Search for SN12345:
All other products fail to be retrieved by exact serial number matching.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggood first issueGood for newcomersGood for newcomers