From 8b7777b33b7ce0ae31d895fea1ea51dca93a3027 Mon Sep 17 00:00:00 2001 From: HatemMn <19950216+HatemMn@users.noreply.github.com> Date: Tue, 26 Nov 2024 17:22:43 +0100 Subject: [PATCH] chore: resyaure previous v6 insts --- crates/findex/.vscode/settings.json | 2 +- crates/findex/src/db_interfaces/redis.rs | 15 --- crates/findex/src/db_interfaces/tests.rs | 122 +++++++++++----------- crates/findex/src/instantiation/findex.rs | 31 +++--- 4 files changed, 78 insertions(+), 92 deletions(-) diff --git a/crates/findex/.vscode/settings.json b/crates/findex/.vscode/settings.json index 72bde94c..a2044ce6 100644 --- a/crates/findex/.vscode/settings.json +++ b/crates/findex/.vscode/settings.json @@ -1,5 +1,5 @@ { - // change this to chgange the features + // change this to change the features // "rest-interface" "rust-analyzer.cargo.features": [ "redis-interface" diff --git a/crates/findex/src/db_interfaces/redis.rs b/crates/findex/src/db_interfaces/redis.rs index 80f586c1..f67531b8 100644 --- a/crates/findex/src/db_interfaces/redis.rs +++ b/crates/findex/src/db_interfaces/redis.rs @@ -73,21 +73,6 @@ impl RedisBackend Result { - // Ok(Self { - // connection: Arc::new(Mutex::new(manager)), - // write_script: Script::new(GUARDED_WRITE_LUA_SCRIPT), - // _marker_adr: PhantomData, - // _marker_value: PhantomData, - // }) - // } pub fn clear_indexes(&self) -> Result<(), redis::RedisError> { let safe_connection = &mut *self.connection.lock().expect(POISONED_LOCK_ERROR_MSG); diff --git a/crates/findex/src/db_interfaces/tests.rs b/crates/findex/src/db_interfaces/tests.rs index 9852c9d0..fe48a6b8 100644 --- a/crates/findex/src/db_interfaces/tests.rs +++ b/crates/findex/src/db_interfaces/tests.rs @@ -156,34 +156,34 @@ async fn insert_users(findex: &InstantiatedFindex, key: &UserKey, label: &Label) /// Asserts each user can be retrieved using each field it is indexed for. async fn find_users(findex: &InstantiatedFindex, key: &UserKey, label: &Label) { - // let users = get_users().unwrap(); - - // // Assert results are reachable from each indexing keyword. - // for (idx, user) in users.iter().enumerate() { - // trace!("Search indexes."); - - // let res = findex - // .search( - // key, - // label, - // Keywords::from_iter( - // user.values() - // .into_iter() - // .map(|word| Keyword::from(word.as_bytes())), - // ), - // &|_| async move { Ok(false) }, - // ) - // .await - // .unwrap(); - - // for word in user.values() { - // let keyword = Keyword::from(word.as_bytes()); - // let data = Data::from((idx as i64).to_be_bytes().as_slice()); - // assert!(res.contains_key(&keyword)); - // let word_res = res.get(&keyword).unwrap(); - // assert!(word_res.contains(&data)); - // } - // } + let users = get_users().unwrap(); + + // Assert results are reachable from each indexing keyword. + for (idx, user) in users.iter().enumerate() { + trace!("Search indexes."); + + let res = findex + .search( + key, + label, + Keywords::from_iter( + user.values() + .into_iter() + .map(|word| Keyword::from(word.as_bytes())), + ), + &|_| async move { Ok(false) }, + ) + .await + .unwrap(); + + for word in user.values() { + let keyword = Keyword::from(word.as_bytes()); + let data = Data::from((idx as i64).to_be_bytes().as_slice()); + assert!(res.contains_key(&keyword)); + let word_res = res.get(&keyword).unwrap(); + assert!(word_res.contains(&data)); + } + } } /// This test: @@ -228,39 +228,39 @@ pub async fn test_backend(config: Configuration) { find_users(&findex, &new_key, &new_label).await; } -pub async fn test_non_regression(_config: Configuration) { - // let is_non_regression = true; - // let key = get_key(is_non_regression); - // let label = get_label(is_non_regression); - - // let mut expected_results: Vec = - // serde_json::from_str(include_str!("../../datasets/expected_db_uids.json")) - // .map_err(|e| DbInterfaceError::Serialization(e.to_string())) - // .unwrap(); - // expected_results.sort_unstable(); - - // let findex = InstantiatedFindex::new(config).await.unwrap(); - - // let keyword = Keyword::from("France".as_bytes()); - // let results = findex - // .search( - // &key, - // &label, - // Keywords::from_iter([keyword.clone()]), - // &|_| async move { Ok(false) }, - // ) - // .await - // .unwrap(); - - // let mut results = results - // .get(&keyword) - // .unwrap() - // .iter() - // .map(|data| i64::from_be_bytes(data.as_ref().try_into().unwrap())) - // .collect::>(); - // results.sort_unstable(); - - // assert_eq!(results, expected_results); +pub async fn test_non_regression(config: Configuration) { + let is_non_regression = true; + let key = get_key(is_non_regression); + let label = get_label(is_non_regression); + + let mut expected_results: Vec = + serde_json::from_str(include_str!("../../datasets/expected_db_uids.json")) + .map_err(|e| DbInterfaceError::Serialization(e.to_string())) + .unwrap(); + expected_results.sort_unstable(); + + let findex = InstantiatedFindex::new(config).await.unwrap(); + + let keyword = Keyword::from("France".as_bytes()); + let results = findex + .search( + &key, + &label, + Keywords::from_iter([keyword.clone()]), + &|_| async move { Ok(false) }, + ) + .await + .unwrap(); + + let mut results = results + .get(&keyword) + .unwrap() + .iter() + .map(|data| i64::from_be_bytes(data.as_ref().try_into().unwrap())) + .collect::>(); + results.sort_unstable(); + + assert_eq!(results, expected_results); } pub async fn test_generate_non_regression_db(config: Configuration) { diff --git a/crates/findex/src/instantiation/findex.rs b/crates/findex/src/instantiation/findex.rs index 083a29fd..798b2d54 100644 --- a/crates/findex/src/instantiation/findex.rs +++ b/crates/findex/src/instantiation/findex.rs @@ -94,15 +94,15 @@ pub enum InstantiatedFindex { ), } /// Temporary enum for Findex migration -#[deprecated( - since = "7.0.0", - note = "This enum is temporary and will be removed after migration to new Findex version" -)] -#[derive(Debug)] -pub enum SearchResult { - Old(KeywordToDataMap), - Recent(HashMap>), -} +// #[deprecated( +// since = "7.0.0", +// note = "This enum is temporary and will be removed after migration to new Findex version" +// )] +// #[derive(Debug)] +// pub enum SearchResult { +// Old(KeywordToDataMap), +// Recent(HashMap>), +// } impl InstantiatedFindex { /// Wrapper around Findex [`new`](Index::new) for static dispatch. @@ -182,14 +182,13 @@ impl InstantiatedFindex { pub async fn search< F: Future>, Interrupt: Fn(HashMap>>) -> F, - K: std::iter::Iterator, >( &self, key: &UserKey, label: &Label, - keywords: K, + keywords: Keywords, interrupt: &Interrupt, - ) -> Result> { + ) -> Result> { match self { #[cfg(feature = "rest-interface")] Self::Rest(findex) => findex.search(key, label, keywords, interrupt).await, @@ -200,7 +199,9 @@ impl InstantiatedFindex { #[cfg(feature = "sqlite-interface")] Self::Sqlite(findex) => findex.search(key, label, keywords, interrupt).await, #[cfg(feature = "redis-interface")] - Self::Redis(findex) => Ok(SearchResult::Recent(findex.search(keywords).await.unwrap())), + Self::Redis(findex) => Ok(todo!( + "SearchResult::Recent(findex.search(keywords).await.unwrap())" + )), #[cfg(feature = "wasm")] Self::Wasm(findex) => findex.search(key, label, keywords, interrupt).await, } @@ -218,7 +219,7 @@ impl InstantiatedFindex { Self::Sqlite(findex) => findex.add(key, label, additions).await, #[cfg(feature = "redis-interface")] Self::Redis(findex) => { - todo!("add me") + todo!("TBD") } #[cfg(feature = "ffi")] Self::Ffi(findex) => findex.add(key, label, additions).await, @@ -242,7 +243,7 @@ impl InstantiatedFindex { #[cfg(feature = "sqlite-interface")] Self::Sqlite(findex) => findex.delete(key, label, deletions).await, #[cfg(feature = "redis-interface")] - Self::Redis(findex) => todo!("do me"), + Self::Redis(findex) => todo!("TBD"), #[cfg(feature = "ffi")] Self::Ffi(findex) => findex.delete(key, label, deletions).await, #[cfg(feature = "python")]