mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-26 05:26:27 +00:00 
			
		
		
		
	map: Increase the SmallVec size
This commit is contained in:
		| @@ -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(); | ||||
|   | ||||
| @@ -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 !"); | ||||
|  | ||||
|   | ||||
							
								
								
									
										10
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/lib.rs
									
									
									
									
									
								
							| @@ -13,12 +13,12 @@ use std::str::from_utf8_unchecked; | ||||
| pub use fst::MapBuilder; | ||||
| use smallvec::SmallVec; | ||||
|  | ||||
| type SmallVec16<T> = SmallVec<[T; 16]>; | ||||
| type SmallVec32<T> = SmallVec<[T; 16]>; | ||||
|  | ||||
| #[derive(Debug)] | ||||
| pub struct MultiMap { | ||||
|     map: fst::Map, | ||||
|     values: Box<[SmallVec16<u64>]>, | ||||
|     values: Box<[SmallVec32<u64>]>, | ||||
| } | ||||
|  | ||||
| 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<u64>], | ||||
|     values: &'a [SmallVec32<u64>], | ||||
| } | ||||
|  | ||||
| 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<SmallVec16<u64>>, | ||||
|     values: Vec<SmallVec32<u64>>, | ||||
| } | ||||
|  | ||||
| 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 | ||||
|                 }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user