mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 10:37:41 +08:00
edit documentation
This commit is contained in:
parent
85b5260d9d
commit
a38215de98
@ -18,14 +18,16 @@ pub use index::Index;
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub use test::MockIndex as Index;
|
pub use test::MockIndex as Index;
|
||||||
|
|
||||||
|
/// The index::test module provides means of mocking an index instance. I can be used throughout the
|
||||||
|
/// code for unit testing, in places where an index would normally be used.
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub mod test {
|
pub mod test {
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::panic::{RefUnwindSafe, UnwindSafe};
|
use std::panic::{RefUnwindSafe, UnwindSafe};
|
||||||
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Mutex;
|
use std::sync::{Arc, Mutex};
|
||||||
use std::{path::Path, sync::Arc};
|
|
||||||
|
|
||||||
use serde_json::{Map, Value};
|
use serde_json::{Map, Value};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
@ -71,9 +73,9 @@ pub mod test {
|
|||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since we add assertions in drop implementation for Stub, an panic can occur in a
|
// Since we add assertions in the drop implementation for Stub, a panic can occur in a
|
||||||
// panic, cause a hard abort of the program. To handle that, we catch the panic, and
|
// panic, causing a hard abort of the program. To handle that, we catch the panic, and
|
||||||
// set the stub as invalidated so the assertions are not run during the drop.
|
// set the stub as invalidated so the assertions aren't run during the drop.
|
||||||
impl<'a, A, R> RefUnwindSafe for StubHolder<'a, A, R> {}
|
impl<'a, A, R> RefUnwindSafe for StubHolder<'a, A, R> {}
|
||||||
struct StubHolder<'a, A, R>(&'a (dyn Fn(A) -> R + Sync + Send));
|
struct StubHolder<'a, A, R>(&'a (dyn Fn(A) -> R + Sync + Send));
|
||||||
|
|
||||||
@ -169,8 +171,12 @@ pub mod test {
|
|||||||
match self.store.get_mut(name) {
|
match self.store.get_mut(name) {
|
||||||
Some(stub) => stub,
|
Some(stub) => stub,
|
||||||
None => {
|
None => {
|
||||||
// TODO: this can cause nested panics, because stubs are dropped and panic
|
// panic here causes the stubs to get dropped, and panic in turn. To prevent
|
||||||
// themselves in their drops.
|
// that, we forget them, and let them be cleaned by the os later. This is not
|
||||||
|
// optimal, but is still better than nested panicks.
|
||||||
|
let mut stubs = self.store.inner.lock().unwrap();
|
||||||
|
let stubs = std::mem::replace(&mut *stubs, HashMap::new());
|
||||||
|
std::mem::forget(stubs);
|
||||||
panic!("unexpected call to {}", name)
|
panic!("unexpected call to {}", name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,8 @@ impl IndexControllerBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Using derivative to derive clone here, to ignore U and I bounds.
|
// We are using derivative here to derive Clone, because U, I and D do not necessarily implement
|
||||||
|
// Clone themselves.
|
||||||
#[derive(derivative::Derivative)]
|
#[derive(derivative::Derivative)]
|
||||||
#[derivative(Clone(bound = ""))]
|
#[derivative(Clone(bound = ""))]
|
||||||
pub struct IndexController<U, I, D> {
|
pub struct IndexController<U, I, D> {
|
||||||
@ -513,20 +514,6 @@ pub async fn get_arc_ownership_blocking<T>(mut item: Arc<T>) -> T {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the v1 version of the Asc ranking rules `asc(price)`and returns the field name.
|
|
||||||
pub fn asc_ranking_rule(text: &str) -> Option<&str> {
|
|
||||||
text.split_once("asc(")
|
|
||||||
.and_then(|(_, tail)| tail.rsplit_once(")"))
|
|
||||||
.map(|(field, _)| field)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Parses the v1 version of the Desc ranking rules `desc(price)`and returns the field name.
|
|
||||||
pub fn desc_ranking_rule(text: &str) -> Option<&str> {
|
|
||||||
text.split_once("desc(")
|
|
||||||
.and_then(|(_, tail)| tail.rsplit_once(")"))
|
|
||||||
.map(|(field, _)| field)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use futures::future::ok;
|
use futures::future::ok;
|
||||||
|
Loading…
Reference in New Issue
Block a user