2019-10-08 14:47:38 +02:00
|
|
|
use std::collections::btree_map::{BTreeMap, Entry};
|
2019-10-09 13:48:33 +02:00
|
|
|
use std::collections::HashSet;
|
2019-10-08 14:47:38 +02:00
|
|
|
use std::error::Error;
|
|
|
|
use std::io::Write;
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
use std::path::{Path, PathBuf};
|
2019-10-18 13:05:28 +02:00
|
|
|
use std::time::{Duration, Instant};
|
2019-10-09 11:45:19 +02:00
|
|
|
use std::{fs, io, sync::mpsc};
|
2019-10-08 14:47:38 +02:00
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
use rustyline::{Config, Editor};
|
|
|
|
use serde::{Deserialize, Serialize};
|
2019-10-08 14:47:38 +02:00
|
|
|
use structopt::StructOpt;
|
|
|
|
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
|
|
|
|
|
2019-10-31 11:13:37 +01:00
|
|
|
use meilidb_core::{Database, Highlight, ProcessedUpdateResult};
|
2019-10-08 14:47:38 +02:00
|
|
|
use meilidb_schema::SchemaAttr;
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct IndexCommand {
|
|
|
|
/// The destination where the database must be created.
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
database_path: PathBuf,
|
|
|
|
|
2019-10-31 16:15:07 +01:00
|
|
|
#[structopt(long, default_value = "default")]
|
2019-11-19 16:15:49 +01:00
|
|
|
index_uid: String,
|
2019-10-31 16:15:07 +01:00
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
/// The csv file to index.
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
csv_data_path: PathBuf,
|
|
|
|
|
|
|
|
/// The path to the schema.
|
|
|
|
#[structopt(long, parse(from_os_str))]
|
|
|
|
schema: PathBuf,
|
|
|
|
|
|
|
|
#[structopt(long)]
|
|
|
|
update_group_size: Option<usize>,
|
2019-10-18 12:52:45 +02:00
|
|
|
|
|
|
|
#[structopt(long, parse(from_os_str))]
|
|
|
|
compact_to_path: Option<PathBuf>,
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct SearchCommand {
|
2019-10-29 11:30:44 +01:00
|
|
|
/// The path of the database to work with.
|
2019-10-08 14:47:38 +02:00
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
database_path: PathBuf,
|
|
|
|
|
2019-10-31 16:15:07 +01:00
|
|
|
#[structopt(long, default_value = "default")]
|
2019-11-19 16:15:49 +01:00
|
|
|
index_uid: String,
|
2019-10-31 16:15:07 +01:00
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
/// Timeout after which the search will return results.
|
|
|
|
#[structopt(long)]
|
|
|
|
fetch_timeout_ms: Option<u64>,
|
|
|
|
|
|
|
|
/// The number of returned results
|
|
|
|
#[structopt(short, long, default_value = "10")]
|
|
|
|
number_results: usize,
|
|
|
|
|
|
|
|
/// The number of characters before and after the first match
|
|
|
|
#[structopt(short = "C", long, default_value = "35")]
|
|
|
|
char_context: usize,
|
|
|
|
|
2019-10-09 14:20:37 +02:00
|
|
|
/// A filter string that can be `!adult` or `adult` to
|
|
|
|
/// filter documents on this specfied field
|
|
|
|
#[structopt(short, long)]
|
|
|
|
filter: Option<String>,
|
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
/// Fields that must be displayed.
|
|
|
|
displayed_fields: Vec<String>,
|
|
|
|
}
|
|
|
|
|
2019-10-29 11:30:44 +01:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
struct ShowUpdatesCommand {
|
|
|
|
/// The path of the database to work with.
|
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
database_path: PathBuf,
|
2019-10-31 16:15:07 +01:00
|
|
|
|
|
|
|
#[structopt(long, default_value = "default")]
|
2019-11-19 16:15:49 +01:00
|
|
|
index_uid: String,
|
2019-10-29 11:30:44 +01:00
|
|
|
}
|
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
#[derive(Debug, StructOpt)]
|
|
|
|
enum Command {
|
|
|
|
Index(IndexCommand),
|
|
|
|
Search(SearchCommand),
|
2019-10-29 11:30:44 +01:00
|
|
|
ShowUpdates(ShowUpdatesCommand),
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Command {
|
|
|
|
fn path(&self) -> &Path {
|
|
|
|
match self {
|
|
|
|
Command::Index(command) => &command.database_path,
|
|
|
|
Command::Search(command) => &command.database_path,
|
2019-10-29 11:30:44 +01:00
|
|
|
Command::ShowUpdates(command) => &command.database_path,
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize)]
|
|
|
|
#[serde(transparent)]
|
2019-10-09 13:48:33 +02:00
|
|
|
struct Document(indexmap::IndexMap<String, String>);
|
2019-10-08 14:47:38 +02:00
|
|
|
|
|
|
|
fn index_command(command: IndexCommand, database: Database) -> Result<(), Box<dyn Error>> {
|
|
|
|
let start = Instant::now();
|
|
|
|
|
2019-10-09 15:49:35 +02:00
|
|
|
let (sender, receiver) = mpsc::sync_channel(100);
|
2019-11-15 17:33:06 +01:00
|
|
|
let update_fn =
|
|
|
|
move |_name: &str, update: ProcessedUpdateResult| sender.send(update.update_id).unwrap();
|
2019-11-19 16:15:49 +01:00
|
|
|
let index = match database.open_index(&command.index_uid) {
|
2019-10-10 13:38:58 +02:00
|
|
|
Some(index) => index,
|
2019-11-19 16:15:49 +01:00
|
|
|
None => database.create_index(&command.index_uid).unwrap(),
|
2019-10-10 13:38:58 +02:00
|
|
|
};
|
|
|
|
|
2019-11-15 17:33:06 +01:00
|
|
|
database.set_update_callback(Box::new(update_fn));
|
2019-10-10 13:38:58 +02:00
|
|
|
|
2019-10-16 17:05:24 +02:00
|
|
|
let env = &database.env;
|
2019-10-08 14:47:38 +02:00
|
|
|
|
|
|
|
let schema = {
|
|
|
|
let string = fs::read_to_string(&command.schema)?;
|
|
|
|
toml::from_str(&string).unwrap()
|
|
|
|
};
|
|
|
|
|
2019-10-16 17:05:24 +02:00
|
|
|
let mut writer = env.write_txn().unwrap();
|
2019-10-08 14:47:38 +02:00
|
|
|
match index.main.schema(&writer)? {
|
|
|
|
Some(current_schema) => {
|
|
|
|
if current_schema != schema {
|
2019-10-18 13:05:28 +02:00
|
|
|
return Err(meilidb_core::Error::SchemaDiffer.into());
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
writer.abort();
|
2019-10-18 13:05:28 +02:00
|
|
|
}
|
2019-10-11 11:29:47 +02:00
|
|
|
None => {
|
|
|
|
index.schema_update(&mut writer, schema)?;
|
|
|
|
writer.commit().unwrap();
|
2019-10-18 13:05:28 +02:00
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let mut rdr = csv::Reader::from_path(command.csv_data_path)?;
|
|
|
|
let mut raw_record = csv::StringRecord::new();
|
|
|
|
let headers = rdr.headers()?.clone();
|
|
|
|
|
|
|
|
let mut max_update_id = 0;
|
|
|
|
let mut i = 0;
|
|
|
|
let mut end_of_file = false;
|
|
|
|
|
|
|
|
while !end_of_file {
|
|
|
|
let mut additions = index.documents_addition();
|
|
|
|
|
|
|
|
loop {
|
|
|
|
end_of_file = !rdr.read_record(&mut raw_record)?;
|
2019-10-18 13:05:28 +02:00
|
|
|
if end_of_file {
|
|
|
|
break;
|
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
|
|
|
|
let document: Document = match raw_record.deserialize(Some(&headers)) {
|
|
|
|
Ok(document) => document,
|
|
|
|
Err(e) => {
|
|
|
|
eprintln!("{:?}", e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
additions.update_document(document);
|
|
|
|
|
|
|
|
print!("\rindexing document {}", i);
|
|
|
|
i += 1;
|
|
|
|
|
|
|
|
if let Some(group_size) = command.update_group_size {
|
2019-10-18 13:05:28 +02:00
|
|
|
if i % group_size == 0 {
|
|
|
|
break;
|
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
println!();
|
|
|
|
|
2019-10-16 17:05:24 +02:00
|
|
|
let mut writer = env.write_txn().unwrap();
|
2019-10-08 14:47:38 +02:00
|
|
|
println!("committing update...");
|
2019-10-11 11:29:47 +02:00
|
|
|
let update_id = additions.finalize(&mut writer)?;
|
|
|
|
writer.commit().unwrap();
|
2019-10-08 14:47:38 +02:00
|
|
|
max_update_id = max_update_id.max(update_id);
|
2019-10-09 15:49:35 +02:00
|
|
|
println!("committed update {}", update_id);
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-09 11:45:19 +02:00
|
|
|
println!("Waiting for update {}", max_update_id);
|
|
|
|
for id in receiver {
|
2019-10-18 13:05:28 +02:00
|
|
|
if id == max_update_id {
|
|
|
|
break;
|
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
println!(
|
|
|
|
"database created in {:.2?} at: {:?}",
|
|
|
|
start.elapsed(),
|
|
|
|
command.database_path
|
|
|
|
);
|
2019-10-08 14:47:38 +02:00
|
|
|
|
2019-10-18 12:52:45 +02:00
|
|
|
if let Some(path) = command.compact_to_path {
|
2019-11-17 20:01:02 +01:00
|
|
|
fs::create_dir_all(&path)?;
|
2019-10-18 12:52:45 +02:00
|
|
|
let start = Instant::now();
|
2019-11-17 20:01:02 +01:00
|
|
|
let _file = database.copy_and_compact_to_path(path.join("data.mdb"))?;
|
2019-10-18 13:05:28 +02:00
|
|
|
println!(
|
|
|
|
"database compacted in {:.2?} at: {:?}",
|
|
|
|
start.elapsed(),
|
|
|
|
path
|
|
|
|
);
|
2019-10-18 12:52:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn display_highlights(text: &str, ranges: &[usize]) -> io::Result<()> {
|
|
|
|
let mut stdout = StandardStream::stdout(ColorChoice::Always);
|
|
|
|
let mut highlighted = false;
|
|
|
|
|
|
|
|
for range in ranges.windows(2) {
|
2019-10-18 13:05:28 +02:00
|
|
|
let [start, end] = match range {
|
|
|
|
[start, end] => [*start, *end],
|
|
|
|
_ => unreachable!(),
|
|
|
|
};
|
2019-10-08 14:47:38 +02:00
|
|
|
if highlighted {
|
2019-11-05 16:40:48 +01:00
|
|
|
stdout.set_color(
|
|
|
|
ColorSpec::new()
|
|
|
|
.set_fg(Some(Color::Yellow))
|
|
|
|
.set_underline(true),
|
|
|
|
)?;
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
write!(&mut stdout, "{}", &text[start..end])?;
|
|
|
|
stdout.reset()?;
|
|
|
|
highlighted = !highlighted;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn char_to_byte_range(index: usize, length: usize, text: &str) -> (usize, usize) {
|
|
|
|
let mut byte_index = 0;
|
|
|
|
let mut byte_length = 0;
|
|
|
|
|
|
|
|
for (n, (i, c)) in text.char_indices().enumerate() {
|
|
|
|
if n == index {
|
|
|
|
byte_index = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if n + 1 == index + length {
|
|
|
|
byte_length = i - byte_index + c.len_utf8();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
(byte_index, byte_length)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn create_highlight_areas(text: &str, highlights: &[Highlight]) -> Vec<usize> {
|
|
|
|
let mut byte_indexes = BTreeMap::new();
|
|
|
|
|
|
|
|
for highlight in highlights {
|
|
|
|
let char_index = highlight.char_index as usize;
|
|
|
|
let char_length = highlight.char_length as usize;
|
|
|
|
let (byte_index, byte_length) = char_to_byte_range(char_index, char_length, text);
|
|
|
|
|
|
|
|
match byte_indexes.entry(byte_index) {
|
2019-10-18 13:05:28 +02:00
|
|
|
Entry::Vacant(entry) => {
|
|
|
|
entry.insert(byte_length);
|
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
Entry::Occupied(mut entry) => {
|
|
|
|
if *entry.get() < byte_length {
|
|
|
|
entry.insert(byte_length);
|
|
|
|
}
|
2019-10-18 13:05:28 +02:00
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut title_areas = Vec::new();
|
|
|
|
title_areas.push(0);
|
|
|
|
for (byte_index, length) in byte_indexes {
|
|
|
|
title_areas.push(byte_index);
|
|
|
|
title_areas.push(byte_index + length);
|
|
|
|
}
|
|
|
|
title_areas.push(text.len());
|
|
|
|
title_areas.sort_unstable();
|
|
|
|
title_areas
|
|
|
|
}
|
|
|
|
|
|
|
|
/// note: matches must have been sorted by `char_index` and `char_length` before being passed.
|
|
|
|
///
|
|
|
|
/// ```no_run
|
|
|
|
/// matches.sort_unstable_by_key(|m| (m.char_index, m.char_length));
|
|
|
|
///
|
|
|
|
/// let matches = matches.matches.iter().filter(|m| SchemaAttr::new(m.attribute) == attr).cloned();
|
|
|
|
///
|
|
|
|
/// let (text, matches) = crop_text(&text, matches, 35);
|
|
|
|
/// ```
|
|
|
|
fn crop_text(
|
|
|
|
text: &str,
|
2019-10-18 13:05:28 +02:00
|
|
|
highlights: impl IntoIterator<Item = Highlight>,
|
2019-10-08 14:47:38 +02:00
|
|
|
context: usize,
|
2019-10-18 13:05:28 +02:00
|
|
|
) -> (String, Vec<Highlight>) {
|
2019-10-08 14:47:38 +02:00
|
|
|
let mut highlights = highlights.into_iter().peekable();
|
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
let char_index = highlights
|
|
|
|
.peek()
|
|
|
|
.map(|m| m.char_index as usize)
|
|
|
|
.unwrap_or(0);
|
2019-10-08 14:47:38 +02:00
|
|
|
let start = char_index.saturating_sub(context);
|
|
|
|
let text = text.chars().skip(start).take(context * 2).collect();
|
|
|
|
|
|
|
|
let highlights = highlights
|
2019-10-18 13:05:28 +02:00
|
|
|
.take_while(|m| (m.char_index as usize) + (m.char_length as usize) <= start + (context * 2))
|
|
|
|
.map(|highlight| Highlight {
|
|
|
|
char_index: highlight.char_index - start as u16,
|
|
|
|
..highlight
|
2019-10-08 14:47:38 +02:00
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
(text, highlights)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn search_command(command: SearchCommand, database: Database) -> Result<(), Box<dyn Error>> {
|
2019-10-16 17:05:24 +02:00
|
|
|
let env = &database.env;
|
2019-10-18 13:05:28 +02:00
|
|
|
let index = database
|
2019-11-19 16:15:49 +01:00
|
|
|
.open_index(&command.index_uid)
|
2019-10-18 13:05:28 +02:00
|
|
|
.expect("Could not find index");
|
2019-10-08 14:47:38 +02:00
|
|
|
|
2019-10-17 14:45:21 +02:00
|
|
|
let reader = env.read_txn().unwrap();
|
2019-10-08 14:47:38 +02:00
|
|
|
let schema = index.main.schema(&reader)?;
|
2019-10-17 14:45:21 +02:00
|
|
|
reader.abort();
|
2019-10-29 11:30:44 +01:00
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
let schema = schema.ok_or(meilidb_core::Error::SchemaMissing)?;
|
|
|
|
|
|
|
|
let fields = command.displayed_fields.iter().map(String::as_str);
|
|
|
|
let fields = HashSet::from_iter(fields);
|
|
|
|
|
|
|
|
let config = Config::builder().auto_add_history(true).build();
|
|
|
|
let mut readline = Editor::<()>::with_config(config);
|
|
|
|
let _ = readline.load_history("query-history.txt");
|
|
|
|
|
|
|
|
for result in readline.iter("Searching for: ") {
|
|
|
|
match result {
|
|
|
|
Ok(query) => {
|
|
|
|
let start_total = Instant::now();
|
|
|
|
|
2019-10-17 14:45:21 +02:00
|
|
|
let reader = env.read_txn().unwrap();
|
|
|
|
let ref_index = &index;
|
|
|
|
let ref_reader = &reader;
|
|
|
|
|
|
|
|
let mut builder = index.query_builder();
|
|
|
|
if let Some(timeout) = command.fetch_timeout_ms {
|
|
|
|
builder.with_fetch_timeout(Duration::from_millis(timeout));
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(ref filter) = command.filter {
|
|
|
|
let filter = filter.as_str();
|
|
|
|
let (positive, filter) = if filter.chars().next() == Some('!') {
|
|
|
|
(false, &filter[1..])
|
|
|
|
} else {
|
|
|
|
(true, filter)
|
|
|
|
};
|
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
let attr = schema
|
|
|
|
.attribute(&filter)
|
|
|
|
.expect("Could not find filtered attribute");
|
2019-10-17 14:45:21 +02:00
|
|
|
|
|
|
|
builder.with_filter(move |document_id| {
|
2019-10-18 13:05:28 +02:00
|
|
|
let string: String = ref_index
|
|
|
|
.document_attribute(ref_reader, document_id, attr)
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
2019-10-17 14:45:21 +02:00
|
|
|
(string == "true") == positive
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
let documents = builder.query(ref_reader, &query, 0..command.number_results)?;
|
2019-10-08 14:47:38 +02:00
|
|
|
|
|
|
|
let mut retrieve_duration = Duration::default();
|
|
|
|
|
|
|
|
let number_of_documents = documents.len();
|
|
|
|
for mut doc in documents {
|
2019-10-18 13:05:28 +02:00
|
|
|
doc.highlights
|
|
|
|
.sort_unstable_by_key(|m| (m.char_index, m.char_length));
|
2019-10-08 14:47:38 +02:00
|
|
|
|
|
|
|
let start_retrieve = Instant::now();
|
2019-10-16 17:05:24 +02:00
|
|
|
let result = index.document::<Document>(&reader, Some(&fields), doc.id);
|
2019-10-08 14:47:38 +02:00
|
|
|
retrieve_duration += start_retrieve.elapsed();
|
|
|
|
|
|
|
|
match result {
|
|
|
|
Ok(Some(document)) => {
|
|
|
|
println!("raw-id: {:?}", doc.id);
|
|
|
|
for (name, text) in document.0 {
|
|
|
|
print!("{}: ", name);
|
|
|
|
|
|
|
|
let attr = schema.attribute(&name).unwrap();
|
2019-10-18 13:05:28 +02:00
|
|
|
let highlights = doc
|
|
|
|
.highlights
|
|
|
|
.iter()
|
|
|
|
.filter(|m| SchemaAttr::new(m.attribute) == attr)
|
|
|
|
.cloned();
|
|
|
|
let (text, highlights) =
|
|
|
|
crop_text(&text, highlights, command.char_context);
|
2019-10-08 14:47:38 +02:00
|
|
|
let areas = create_highlight_areas(&text, &highlights);
|
|
|
|
display_highlights(&text, &areas)?;
|
|
|
|
println!();
|
|
|
|
}
|
2019-10-18 13:05:28 +02:00
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
Ok(None) => eprintln!("missing document"),
|
|
|
|
Err(e) => eprintln!("{}", e),
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut matching_attributes = HashSet::new();
|
|
|
|
for highlight in doc.highlights {
|
|
|
|
let attr = SchemaAttr::new(highlight.attribute);
|
|
|
|
let name = schema.attribute_name(attr);
|
|
|
|
matching_attributes.insert(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
let matching_attributes = Vec::from_iter(matching_attributes);
|
|
|
|
println!("matching in: {:?}", matching_attributes);
|
|
|
|
|
|
|
|
println!();
|
|
|
|
}
|
|
|
|
|
2019-10-18 13:05:28 +02:00
|
|
|
eprintln!(
|
|
|
|
"whole documents fields retrieve took {:.2?}",
|
|
|
|
retrieve_duration
|
|
|
|
);
|
|
|
|
eprintln!(
|
|
|
|
"===== Found {} results in {:.2?} =====",
|
|
|
|
number_of_documents,
|
|
|
|
start_total.elapsed()
|
|
|
|
);
|
|
|
|
}
|
2019-10-08 14:47:38 +02:00
|
|
|
Err(err) => {
|
|
|
|
println!("Error: {:?}", err);
|
2019-10-18 13:05:28 +02:00
|
|
|
break;
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
readline.save_history("query-history.txt").unwrap();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-29 11:30:44 +01:00
|
|
|
fn show_updates_command(
|
2019-10-31 16:15:07 +01:00
|
|
|
command: ShowUpdatesCommand,
|
2019-10-29 11:30:44 +01:00
|
|
|
database: Database,
|
|
|
|
) -> Result<(), Box<dyn Error>> {
|
|
|
|
let env = &database.env;
|
|
|
|
let index = database
|
2019-11-19 16:15:49 +01:00
|
|
|
.open_index(&command.index_uid)
|
2019-10-29 11:30:44 +01:00
|
|
|
.expect("Could not find index");
|
|
|
|
|
|
|
|
let reader = env.read_txn().unwrap();
|
|
|
|
let updates = index.all_updates_status(&reader)?;
|
|
|
|
println!("{:#?}", updates);
|
|
|
|
reader.abort();
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-08 14:47:38 +02:00
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
env_logger::init();
|
|
|
|
|
|
|
|
let opt = Command::from_args();
|
|
|
|
let database = Database::open_or_create(opt.path())?;
|
|
|
|
|
|
|
|
match opt {
|
|
|
|
Command::Index(command) => index_command(command, database),
|
|
|
|
Command::Search(command) => search_command(command, database),
|
2019-10-29 11:30:44 +01:00
|
|
|
Command::ShowUpdates(command) => show_updates_command(command, database),
|
2019-10-08 14:47:38 +02:00
|
|
|
}
|
|
|
|
}
|