ranking fields should be stored and indexed by default; fix #521

This commit is contained in:
Quentin de Quelen 2020-03-16 12:17:51 +01:00
parent cf6e481c14
commit 2d82f1b655
3 changed files with 58 additions and 2 deletions

View File

@ -45,7 +45,13 @@ pub fn apply_settings_update(
match settings.ranking_rules {
UpdateState::Update(v) => {
let ranked_field: Vec<&str> = v.iter().filter_map(RankingRule::field).collect();
schema.update_ranked(ranked_field)?;
schema.update_ranked(&ranked_field)?;
for name in ranked_field {
if schema.accept_new_fields() {
schema.set_indexed(name.as_ref())?;
schema.set_displayed(name.as_ref())?;
}
}
index.main.put_ranking_rules(writer, &v)?;
must_reindex = true;
},

View File

@ -427,5 +427,4 @@ fn write_setting_and_update_partial() {
let (response, _status_code) = server.get_all_settings();
assert_json_eq!(expected, response, ordered: false);
}

View File

@ -135,3 +135,54 @@ fn send_malformed_custom_rule() {
let (_response, status_code) = server.update_ranking_rules_sync(body);
assert_eq!(status_code, 400);
}
// Test issue https://github.com/meilisearch/MeiliSearch/issues/521
#[test]
fn write_custom_ranking_and_index_documents() {
let mut server = common::Server::with_uid("movies");
let body = json!({
"uid": "movies",
"primaryKey": "id",
});
server.create_index(body);
// 1 - Add ranking rules with one custom ranking on a string
let body = json!([
"asc(title)",
"typo"
]);
server.update_ranking_rules(body);
// 2 - Add documents
let body = json!([
{
"id": 1,
"title": "Le Petit Prince",
"author": "Exupéry"
},
{
"id": 2,
"title": "Pride and Prejudice",
"author": "Jane Austen"
}
]);
server.add_or_replace_multiple_documents(body);
// 3 - Get the first document and compare
let expected = json!({
"id": 1,
"title": "Le Petit Prince",
"author": "Exupéry"
});
let (response, status_code) = server.get_document(1);
assert_eq!(status_code, 200);
assert_json_eq!(response, expected, ordered: false);
}