mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 14:54:27 +01:00
Constify the default primary key name
This commit is contained in:
parent
5f1bfb73ee
commit
742543091e
@ -12,6 +12,9 @@ use crate::{FieldId, Index, Object, Result};
|
|||||||
/// The symbol used to define levels in a nested primary key.
|
/// The symbol used to define levels in a nested primary key.
|
||||||
const PRIMARY_KEY_SPLIT_SYMBOL: char = '.';
|
const PRIMARY_KEY_SPLIT_SYMBOL: char = '.';
|
||||||
|
|
||||||
|
/// The default primary that is used when not specified.
|
||||||
|
const DEFAULT_PRIMARY_KEY: &str = "id";
|
||||||
|
|
||||||
/// This function validates and enrich the documents by checking that:
|
/// This function validates and enrich the documents by checking that:
|
||||||
/// - we can infer a primary key,
|
/// - we can infer a primary key,
|
||||||
/// - all the documents id exist and are extracted,
|
/// - all the documents id exist and are extracted,
|
||||||
@ -51,13 +54,14 @@ pub fn validate_and_enrich_documents_batch<R: Read + Seek>(
|
|||||||
None => {
|
None => {
|
||||||
let guessed = documents_batch_index
|
let guessed = documents_batch_index
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(_, name)| name.to_lowercase().contains("id"))
|
.filter(|(_, name)| name.to_lowercase().contains(DEFAULT_PRIMARY_KEY))
|
||||||
.min_by_key(|(fid, _)| *fid);
|
.min_by_key(|(fid, _)| *fid);
|
||||||
match guessed {
|
match guessed {
|
||||||
Some((id, name)) => PrimaryKey::flat(name.as_str(), *id),
|
Some((id, name)) => PrimaryKey::flat(name.as_str(), *id),
|
||||||
None if autogenerate_docids => {
|
None if autogenerate_docids => PrimaryKey::flat(
|
||||||
PrimaryKey::flat("id", documents_batch_index.insert("id"))
|
DEFAULT_PRIMARY_KEY,
|
||||||
}
|
documents_batch_index.insert(DEFAULT_PRIMARY_KEY),
|
||||||
|
),
|
||||||
None => return Ok(Err(UserError::MissingPrimaryKey)),
|
None => return Ok(Err(UserError::MissingPrimaryKey)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user