meilisearch / meilisearch

A lightning-fast search API that fits effortlessly into your apps, websites, and workflow
https://www.meilisearch.com
MIT License
47.43k stars 1.85k forks source link

Why 2 results ? #2004

Closed zjttfs closed 2 years ago

zjttfs commented 2 years ago

Describe the bug Searching for woman brought up irrelevant results Carol

To Reproduce

<?php

require_once __DIR__ . '/vendor/autoload.php';

use MeiliSearch\Client;

$client = new Client('http://127.0.0.1:7700', 'masterKey');

# An index is where the documents are stored.
$index = $client->index('movies');

$documents = [
    ['id' => 1,  'title' => 'Carol', 'genres' => ['Romance, Drama']],
    ['id' => 2,  'title' => 'Wonder Woman', 'genres' => ['Action, Adventure']],
    ['id' => 3,  'title' => 'Life of Pi', 'genres' => ['Adventure, Drama']],
    ['id' => 4,  'title' => 'Mad Max: Fury Road', 'genres' => ['Adventure, Science Fiction']],
    ['id' => 5,  'title' => 'Moana', 'genres' => ['Fantasy, Action']],
    ['id' => 6,  'title' => 'Philadelphia', 'genres' => ['Drama']],
];

# If the index 'movies' does not exist, MeiliSearch creates it when you first add the documents.
$index->addDocuments($documents); // => { "updateId": 0 }

Expected behavior

only Wonder Woman

Screenshots

1 2

MeiliSearch version:

v0.24.0

Additional context

Installing with docker docker pull getmeili/meilisearch:latest

Kerollmops commented 2 years ago

Hey @zjttfs,

It can feel like a bug but it is not, the engine found out that woman with a typo can match the start of Romance. You would say that it is the same with the word woma but that's not as the engine will discard any typo on a word with 4 or fewer characters. You can read more about the typo rules on this documentation page.

Furthermore, the woman query is considered as a prefix word query as it is the last word of the query and it doesn't contain a space and this is why the e of romance is not part of the comparison with woman, there is only one typo. You can read more about the search engine prefix feature on the documentation.

gmourier commented 2 years ago

Hi @zjttfs

If the expected behavior is to not want to consider the field genres as an attribute that users could search via the search bar, you can explicitly set title as a searchableAttributes. By default, all fields are set as searchableAttributes on a newly created index.

To be able to filter interactively by genres, you can set it as a filterableAttributes.