Derive Macro meilisearch_sdk::documents::IndexConfig
source · #[derive(IndexConfig)]
{
// Attributes available to this derive:
#[index_config]
}
Expand description
Derive the IndexConfig trait.
§Field attribute
Use the #[index_config(..)] field attribute to generate the correct settings
for each field. The available parameters are:
primary_key(can only be used once)distinct(can only be used once)searchabledisplayedfilterablesortable
§Index name
The name of the index will be the name of the struct converted to snake case.
§Sample usage:
use serde::{Serialize, Deserialize};
use meilisearch_sdk::documents::IndexConfig;
use meilisearch_sdk::settings::Settings;
use meilisearch_sdk::indexes::Index;
use meilisearch_sdk::client::Client;
#[derive(Serialize, Deserialize, IndexConfig)]
struct Movie {
#[index_config(primary_key)]
movie_id: u64,
#[index_config(displayed, searchable)]
title: String,
#[index_config(displayed)]
description: String,
#[index_config(filterable, sortable, displayed)]
release_date: String,
#[index_config(filterable, displayed)]
genres: Vec<String>,
}
async fn usage(client: Client) {
// Default settings with the distinct, searchable, displayed, filterable, and sortable fields set correctly.
let settings: Settings = Movie::generate_settings();
// Index created with the name `movie` and the primary key set to `movie_id`
let index: Index = Movie::generate_index(&client).await.unwrap();
}