Skip to content

Commit

Permalink
chore: resyaure previous v6 insts
Browse files Browse the repository at this point in the history
  • Loading branch information
HatemMn committed Nov 26, 2024
1 parent 1ab60e6 commit 8b7777b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 92 deletions.
2 changes: 1 addition & 1 deletion crates/findex/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// change this to chgange the features
// change this to change the features
// "rest-interface"
"rust-analyzer.cargo.features": [
"redis-interface"
Expand Down
15 changes: 0 additions & 15 deletions crates/findex/src/db_interfaces/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,21 +73,6 @@ impl<Address: Hash + Eq, const WORD_LENGTH: usize> RedisBackend<Address, WORD_LE
_marker_adr: PhantomData,
})
}
// Script::new(GUARDED_WRITE_LUA_SCRIPT),

// TODO : manager is not compatible with the return types of memoryADT
// should we keep it ?
/// Connects to a Redis server with a `ConnectionManager`.
// pub async fn connect_with_manager(
// manager: ConnectionManager,
// ) -> Result<Self, DbInterfaceError> {
// 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);
Expand Down
122 changes: 61 additions & 61 deletions crates/findex/src/db_interfaces/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<i64> =
// 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::<Vec<_>>();
// 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<i64> =
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::<Vec<_>>();
results.sort_unstable();

assert_eq!(results, expected_results);
}

pub async fn test_generate_non_regression_db(config: Configuration) {
Expand Down
31 changes: 16 additions & 15 deletions crates/findex/src/instantiation/findex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keyword, HashSet<Value>>),
}
// #[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<Keyword, HashSet<Value>>),
// }

impl InstantiatedFindex {
/// Wrapper around Findex [`new`](Index::new) for static dispatch.
Expand Down Expand Up @@ -182,14 +182,13 @@ impl InstantiatedFindex {
pub async fn search<
F: Future<Output = Result<bool, String>>,
Interrupt: Fn(HashMap<Keyword, HashSet<IndexedValue<Keyword, Data>>>) -> F,
K: std::iter::Iterator<Item = Keyword>,
>(
&self,
key: &UserKey,
label: &Label,
keywords: K,
keywords: Keywords,
interrupt: &Interrupt,
) -> Result<SearchResult, FindexError<DbInterfaceError>> {
) -> Result<KeywordToDataMap, FindexError<DbInterfaceError>> {
match self {
#[cfg(feature = "rest-interface")]
Self::Rest(findex) => findex.search(key, label, keywords, interrupt).await,
Expand All @@ -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,
}
Expand All @@ -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,
Expand All @@ -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")]
Expand Down

0 comments on commit 8b7777b

Please sign in to comment.