chore: add test for custom settings

This commit is contained in:
qdequele 2019-09-18 11:42:30 +02:00
parent 03709910fd
commit e1c119b5a8
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
2 changed files with 38 additions and 8 deletions

View File

@ -38,3 +38,4 @@ branch = "arc-byte-slice"
[dev-dependencies]
tempfile = "3.1.0"
maplit = "1.0.2"
big_s = "1.0.2"

View File

@ -3,8 +3,9 @@
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
use std::sync::Arc;
use big_s::S;
use serde_json::json;
use meilidb_data::Database;
use meilidb_data::{Database, RankingOrdering};
use meilidb_schema::{Schema, SchemaBuilder, DISPLAYED, INDEXED};
fn simple_schema() -> Schema {
@ -120,8 +121,8 @@ fn database_stats() {
assert!(status.result.is_ok());
let stats = index.stats().unwrap();
let repartition = hashmap!{
"objectId".to_string() => 1u64,
"title".to_string() => 1u64,
S("objectId") => 1u64,
S("title") => 1u64,
};
assert_eq!(stats.number_of_documents, 1);
assert_eq!(stats.documents_fields_repartition, repartition);
@ -136,8 +137,8 @@ fn database_stats() {
assert!(status.result.is_ok());
let stats = index.stats().unwrap();
let repartition = hashmap!{
"objectId".to_string() => 2u64,
"title".to_string() => 2u64,
S("objectId") => 2u64,
S("title") => 2u64,
};
assert_eq!(stats.number_of_documents, 2);
assert_eq!(stats.documents_fields_repartition, repartition);
@ -153,10 +154,38 @@ fn database_stats() {
assert!(status.result.is_ok());
let stats = index.stats().unwrap();
let repartition = hashmap!{
"objectId".to_string() => 3u64,
"title".to_string() => 2u64,
S("objectId") => 3u64,
S("title") => 2u64,
};
assert_eq!(stats.number_of_documents, 3);
assert_eq!(stats.documents_fields_repartition, repartition);
}
#[test]
fn custom_settings() {
let tmp_dir = tempfile::tempdir().unwrap();
let database = Database::open(&tmp_dir).unwrap();
let schema = simple_schema();
let index = database.create_index("hello", schema).unwrap();
let stop_words = hashset!{ S("le"), S("la"), S("les"), };
let ranking_order = vec![S("SumOfTypos"), S("NumberOfWords"), S("WordsProximity"), S("SumOfWordsAttribute"), S("SumOfWordsPosition"), S("Exact"), S("DocumentId")];
let distinct_field = S("title");
let ranking_rules = hashmap!{ S("objectId") => RankingOrdering::Asc };
index.custom_settings().set_stop_words(&stop_words).unwrap();
index.custom_settings().set_ranking_order(&ranking_order).unwrap();
index.custom_settings().set_distinct_field(&distinct_field).unwrap();
index.custom_settings().set_ranking_rules(&ranking_rules).unwrap();
let ret_stop_words = index.custom_settings().get_stop_words().unwrap().unwrap();
let ret_ranking_orderer = index.custom_settings().get_ranking_order().unwrap().unwrap();
let ret_distinct_field = index.custom_settings().get_distinct_field().unwrap().unwrap();
let ret_ranking_rules = index.custom_settings().get_ranking_rules().unwrap().unwrap();
assert_eq!(ret_stop_words, stop_words);
assert_eq!(ret_ranking_orderer, ranking_order);
assert_eq!(ret_distinct_field, distinct_field);
assert_eq!(ret_ranking_rules, ranking_rules);
}