mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 04:17:10 +02:00
rename identifier into primaryKey; fix #514
This commit is contained in:
parent
8ffa80883a
commit
c984d8d5a5
24 changed files with 142 additions and 142 deletions
|
@ -380,7 +380,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -451,7 +451,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -521,7 +521,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -584,7 +584,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -736,7 +736,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -824,7 +824,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -971,7 +971,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ mod tests {
|
|||
database.set_update_callback(Box::new(update_fn));
|
||||
|
||||
let settings_update = SettingsUpdate{
|
||||
identifier: UpdateState::Update("id".to_string()),
|
||||
primary_key: UpdateState::Update("id".to_string()),
|
||||
..SettingsUpdate::default()
|
||||
};
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ pub type MResult<T> = Result<T, Error>;
|
|||
pub enum Error {
|
||||
Io(io::Error),
|
||||
IndexAlreadyExists,
|
||||
MissingIdentifier,
|
||||
MissingPrimaryKey,
|
||||
SchemaMissing,
|
||||
WordIndexMissing,
|
||||
MissingDocumentId,
|
||||
|
@ -87,7 +87,7 @@ impl fmt::Display for Error {
|
|||
match self {
|
||||
Io(e) => write!(f, "{}", e),
|
||||
IndexAlreadyExists => write!(f, "index already exists"),
|
||||
MissingIdentifier => write!(f, "schema cannot be built without identifier"),
|
||||
MissingPrimaryKey => write!(f, "schema cannot be built without primary key"),
|
||||
SchemaMissing => write!(f, "this index does not have a schema"),
|
||||
WordIndexMissing => write!(f, "this index does not have a word index"),
|
||||
MissingDocumentId => write!(f, "document id is missing"),
|
||||
|
@ -109,7 +109,7 @@ impl error::Error for Error {}
|
|||
#[derive(Debug)]
|
||||
pub enum UnsupportedOperation {
|
||||
SchemaAlreadyExists,
|
||||
CannotUpdateSchemaIdentifier,
|
||||
CannotUpdateSchemaPrimaryKey,
|
||||
CannotReorderSchemaAttribute,
|
||||
CanOnlyIntroduceNewSchemaAttributesAtEnd,
|
||||
CannotRemoveSchemaAttribute,
|
||||
|
@ -120,7 +120,7 @@ impl fmt::Display for UnsupportedOperation {
|
|||
use self::UnsupportedOperation::*;
|
||||
match self {
|
||||
SchemaAlreadyExists => write!(f, "Cannot update index which already have a schema"),
|
||||
CannotUpdateSchemaIdentifier => write!(f, "Cannot update the identifier of a schema"),
|
||||
CannotUpdateSchemaPrimaryKey => write!(f, "Cannot update the primary key of a schema"),
|
||||
CannotReorderSchemaAttribute => write!(f, "Cannot reorder the attributes of a schema"),
|
||||
CanOnlyIntroduceNewSchemaAttributesAtEnd => {
|
||||
write!(f, "Can only introduce new attributes at end of a schema")
|
||||
|
|
|
@ -259,7 +259,7 @@ mod tests {
|
|||
let mut postings_lists = HashMap::new();
|
||||
let mut fields_counts = HashMap::<_, u16>::new();
|
||||
|
||||
let mut schema = Schema::with_identifier("id");
|
||||
let mut schema = Schema::with_primary_key("id");
|
||||
|
||||
for (word, indexes) in iter {
|
||||
let mut final_indexes = Vec::new();
|
||||
|
|
|
@ -8,13 +8,13 @@ use siphasher::sip::SipHasher;
|
|||
use super::{ConvertToString, SerializerError};
|
||||
|
||||
pub fn extract_document_id<D>(
|
||||
identifier: &str,
|
||||
primary_key: &str,
|
||||
document: &D,
|
||||
) -> Result<Option<DocumentId>, SerializerError>
|
||||
where
|
||||
D: serde::Serialize,
|
||||
{
|
||||
let serializer = ExtractDocumentId { identifier };
|
||||
let serializer = ExtractDocumentId { primary_key };
|
||||
document.serialize(serializer)
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ pub fn compute_document_id<H: Hash>(t: H) -> DocumentId {
|
|||
}
|
||||
|
||||
struct ExtractDocumentId<'a> {
|
||||
identifier: &'a str,
|
||||
primary_key: &'a str,
|
||||
}
|
||||
|
||||
impl<'a> ser::Serializer for ExtractDocumentId<'a> {
|
||||
|
@ -188,7 +188,7 @@ impl<'a> ser::Serializer for ExtractDocumentId<'a> {
|
|||
|
||||
fn serialize_map(self, _len: Option<usize>) -> Result<Self::SerializeMap, Self::Error> {
|
||||
let serializer = ExtractDocumentIdMapSerializer {
|
||||
identifier: self.identifier,
|
||||
primary_key: self.primary_key,
|
||||
document_id: None,
|
||||
current_key_name: None,
|
||||
};
|
||||
|
@ -202,7 +202,7 @@ impl<'a> ser::Serializer for ExtractDocumentId<'a> {
|
|||
_len: usize,
|
||||
) -> Result<Self::SerializeStruct, Self::Error> {
|
||||
let serializer = ExtractDocumentIdStructSerializer {
|
||||
identifier: self.identifier,
|
||||
primary_key: self.primary_key,
|
||||
document_id: None,
|
||||
};
|
||||
|
||||
|
@ -223,7 +223,7 @@ impl<'a> ser::Serializer for ExtractDocumentId<'a> {
|
|||
}
|
||||
|
||||
pub struct ExtractDocumentIdMapSerializer<'a> {
|
||||
identifier: &'a str,
|
||||
primary_key: &'a str,
|
||||
document_id: Option<DocumentId>,
|
||||
current_key_name: Option<String>,
|
||||
}
|
||||
|
@ -260,7 +260,7 @@ impl<'a> ser::SerializeMap for ExtractDocumentIdMapSerializer<'a> {
|
|||
{
|
||||
let key = key.serialize(ConvertToString)?;
|
||||
|
||||
if self.identifier == key {
|
||||
if self.primary_key == key {
|
||||
let value = serde_json::to_string(value).and_then(|s| serde_json::from_str(&s))?;
|
||||
match value_to_string(&value).map(|s| compute_document_id(&s)) {
|
||||
Some(document_id) => self.document_id = Some(document_id),
|
||||
|
@ -277,7 +277,7 @@ impl<'a> ser::SerializeMap for ExtractDocumentIdMapSerializer<'a> {
|
|||
}
|
||||
|
||||
pub struct ExtractDocumentIdStructSerializer<'a> {
|
||||
identifier: &'a str,
|
||||
primary_key: &'a str,
|
||||
document_id: Option<DocumentId>,
|
||||
}
|
||||
|
||||
|
@ -293,7 +293,7 @@ impl<'a> ser::SerializeStruct for ExtractDocumentIdStructSerializer<'a> {
|
|||
where
|
||||
T: Serialize,
|
||||
{
|
||||
if self.identifier == key {
|
||||
if self.primary_key == key {
|
||||
let value = serde_json::to_string(value).and_then(|s| serde_json::from_str(&s))?;
|
||||
match value_to_string(&value).map(compute_document_id) {
|
||||
Some(document_id) => self.document_id = Some(document_id),
|
||||
|
|
|
@ -57,7 +57,7 @@ impl fmt::Display for SerializerError {
|
|||
f.write_str("serialized document does not have an id according to the schema")
|
||||
}
|
||||
SerializerError::InvalidDocumentIdType => {
|
||||
f.write_str("documents identifiers can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).")
|
||||
f.write_str("documents primary keys can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).")
|
||||
}
|
||||
SerializerError::Zlmdb(e) => write!(f, "heed related error: {}", e),
|
||||
SerializerError::SerdeJson(e) => write!(f, "serde json error: {}", e),
|
||||
|
|
|
@ -54,7 +54,7 @@ impl Settings {
|
|||
Ok(SettingsUpdate {
|
||||
ranking_rules,
|
||||
distinct_attribute: settings.distinct_attribute.into(),
|
||||
identifier: UpdateState::Nothing,
|
||||
primary_key: UpdateState::Nothing,
|
||||
searchable_attributes: settings.searchable_attributes.into(),
|
||||
displayed_attributes: settings.displayed_attributes.into(),
|
||||
stop_words: settings.stop_words.into(),
|
||||
|
@ -160,7 +160,7 @@ impl RankingRule {
|
|||
pub struct SettingsUpdate {
|
||||
pub ranking_rules: UpdateState<Vec<RankingRule>>,
|
||||
pub distinct_attribute: UpdateState<String>,
|
||||
pub identifier: UpdateState<String>,
|
||||
pub primary_key: UpdateState<String>,
|
||||
pub searchable_attributes: UpdateState<Vec<String>>,
|
||||
pub displayed_attributes: UpdateState<HashSet<String>>,
|
||||
pub stop_words: UpdateState<BTreeSet<String>>,
|
||||
|
@ -173,7 +173,7 @@ impl Default for SettingsUpdate {
|
|||
Self {
|
||||
ranking_rules: UpdateState::Nothing,
|
||||
distinct_attribute: UpdateState::Nothing,
|
||||
identifier: UpdateState::Nothing,
|
||||
primary_key: UpdateState::Nothing,
|
||||
searchable_attributes: UpdateState::Nothing,
|
||||
displayed_attributes: UpdateState::Nothing,
|
||||
stop_words: UpdateState::Nothing,
|
||||
|
|
|
@ -115,11 +115,11 @@ pub fn apply_documents_addition<'a, 'b>(
|
|||
None => return Err(Error::SchemaMissing),
|
||||
};
|
||||
|
||||
let identifier = schema.identifier().ok_or(Error::MissingIdentifier)?;
|
||||
let primary_key = schema.primary_key().ok_or(Error::MissingPrimaryKey)?;
|
||||
|
||||
// 1. store documents ids for future deletion
|
||||
for document in addition {
|
||||
let document_id = match extract_document_id(&identifier, &document)? {
|
||||
let document_id = match extract_document_id(&primary_key, &document)? {
|
||||
Some(id) => id,
|
||||
None => return Err(Error::MissingDocumentId),
|
||||
};
|
||||
|
@ -184,11 +184,11 @@ pub fn apply_documents_partial_addition<'a, 'b>(
|
|||
None => return Err(Error::SchemaMissing),
|
||||
};
|
||||
|
||||
let identifier = schema.identifier().ok_or(Error::MissingIdentifier)?;
|
||||
let primary_key = schema.primary_key().ok_or(Error::MissingPrimaryKey)?;
|
||||
|
||||
// 1. store documents ids for future deletion
|
||||
for mut document in addition {
|
||||
let document_id = match extract_document_id(&identifier, &document)? {
|
||||
let document_id = match extract_document_id(&primary_key, &document)? {
|
||||
Some(id) => id,
|
||||
None => return Err(Error::MissingDocumentId),
|
||||
};
|
||||
|
|
|
@ -40,8 +40,8 @@ impl DocumentsDeletion {
|
|||
where
|
||||
D: serde::Serialize,
|
||||
{
|
||||
let identifier = schema.identifier().ok_or(Error::MissingIdentifier)?;
|
||||
let document_id = match extract_document_id(&identifier, &document)? {
|
||||
let primary_key = schema.primary_key().ok_or(Error::MissingPrimaryKey)?;
|
||||
let document_id = match extract_document_id(&primary_key, &document)? {
|
||||
Some(id) => id,
|
||||
None => return Err(Error::MissingDocumentId),
|
||||
};
|
||||
|
|
|
@ -35,9 +35,9 @@ pub fn apply_settings_update(
|
|||
let mut schema = match index.main.schema(writer)? {
|
||||
Some(schema) => schema,
|
||||
None => {
|
||||
match settings.identifier.clone() {
|
||||
UpdateState::Update(id) => Schema::with_identifier(&id),
|
||||
_ => return Err(Error::MissingIdentifier)
|
||||
match settings.primary_key.clone() {
|
||||
UpdateState::Update(id) => Schema::with_primary_key(&id),
|
||||
_ => return Err(Error::MissingPrimaryKey)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue