Repository: meilisearch/meilisearch
File: crates/meilisearch/tests/search/filters.rs (Rust)

Code before:
use meili_snap::{json_string, snapshot};
use meilisearch::Opt;
use tempfile::TempDir;

use super::test_settings_documents_indexing_swapping_and_search;
use crate::{
    common::{default_settings, shared_index_with_documents, Server, DOCUMENTS, NESTED_DOCUMENTS},
    json,
};

#[actix_rt::test]
async fn search_with_filter_string_notation() {
    let server = Server::new_shared();
    let index = server.unique_index();

    let (_, code) = index.update_settings(json!({"filterableAttributes": ["title"]})).await;
    snapshot!(code, @"202 Accepted");

    let documents = DOCUMENTS.clone();
    let (task, code) = index.add_documents(documents, None).await;
    snapshot!(code, @"202 Accepted");
    let res = index.wait_task(task.uid()).await.succeeded();
    snapshot!(res["status"], @r###""succeeded""###);

    index
        .search(
            json!({
                "filter": "title = Gläss"
            }),
            |response, code| {
                assert_eq!(code, 200, "{response}");
                assert_eq!(response["hits"].as_array().unwrap().len(), 1);
            },
        )
        .await;

    let nested_index = server.unique_index();

    let (_, code) = nested_index
        .update_settings(json!({"filterableAttributes": ["cattos", "doggos.age"]}))
        .await;
    snapshot!(code, @"202 Accepted");

    let documents = NESTED_DOCUMENTS.clone();
    let (task, code) = nested_index.add_documents(documents, None).await;
    snapshot!(code, @"202 Accepted");
    let res = nested_index.wait_task(task.uid()).await.succeeded();
    snapshot!(res["status"], @r###""succeeded""###);

Review comment (suggestion):
We can use the shared index with documents instead of creating a new index and indexing stuff in it here: https://github.com/meilisearch/meilisearch/blob/ea6bb4df1d76e8ae3880b60a99b85b1102891a68/crates/meilisearch/tests/common/mod.rs#L224

Code after:
use meili_snap::{json_string, snapshot};
use meilisearch::Opt;
use tempfile::TempDir;

use super::test_settings_documents_indexing_swapping_and_search;
use crate::{
    common::{
        default_settings, shared_index_with_documents, shared_index_with_nested_documents, Server,
        DOCUMENTS, NESTED_DOCUMENTS,
    },
    json,
};

#[actix_rt::test]
async fn search_with_filter_string_notation() {
    let index = shared_index_with_documents().await;

    index
        .search(
            json!({
                "filter": "title = Gläss"
            }),
            |response, code| {
                assert_eq!(code, 200, "{response}");
                assert_eq!(response["hits"].as_array().unwrap().len(), 1);
            },
        )
        .await;

    let nested_index = shared_index_with_nested_documents().await;

    nested_index
        .search(
            json!({
                "filter": "cattos = pésti"
            }),
            |response, code| {
                assert_eq!(code, 200, "{response}");
                assert_eq!(response["hits"].as_array().unwrap().len(), 1);
                assert_eq!(response["hits"][0]["id"], json!(852));
            },
        )
        .await;

    nested_index
        .search(
            json!({
                "filter": "doggos.age > 5"