-
Notifications
You must be signed in to change notification settings - Fork 102
Closed
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers
Description
Currently to communicate a primary key on document addition the document structure must implement the following trait:
// src/document.rs
pub trait Document: DeserializeOwned + std::fmt::Debug + Serialize {
/// The type of the primary key
type UIDType: Display;
/// The method returning the primary key of the Document.
///
/// **WARNING**! This method **MUST** only return an object that displays himself only using alphanumeric characters, '/' and '-'.
/// Otherwise, the Meilisearch server will reject your document.
fn get_uid(&self) -> &Self::UIDType;
}Here UIDType is the primary key. This trait is not very intuitive and makes the code harder to use than it should be.
The naming is not very clear and it requires an additional step of implementation on all document addition even when the user does not need to communicate the primary key.
for example:
// Define the type of our documents
#[derive(Serialize, Deserialize, Debug)]
struct Movie {
id: String,
title: String
}
impl Document for Movie {
type UIDType = String;
fn get_uid(&self) -> &Self::UIDType { &self.id }
}
// Add a document to our index
let task: Task = client.index("movies").add_documents(&[
Movie {
id: "123sq178".to_string(),
title: "Amélie Poulain".to_string(),
}
], None).await.unwrap();and when the user wants to communicate the primary key he still needs to give it as the second parameter of add_documents
add_documents(documents, Some("id"))irevoire, brunoocasali and curquiza
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomers