Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Aug 26, 2024
1 parent 08660a9 commit 46680ad
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 47 deletions.
45 changes: 22 additions & 23 deletions crates/tabby-index-cli/src/commands/bench.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use crate::timer::TimerTree;
use std::{
fs::File,
io,
io::{BufRead, BufReader},
path::{Path, PathBuf},
};

use clap::Args;
use std::fs::File;
use std::io;
use std::io::BufRead;
use std::io::BufReader;
use std::path::Path;
use std::path::PathBuf;
use tantivy::collector::{Count, TopDocs};
use tantivy::query::QueryParser;
use tantivy::schema::{Field, Schema};
use tantivy::Index;
use tantivy::TantivyDocument;
use tantivy::{
collector::{Count, TopDocs},
query::QueryParser,
schema::{Field, Schema},
Index, TantivyDocument,
};

use crate::timer::TimerTree;

#[derive(Args)]
pub struct BenchArgs {
Expand All @@ -36,7 +39,7 @@ fn extract_search_fields(schema: &Schema) -> Vec<Field> {
}

fn read_query_file(query_path: &Path) -> io::Result<Vec<String>> {
let query_file: File = File::open(&query_path)?;
let query_file: File = File::open(query_path)?;
let file = BufReader::new(&query_file);
let mut queries = Vec::new();
for line_res in file.lines() {
Expand Down Expand Up @@ -66,16 +69,12 @@ fn run_bench(index_path: &Path, query_filepath: &Path, num_repeat: usize) -> Res
);

println!("SEARCH\n");
println!("{}\t{}\t{}", "query", "num hits", "time in microsecs");
println!("query\tnum hits\ttime in microsecs");
for _ in 0..num_repeat {
for query_txt in &queries {
let query = query_parser.parse_query(&query_txt).unwrap_or_else(|x| {
panic!(
"Failed to parse query {:?}.\n\n{:?}",
query_txt,
x
)
});
let query = query_parser
.parse_query(query_txt)
.unwrap_or_else(|x| panic!("Failed to parse query {:?}.\n\n{:?}", query_txt, x));
let mut timing = TimerTree::default();
let (_top_docs, count) = {
let _search = timing.open("search");
Expand All @@ -90,10 +89,10 @@ fn run_bench(index_path: &Path, query_filepath: &Path, num_repeat: usize) -> Res
}

println!("\n\nFETCH STORE\n");
println!("{}\t{}", "query", "time in microsecs");
println!("query\ttime in microsecs");
for _ in 0..num_repeat {
for query_txt in &queries {
let query = query_parser.parse_query(&query_txt).unwrap();
let query = query_parser.parse_query(query_txt).unwrap();
let top_docs = searcher
.search(&*query, &TopDocs::with_limit(10))
.map_err(|e| {
Expand Down
24 changes: 11 additions & 13 deletions crates/tabby-index-cli/src/commands/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::path::Path;
use tantivy;
use tantivy::schema::Schema;
use tantivy::space_usage::PerFieldSpaceUsage;
use tantivy::Index;

use tantivy::{self, schema::Schema, space_usage::PerFieldSpaceUsage, Index};

pub fn run_inspect_cli(directory: &Path) -> tantivy::Result<()> {
let index = Index::open_in_dir(directory)?;
let schema = index.schema();
let searcher = index.reader()?.searcher();
let segments = searcher.segment_readers();
println!("");
println!();
println!("===============================================================================");
println!("Inspect index report");
println!("===============================================================================\n");
Expand All @@ -19,7 +17,7 @@ pub fn run_inspect_cli(directory: &Path) -> tantivy::Result<()> {
println!("Number of segments: {}", segments.len());
let space_usage = searcher.space_usage()?;
println!("Total bytes: {}", space_usage.total());
println!("");
println!();
for (i, (segment_reader, segment_space_usage)) in segments
.iter()
.zip(space_usage.segments().iter())
Expand All @@ -39,37 +37,37 @@ pub fn run_inspect_cli(directory: &Path) -> tantivy::Result<()> {
"Offset bytes: {}",
segment_space_usage.store().offsets_usage()
);
println!("");
println!();
println!("{}.1 Term dictionnary space usage", section_count);
println!("--------------------------------");
let per_field_space_usage = segment_space_usage.termdict();
println!("Total bytes: {}", per_field_space_usage.total());
print_fields_space_usage(&schema, per_field_space_usage);
println!("");
println!();

println!("{}.2 Fast field space usage", section_count);
println!("--------------------------------");
let fast_field_space_usage = segment_space_usage.fast_fields();
println!("Total bytes: {}", fast_field_space_usage.total());
print_fields_space_usage(&schema, fast_field_space_usage);
println!("");
println!();

println!("{}.3 Postings space usage", section_count);
println!("--------------------------------");
let postings_space_usage = segment_space_usage.postings();
println!("Total bytes: {}", postings_space_usage.total());
print_fields_space_usage(&schema, postings_space_usage);
println!("");
println!();

println!("{}.4 Positions space usage", section_count);
println!("--------------------------------");
let positions_space_usage = segment_space_usage.positions();
println!("Total bytes: {}", positions_space_usage.total());
print_fields_space_usage(&schema, positions_space_usage);
println!("");
println!();
}

println!("");
println!();
println!("----------------------------- END OF REPORT ----------------------------------");
Ok(())
}
Expand All @@ -84,4 +82,4 @@ fn print_fields_space_usage(schema: &Schema, per_field_space_usage: &PerFieldSpa
field_space_usage.total()
);
}
}
}
6 changes: 4 additions & 2 deletions crates/tabby-index-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod bench;
mod inspect;

pub use self::inspect::run_inspect_cli;
pub use self::bench::{run_bench_cli, BenchArgs};
pub use self::{
bench::{run_bench_cli, BenchArgs},
inspect::run_inspect_cli,
};
2 changes: 1 addition & 1 deletion crates/tabby-index-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod commands;
mod timer;

use std::path::{Path, PathBuf};
use std::path::PathBuf;

use clap::{Parser, Subcommand};
use commands::BenchArgs;
Expand Down
10 changes: 2 additions & 8 deletions crates/tabby-index-cli/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub struct Timing {

/// Timer tree
#[derive(Debug, Serialize)]
#[derive(Default)]
pub struct TimerTree {
timings: Vec<Timing>,
}
Expand All @@ -64,13 +65,6 @@ impl TimerTree {
}
}

impl Default for TimerTree {
fn default() -> TimerTree {
TimerTree {
timings: Vec::new(),
}
}
}

#[cfg(test)]
mod tests {
Expand All @@ -94,4 +88,4 @@ mod tests {
}
assert_eq!(timer_tree.timings.len(), 4);
}
}
}

0 comments on commit 46680ad

Please sign in to comment.