diff --git a/src/bin/raptor-cli.rs b/src/bin/raptor-cli.rs index fb1cea63e..d7725b17b 100644 --- a/src/bin/raptor-cli.rs +++ b/src/bin/raptor-cli.rs @@ -53,7 +53,8 @@ fn main() { let description = product.ft.split_whitespace().filter(|&s| s != "Description"); let words = title.chain(description) .filter(|&s| s.chars().any(|c| c.is_alphabetic())) // remove that ? - .filter(|&s| !common_words.contains(s)); + .filter(|&s| !common_words.contains(s)) + .map(|s| s.to_lowercase()); for word in words { builder.insert(word, product.product_id); @@ -64,6 +65,7 @@ fn main() { let values = File::create("values.vecs").unwrap(); let (map, values) = builder.build(map, values).unwrap(); + // just to check if the dump is valid let map = unsafe { MultiMap::from_paths("map.fst", "values.vecs").unwrap() }; // let mut stream = map.stream(); diff --git a/src/bin/raptor.rs b/src/bin/raptor.rs index d7031a949..1ccffd1c3 100644 --- a/src/bin/raptor.rs +++ b/src/bin/raptor.rs @@ -13,7 +13,7 @@ use tokio_minihttp::{Request, Response, Http}; use tokio_proto::TcpServer; use tokio_service::Service; -use raptor::{MultiMapBuilder, MultiMap}; +use raptor::MultiMap; struct MainService { map: MultiMap, @@ -30,13 +30,14 @@ impl Service for MainService { let url = format!("http://raptor.net{}", request.path()); let url = url::Url::parse(&url).unwrap(); + let mut resp = Response::new(); + if let Some((_, key)) = url.query_pairs().find(|&(ref k, _)| k == "query") { - let values = self.map.get(&*key); - println!("{:?}", values); + let key = key.to_lowercase(); + let values = self.map.get(&key).map(|a| &a[..10]); + resp.body(&format!("{:?}", values)); } - let mut resp = Response::new(); - resp.body("Hello, world!"); future::ok(resp) } } @@ -51,12 +52,7 @@ fn main() { // closure, make it global. // It will permit the server to be multithreaded. - let mut builder = MultiMapBuilder::new(); - builder.insert("foo", 12); - builder.insert("foo", 13); - builder.insert("bar", 10); - - let map = builder.build_memory().unwrap(); + let map = unsafe { MultiMap::from_paths("map.fst", "values.vecs").unwrap() }; println!("Called Fn here !"); diff --git a/src/lib.rs b/src/lib.rs index c3620158d..1928a4e70 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,12 +13,12 @@ use std::str::from_utf8_unchecked; pub use fst::MapBuilder; use smallvec::SmallVec; -type SmallVec16 = SmallVec<[T; 16]>; +type SmallVec32 = SmallVec<[T; 16]>; #[derive(Debug)] pub struct MultiMap { map: fst::Map, - values: Box<[SmallVec16]>, + values: Box<[SmallVec32]>, } impl MultiMap { @@ -54,7 +54,7 @@ impl MultiMap { pub struct Stream<'a, A: fst::Automaton = fst::automaton::AlwaysMatch> { inner: fst::map::Stream<'a, A>, - values: &'a [SmallVec16], + values: &'a [SmallVec32], } impl<'a, 'm, A: fst::Automaton> fst::Streamer<'a> for Stream<'m, A> { @@ -75,7 +75,7 @@ impl<'a, 'm, A: fst::Automaton> fst::Streamer<'a> for Stream<'m, A> { #[derive(Debug)] pub struct MultiMapBuilder { map: Vec<(String, u64)>, - values: Vec>, + values: Vec>, } impl<'a> MultiMapBuilder { @@ -98,7 +98,7 @@ impl<'a> MultiMapBuilder { }, Err(index) => { let values = { - let mut vec = SmallVec16::new(); + let mut vec = SmallVec32::new(); vec.push(value); vec };