diff --git a/raptor-search/benches/main.rs b/raptor-search/benches/main.rs new file mode 100644 index 000000000..e761252d5 --- /dev/null +++ b/raptor-search/benches/main.rs @@ -0,0 +1,31 @@ +#![feature(test)] + +extern crate test; +extern crate fst; +extern crate raptor; + +use std::path::Path; +use std::{fs, env, io}; +use fst::Streamer; +use raptor::{load_map, DocIndexMap, RankedStream, LevBuilder}; + +#[bench] +fn chauve_souris(b: &mut test::Bencher) { + let lev_builder = LevBuilder::new(); + let map = load_map("map.fst", "values.vecs").unwrap(); + + let query = "chauve souris"; + + b.iter(|| { + let mut automatons = Vec::new(); + for query in query.split_whitespace() { + let lev = lev_builder.build_automaton(query); + automatons.push(lev); + } + + let mut stream = RankedStream::new(&map, &map.values(), automatons); + while let Some(document_id) = stream.next() { + test::black_box(document_id); + } + }) +} diff --git a/raptor-search/src/main.rs b/raptor-search/src/main.rs index 6e987e2f1..ed57b507f 100644 --- a/raptor-search/src/main.rs +++ b/raptor-search/src/main.rs @@ -2,19 +2,16 @@ extern crate env_logger; extern crate fst; extern crate raptor; -use std::{fs, env}; +use std::path::Path; +use std::{fs, env, io}; use fst::Streamer; -use raptor::{DocIndexMap, RankedStream, LevBuilder}; +use raptor::{load_map, DocIndexMap, RankedStream, LevBuilder}; fn main() { drop(env_logger::init()); let lev_builder = LevBuilder::new(); - let map = { - let fst = fs::read("map.fst").unwrap(); - let values = fs::read("values.vecs").unwrap(); - DocIndexMap::from_bytes(fst, &values).unwrap() - }; + let map = load_map("map.fst", "values.vecs").unwrap(); let query = env::args().nth(1).expect("Please enter query words!"); let query = query.to_lowercase(); diff --git a/src/lib.rs b/src/lib.rs index eb1ec0402..f97326611 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,9 @@ pub mod map; pub mod rank; mod levenshtein; +use std::path::Path; +use std::fs; + pub use self::map::{Map, MapBuilder, Values}; pub use self::map::{ OpBuilder, IndexedValues, @@ -101,3 +104,12 @@ impl Match { } } } + + +pub fn load_map
(map: P, values: Q) -> fst::Result