Repository: meilisearch/meilisearch
File: meilisearch-http/src/index/dump.rs (Rust)

Code before:
        let mut reader = BufReader::new(reader);
        reader.fill_buf()?;
        // If the document file is empty, we don't perform the document addition, to prevent
        // a primary key error to be thrown.
        if !reader.buffer().is_empty() {
            index.update_documents_txn(
                &mut txn,
                JsonStream,
                IndexDocumentsMethod::UpdateDocuments,
                Some(reader),
                handler.update_builder(0),
                primary_key.as_deref(),
            )?;
        }

        txn.commit()?;

        match Arc::try_unwrap(index.0) {
            Ok(inner) => inner.prepare_for_closing().wait(),
            Err(_) => bail!("Could not close index properly."),
        }

        Ok(())
    }
}

/// Changes the custom ranking rules i.e. `asc(_)`, `desc(_)`
/// with the new syntax i.e. `_:asc`, `_:desc`.
fn update_custom_ranking_rules(ranking_rules: &mut Value) {
    *ranking_rules = match ranking_rules.take() {
        Value::Array(values) => values
            .into_iter()
            .filter_map(|value| match value {
                Value::String(s) if s.starts_with("asc") => asc_ranking_rule(&s)
                    .map(|f| format!("{}:asc", f))
                    .map(Value::String),
                Value::String(s) if s.starts_with("desc") => desc_ranking_rule(&s)
                    .map(|f| format!("{}:desc", f))
                    .map(Value::String),
                otherwise => Some(otherwise),
            })
            .collect(),
        otherwise => otherwise,
    }
}

/// Returns the old default `rankingRules`.
fn default_ranking_rules_without_sort() -> Vec<String> {
    [
        Criterion::Words,
        Criterion::Typo,

Review comment (suggestion):
```suggestion
/// Converts the ranking rules from the format `asc(_)`, `desc(_)` to the format `_:asc`, `_:desc`.
///
/// This is done for compatibility reasons, and to avoid a new dump version, 
/// since the new syntax was introduced soon after the new dump version.
fn convert_custom_ranking_rules(ranking_rules: &mut Value) {
```

Code after:
        // a primary key error to be thrown.
        if !reader.buffer().is_empty() {
            index.update_documents_txn(
                &mut txn,
                JsonStream,
                IndexDocumentsMethod::UpdateDocuments,
                Some(reader),
                handler.update_builder(0),
                primary_key.as_deref(),
            )?;
        }

        txn.commit()?;

        match Arc::try_unwrap(index.0) {
            Ok(inner) => inner.prepare_for_closing().wait(),
            Err(_) => bail!("Could not close index properly."),
        }

        Ok(())
    }
}

/// Converts the ranking rules from the format `asc(_)`, `desc(_)` to the format `_:asc`, `_:desc`.
///
/// This is done for compatibility reasons, and to avoid a new dump version,
/// since the new syntax was introduced soon after the new dump version.
fn convert_custom_ranking_rules(ranking_rules: &mut Value) {
    *ranking_rules = match ranking_rules.take() {
        Value::Array(values) => values
            .into_iter()
            .filter_map(|value| match value {
                Value::String(s) if s.starts_with("asc") => asc_ranking_rule(&s)
                    .map(|f| format!("{}:asc", f))
                    .map(Value::String),
                Value::String(s) if s.starts_with("desc") => desc_ranking_rule(&s)
                    .map(|f| format!("{}:desc", f))
                    .map(Value::String),
                otherwise => Some(otherwise),
            })
            .collect(),
        otherwise => otherwise,
    }
}