mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-22 18:17:39 +08:00
test: Update the examples
This commit is contained in:
parent
671bd3374f
commit
4bb80c1460
@ -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: 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);
|
||||
|
@ -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: Hash>(t: &T) -> u64 {
|
||||
let mut s = DefaultHasher::new();
|
||||
t.hash(&mut s);
|
||||
s.finish()
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
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<Error>> {
|
||||
|
||||
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<Error>> {
|
||||
}
|
||||
|
||||
println!("{:#?}", full_documents);
|
||||
println!("{}", elapsed);
|
||||
println!("Found {} results in {}", full_documents.len(), elapsed);
|
||||
|
||||
buffer.clear();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user