From 4bb80c1460b070cedf3fc3e609e0bb3c16a2d6ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Mon, 10 Dec 2018 15:30:28 +0100 Subject: [PATCH] test: Update the examples --- examples/create-database.rs | 2 ++ examples/query-database.rs | 21 +++++++++------------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/examples/create-database.rs b/examples/create-database.rs index a26fe05a9..095a20f9a 100644 --- a/examples/create-database.rs +++ b/examples/create-database.rs @@ -26,6 +26,7 @@ pub struct Opt { #[allow(non_snake_case)] struct Document<'a> { skuId: &'a str, + productGroup: &'a str, fr_FR_commercialName: &'a str, en_GB_commercialName: &'a str, maketingColorInternalName: &'a str, @@ -48,6 +49,7 @@ fn calculate_hash(t: &T) -> u64 { fn create_schema() -> Schema { let mut schema = SchemaBuilder::new(); schema.new_attribute("skuId", STORED | INDEXED); + schema.new_attribute("productGroup", STORED | INDEXED); schema.new_attribute("fr_FR_commercialName", STORED | INDEXED); schema.new_attribute("en_GB_commercialName", STORED | INDEXED); schema.new_attribute("maketingColorInternalName", STORED | INDEXED); diff --git a/examples/query-database.rs b/examples/query-database.rs index 09f0f883f..57a17990d 100644 --- a/examples/query-database.rs +++ b/examples/query-database.rs @@ -1,5 +1,3 @@ -use std::collections::hash_map::DefaultHasher; -use std::hash::{Hash, Hasher}; use std::io::{self, Write}; use std::path::PathBuf; use std::error::Error; @@ -14,12 +12,17 @@ pub struct Opt { /// The destination where the database must be created #[structopt(parse(from_os_str))] pub database_path: PathBuf, + + /// The number of returned results + #[structopt(short = "n", long = "number-results", default_value = "10")] + pub number_results: usize, } #[derive(Debug, Serialize, Deserialize)] #[allow(non_snake_case)] struct Document { skuId: String, + productGroup: String, fr_FR_commercialName: String, en_GB_commercialName: String, maketingColorInternalName: String, @@ -28,24 +31,18 @@ struct Document { en_GB_description: String, } -fn calculate_hash(t: &T) -> u64 { - let mut s = DefaultHasher::new(); - t.hash(&mut s); - s.finish() -} - fn main() -> Result<(), Box> { let opt = Opt::from_args(); let (elapsed, result) = elapsed::measure_time(|| Database::open(&opt.database_path)); let database = result?; - println!("database opened in {}", elapsed); + println!("database prepared for you in {}", elapsed); let mut buffer = String::new(); let input = io::stdin(); loop { - print!("Search: "); + print!("Searching for: "); io::stdout().flush()?; if input.read_line(&mut buffer)? == 0 { break } @@ -54,7 +51,7 @@ fn main() -> Result<(), Box> { let (elapsed, documents) = elapsed::measure_time(|| { let builder = view.query_builder().unwrap(); - builder.query(&buffer, 10) + builder.query(&buffer, opt.number_results) }); let mut full_documents = Vec::with_capacity(documents.len()); @@ -67,7 +64,7 @@ fn main() -> Result<(), Box> { } println!("{:#?}", full_documents); - println!("{}", elapsed); + println!("Found {} results in {}", full_documents.len(), elapsed); buffer.clear(); }