mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-26 00:01:00 +00:00
fix: Make the examples build
This commit is contained in:
@ -15,12 +15,13 @@ i128 = ["meilidb-core/i128"]
|
||||
nightly = ["meilidb-core/nightly"]
|
||||
|
||||
[dev-dependencies]
|
||||
csv = "1.0.5"
|
||||
env_logger = "0.6.0"
|
||||
csv = "1.0.7"
|
||||
env_logger = "0.6.1"
|
||||
jemallocator = "0.1.9"
|
||||
quickcheck = "0.8.2"
|
||||
rand = "0.6.5"
|
||||
rand_xorshift = "0.1.1"
|
||||
structopt = "0.2.14"
|
||||
serde = { version = "1.0.90", features = ["derive"] }
|
||||
structopt = "0.2.15"
|
||||
tempfile = "3.0.7"
|
||||
termcolor = "1.0.4"
|
||||
|
@ -9,10 +9,10 @@ use std::error::Error;
|
||||
use std::borrow::Cow;
|
||||
use std::fs::File;
|
||||
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use serde::{Serialize, Deserialize};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use meilidb::database::{Database, Schema};
|
||||
use meilidb_data::{Database, Schema};
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct Opt {
|
||||
@ -50,9 +50,9 @@ fn index(
|
||||
stop_words: &HashSet<String>,
|
||||
) -> Result<Database, Box<Error>>
|
||||
{
|
||||
let database = Database::create(database_path)?;
|
||||
let database = Database::start_default(database_path)?;
|
||||
|
||||
database.create_index("default", &schema)?;
|
||||
let index = database.create_index("default".to_string(), schema.clone())?;
|
||||
|
||||
let mut rdr = csv::Reader::from_path(csv_data_path)?;
|
||||
let mut raw_record = csv::StringRecord::new();
|
||||
@ -62,7 +62,7 @@ fn index(
|
||||
let mut end_of_file = false;
|
||||
|
||||
while !end_of_file {
|
||||
let mut update = database.start_update("default")?;
|
||||
let mut update = index.documents_addition();
|
||||
|
||||
loop {
|
||||
end_of_file = !rdr.read_record(&mut raw_record)?;
|
||||
@ -76,7 +76,7 @@ fn index(
|
||||
}
|
||||
};
|
||||
|
||||
update.update_document(&document, &stop_words)?;
|
||||
update.update_document(&document)?;
|
||||
|
||||
print!("\rindexing document {}", i);
|
||||
i += 1;
|
||||
@ -89,7 +89,7 @@ fn index(
|
||||
println!();
|
||||
|
||||
println!("committing update...");
|
||||
database.commit_update(update)?;
|
||||
update.finalize()?;
|
||||
}
|
||||
|
||||
Ok(database)
|
||||
|
@ -2,19 +2,19 @@
|
||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||
|
||||
use std::collections::btree_map::{BTreeMap, Entry};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::iter::FromIterator;
|
||||
use std::io::{self, Write};
|
||||
use std::time::Instant;
|
||||
use std::path::PathBuf;
|
||||
use std::error::Error;
|
||||
|
||||
use hashbrown::{HashMap, HashSet};
|
||||
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
||||
use structopt::StructOpt;
|
||||
use meilidb_core::Match;
|
||||
|
||||
use meilidb::database::schema::SchemaAttr;
|
||||
use meilidb::database::Database;
|
||||
use meilidb_data::schema::SchemaAttr;
|
||||
use meilidb_data::Database;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
pub struct Opt {
|
||||
@ -138,12 +138,19 @@ fn main() -> Result<(), Box<Error>> {
|
||||
let opt = Opt::from_args();
|
||||
|
||||
let start = Instant::now();
|
||||
let database = Database::open(&opt.database_path)?;
|
||||
println!("database prepared for you in {:.2?}", start.elapsed());
|
||||
let database = Database::start_default(&opt.database_path)?;
|
||||
|
||||
let mut buffer = String::new();
|
||||
let input = io::stdin();
|
||||
|
||||
let index = database.open_index("default")?.unwrap();
|
||||
let schema = index.schema();
|
||||
|
||||
println!("database prepared for you in {:.2?}", start.elapsed());
|
||||
|
||||
let fields = opt.displayed_fields.iter().map(String::as_str);
|
||||
let fields = HashSet::from_iter(fields);
|
||||
|
||||
loop {
|
||||
print!("Searching for: ");
|
||||
io::stdout().flush()?;
|
||||
@ -151,12 +158,9 @@ fn main() -> Result<(), Box<Error>> {
|
||||
if input.read_line(&mut buffer)? == 0 { break }
|
||||
let query = buffer.trim_end_matches('\n');
|
||||
|
||||
let view = database.view("default")?;
|
||||
let schema = view.schema();
|
||||
|
||||
let start = Instant::now();
|
||||
|
||||
let builder = view.query_builder();
|
||||
let builder = index.query_builder();
|
||||
let documents = builder.query(query, 0..opt.number_results);
|
||||
|
||||
let number_of_documents = documents.len();
|
||||
@ -164,19 +168,12 @@ fn main() -> Result<(), Box<Error>> {
|
||||
|
||||
doc.matches.sort_unstable_by_key(|m| (m.char_index, m.char_index));
|
||||
|
||||
match view.document_by_id::<Document>(doc.id) {
|
||||
Ok(document) => {
|
||||
for name in &opt.displayed_fields {
|
||||
let attr = match schema.attribute(name) {
|
||||
Some(attr) => attr,
|
||||
None => continue,
|
||||
};
|
||||
let text = match document.get(name) {
|
||||
Some(text) => text,
|
||||
None => continue,
|
||||
};
|
||||
|
||||
match index.document::<Document>(Some(&fields), doc.id) {
|
||||
Ok(Some(document)) => {
|
||||
for (name, text) in document {
|
||||
print!("{}: ", name);
|
||||
|
||||
let attr = schema.attribute(&name).unwrap();
|
||||
let matches = doc.matches.iter()
|
||||
.filter(|m| SchemaAttr::new(m.attribute) == attr)
|
||||
.cloned();
|
||||
@ -186,6 +183,7 @@ fn main() -> Result<(), Box<Error>> {
|
||||
println!();
|
||||
}
|
||||
},
|
||||
Ok(None) => eprintln!("missing document"),
|
||||
Err(e) => eprintln!("{}", e),
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user