Skip to content

Commit

Permalink
Report search count after context output
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanfrishkorn committed Sep 29, 2023
1 parent 3e24d85 commit 760ebdd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
36 changes: 16 additions & 20 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,22 +708,6 @@ fn main() -> Result<(), Box<dyn Error>> {
Err(e) => return Err(Box::new(e)),
};

// print to stderr to keep redirection clean
eprint!("document");
if search_results.items.len() != 1 {
eprint!("s");
}
eprint!(": {}", search_results.items.len());
// print count of matched terms
let mut term_match_count = 0;
for item in &search_results.items {
for m in &item.matches {
term_match_count += m.1.len();
}
}
eprint!(" occurrences: {}", term_match_count);
eprintln!();

// exit if only counts are requested
if sub_matches.get_flag("count") {
return Ok(());
Expand All @@ -734,10 +718,7 @@ fn main() -> Result<(), Box<dyn Error>> {
return Ok(());
}

// newline for clarity
eprintln!();

for item in search_results.items {
for item in &search_results.items {
let mut s = snip::get_from_uuid(&conn, &item.uuid)?;
s.analyze()?;
println!("{}", s.name.white());
Expand Down Expand Up @@ -781,6 +762,21 @@ fn main() -> Result<(), Box<dyn Error>> {
println!();
}

// print to stderr to keep redirection clean
eprint!("document");
if search_results.items.len() != 1 {
eprint!("s");
}
eprint!(": {}", search_results.items.len());
// print count of matched terms
let mut term_match_count = 0;
for item in &search_results.items {
for m in &item.matches {
term_match_count += m.1.len();
}
}
eprintln!(" occurrences: {}", term_match_count);

/*
// single term direct data search
for (i, term) in terms_stem.iter().enumerate() {
Expand Down
6 changes: 3 additions & 3 deletions src/snip/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -883,18 +883,18 @@ mod tests {
let conn = prepare_database()?;
let id = Uuid::try_parse(ID_STR)?;

let s = snip::get_from_uuid(&conn, &id)?;
let s = get_from_uuid(&conn, &id)?;
// first remove from database
remove_snip(&conn, id)?;

// verify removal
if snip::get_from_uuid(&conn, &id).is_ok() {
if get_from_uuid(&conn, &id).is_ok() {
panic!("expected missing document, got document with id {}", id);
}

// insert and verify presence
s.insert(&conn)?;
if snip::get_from_uuid(&conn, &id).is_err() {
if get_from_uuid(&conn, &id).is_err() {
panic!("expected document, got Err searching for id {}", id);
}

Expand Down

0 comments on commit 760ebdd

Please sign in to comment.