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

Code before:
                snapshot!(response["hits"].as_array().unwrap().len(), @"2");
            },
        )
        .await;
}

#[actix_rt::test]
async fn nested_search_on_title_with_suffix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to any attribute inside 'details.'
    // It's worth noting the difference between 'details.*' and '*.title'
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["details.*"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"].as_array().unwrap().len(), @"3");
            },
        )
        .await;
}

#[actix_rt::test]
async fn nested_search_all_details_with_deep_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Similar to matching all attributes on simple search documents with universal wildcard
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["details.**"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"].as_array().unwrap().len(), @"3");
            },
        )
        .await;

    // Should return 2 documents (ids: 1 and 2)
    index
        .search(
            json!({"q": "true", "attributesToSearchOn": ["details.**"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(response["hits"].as_array().unwrap().len(), @"2");
            },
        )
        .await;
}

Review comment (suggestion):
At the moment this test is very similar to `nested_search_on_title_with_suffix_wildcard` because both of them find their results in the second level fields: `details.title` and `details.desc`.
IMO it would be good to introduce a third level field too in some of the documents and show that `details.**` is broader than `details.*`

Code after:
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["*.title"], "attributesToRetrieve": ["id"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(json_string!(response["hits"]),
                    @r###"
                [
                  {
                    "id": "3"
                  },
                  {
                    "id": "2"
                  }
                ]"###);
            },
        )
        .await;
}

#[actix_rt::test]
async fn nested_search_with_suffix_wildcard() {
    let server = Server::new().await;
    let index = index_with_documents(&server, &NESTED_SEARCH_DOCUMENTS).await;

    // Wildcard should match to any attribute inside 'details.'
    // It's worth noting the difference between 'details.*' and '*.title'
    index
        .search(
            json!({"q": "Captain Marvel", "attributesToSearchOn": ["details.*"], "attributesToRetrieve": ["id"]}),
            |response, code| {
                snapshot!(code, @"200 OK");
                snapshot!(json_string!(response["hits"]),
                    @r###"
                [
                  {
                    "id": "3"
                  },
                  {
                    "id": "1"
                  },
                  {
                    "id": "2"
                  }
                ]"###);
            },
        )
        .await;

    // Should return 1 document (ids: 1)
    index
        .search(