Skip to content

Commit

Permalink
Replace the toml reader with the JSON settings reader, directly parse…
Browse files Browse the repository at this point in the history
… the data to SettingsUpdate, Update CHANGELOG
  • Loading branch information
ppamorim committed Apr 2, 2020
1 parent bc9c80a commit f5d57c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- Add support for aligned crop in search result (#543)
- Sanitize the content displayed in the web interface (#539)
- Add support of nested null, boolean and seq values (#571 and #568, #574)
- Fixed the core benchmark (#576)
1 change: 0 additions & 1 deletion datasets/movies/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"primaryKey": "id",
"searchableAttributes": ["title", "overview"],
"displayedAttributes": [
"id",
Expand Down
23 changes: 16 additions & 7 deletions meilisearch-core/benches/search_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ extern crate assert_matches;

use std::sync::mpsc;
use std::path::Path;
use std::fs;
use std::{fs, fs::File, io::BufReader};
use std::iter;

use meilisearch_core::Database;
use meilisearch_core::{ProcessedUpdateResult, UpdateStatus};
use meilisearch_core::settings::{Settings, SettingsUpdate, UpdateState};
use meilisearch_schema::Schema;
use serde_json::Value;

use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId};
Expand All @@ -24,15 +26,22 @@ fn prepare_database(path: &Path) -> Database {
let index = database.create_index("bench").unwrap();

database.set_update_callback(Box::new(update_fn));

let schema = {
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/schema.toml");
let string = fs::read_to_string(path).expect("find schema");
toml::from_str(&string).unwrap()

let mut writer = db.main_write_txn().unwrap();
index.main.put_schema(&mut writer, &Schema::with_primary_key("id")).unwrap();
writer.commit().unwrap();

let settings_update: SettingsUpdate = {
let path = concat!(env!("CARGO_MANIFEST_DIR"), "/../datasets/movies/settings.json");
let file = File::open(path).unwrap();
let reader = BufReader::new(file);
let settings: Settings = serde_json::from_reader(reader).unwrap();
settings.into_update().unwrap()
};

let mut update_writer = db.update_write_txn().unwrap();
let _update_id = index.schema_update(&mut update_writer, schema).unwrap();
let _update_id = index.settings_update(&mut update_writer, settings_update).unwrap();

update_writer.commit().unwrap();

let mut additions = index.documents_addition();
Expand Down

0 comments on commit f5d57c9

Please sign in to comment.