Fix tests

This commit is contained in:
Francesco Allara 2024-02-13 21:33:09 +01:00
parent c9708f7d0c
commit a082f14c69
25 changed files with 94 additions and 115 deletions

View File

@ -56,7 +56,7 @@ fn main() {
Some(path) => TempDir::new_in(path).unwrap(),
None => TempDir::new().unwrap(),
};
let index = Index::new(options, tempdir.path()).unwrap();
let index = Index::new("", options, tempdir.path()).unwrap();
let indexer_config = IndexerConfig::default();
let index_documents_config = IndexDocumentsConfig::default();

View File

@ -103,7 +103,7 @@ impl ReopenableIndex {
return Ok(());
}
map.unavailable.remove(&self.uuid);
map.create(&self.uuid, path, None, self.enable_mdb_writemap, self.map_size)?;
map.create("", &self.uuid, path, None, self.enable_mdb_writemap, self.map_size)?;
}
Ok(())
}
@ -167,6 +167,7 @@ impl IndexMap {
///
pub fn create(
&mut self,
name: &str,
uuid: &Uuid,
path: &Path,
date: Option<(OffsetDateTime, OffsetDateTime)>,
@ -176,7 +177,7 @@ impl IndexMap {
if !matches!(self.get_unavailable(uuid), Missing) {
panic!("Attempt to open an index that was unavailable");
}
let index = create_or_open_index(path, date, enable_mdb_writemap, map_size)?;
let index = create_or_open_index(name, path, date, enable_mdb_writemap, map_size)?;
match self.available.insert(*uuid, index.clone()) {
InsertionOutcome::InsertedNew => (),
InsertionOutcome::Evicted(evicted_uuid, evicted_index) => {
@ -296,6 +297,7 @@ impl IndexMap {
/// Create or open an index in the specified path.
/// The path *must* exist or an error will be thrown.
fn create_or_open_index(
name: &str,
path: &Path,
date: Option<(OffsetDateTime, OffsetDateTime)>,
enable_mdb_writemap: bool,
@ -309,9 +311,9 @@ fn create_or_open_index(
}
if let Some((created, updated)) = date {
Ok(Index::new_with_creation_dates(options, path, created, updated)?)
Ok(Index::new_with_creation_dates(name, options, path, created, updated)?)
} else {
Ok(Index::new(options, path)?)
Ok(Index::new(name, options, path)?)
}
}

View File

@ -182,6 +182,7 @@ impl IndexMapper {
// This is very unlikely to happen in practice.
// TODO: it would be better to lazily create the index. But we need an Index::open function for milli.
let index = self.index_map.write().unwrap().create(
&name,
&uuid,
&index_path,
date,
@ -371,6 +372,7 @@ impl IndexMapper {
let index_path = self.base_path.join(uuid.to_string());
break index_map.create(
name,
&uuid,
&index_path,
None,

View File

@ -53,8 +53,8 @@ pub async fn search(
req: HttpRequest,
analytics: web::Data<dyn Analytics>,
) -> Result<HttpResponse, ResponseError> {
let index_uid_string = index_uid.into_inner();
let index_uid = IndexUid::try_from(index_uid_string.clone())?;
let index_uid = IndexUid::try_from(index_uid.into_inner())?;
let query = params.into_inner();
debug!(parameters = ?query, "Facet search");
@ -72,14 +72,7 @@ pub async fn search(
let index = index_scheduler.index(&index_uid)?;
let features = index_scheduler.features();
let search_result = tokio::task::spawn_blocking(move || {
perform_facet_search(
&index,
&index_uid_string,
search_query,
facet_query,
facet_name,
features,
)
perform_facet_search(&index, search_query, facet_query, facet_name, features)
})
.await?;

View File

@ -203,10 +203,9 @@ pub async fn search_with_url_query(
let distribution = embed(&mut query, index_scheduler.get_ref(), &index).await?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
let search_result =
tokio::task::spawn_blocking(move || perform_search(&index, query, features, distribution))
.await?;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}
@ -243,10 +242,9 @@ pub async fn search_with_post(
let distribution = embed(&mut query, index_scheduler.get_ref(), &index).await?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid.to_string(), query, features, distribution)
})
.await?;
let search_result =
tokio::task::spawn_blocking(move || perform_search(&index, query, features, distribution))
.await?;
if let Ok(ref search_result) = search_result {
aggregate.succeed(search_result);
}

View File

@ -54,8 +54,6 @@ pub async fn multi_search_with_post(
{
debug!(on_index = query_index, parameters = ?query, "Multi-search");
let index_uid_name = index_uid.to_string();
// Check index from API key
if !index_scheduler.filters().is_index_authorized(&index_uid) {
return Err(AuthenticationError::InvalidToken).with_index(query_index);
@ -82,13 +80,13 @@ pub async fn multi_search_with_post(
.with_index(query_index)?;
let search_result = tokio::task::spawn_blocking(move || {
perform_search(&index, &index_uid_name.clone(), query, features, distribution)
perform_search(&index, query, features, distribution)
})
.await
.with_index(query_index)?;
search_results.push(SearchResultWithIndex {
index_uid: index_uid.to_string(),
index_uid: index_uid.into_inner(),
result: search_result.with_index(query_index)?,
});
}

View File

@ -217,7 +217,6 @@ impl SearchQueryWithIndex {
attributes_to_search_on,
hybrid,
} = self;
(
index_uid,
SearchQuery {
@ -379,13 +378,12 @@ pub fn add_search_rules(query: &mut SearchQuery, rules: IndexSearchRules) {
fn prepare_search<'t>(
index: &'t Index,
index_uid: &'t String,
rtxn: &'t RoTxn,
query: &'t SearchQuery,
features: RoFeatures,
distribution: Option<DistributionShift>,
) -> Result<(milli::Search<'t>, bool, usize, usize), MeilisearchHttpError> {
let mut search = index.search(rtxn, &index_uid);
let mut search = index.search(rtxn);
if query.vector.is_some() {
features.check_vector("Passing `vector` as a query parameter")?;
@ -488,7 +486,6 @@ fn prepare_search<'t>(
pub fn perform_search(
index: &Index,
index_uid: &String,
query: SearchQuery,
features: RoFeatures,
distribution: Option<DistributionShift>,
@ -497,7 +494,7 @@ pub fn perform_search(
let rtxn = index.read_txn()?;
let (search, is_finite_pagination, max_total_hits, offset) =
prepare_search(index, &index_uid, &rtxn, &query, features, distribution)?;
prepare_search(index, &rtxn, &query, features, distribution)?;
let milli::SearchResult { documents_ids, matching_words, candidates, document_scores, .. } =
match &query.hybrid {
@ -720,7 +717,6 @@ pub fn perform_search(
pub fn perform_facet_search(
index: &Index,
index_uid: &String,
search_query: SearchQuery,
facet_query: Option<String>,
facet_name: String,
@ -728,8 +724,8 @@ pub fn perform_facet_search(
) -> Result<FacetSearchResult, MeilisearchHttpError> {
let before_search = Instant::now();
let rtxn = index.read_txn()?;
let (search, _, _, _) =
prepare_search(index, &index_uid, &rtxn, &search_query, features, None)?;
let (search, _, _, _) = prepare_search(index, &rtxn, &search_query, features, None)?;
let mut facet_search =
SearchForFacetValues::new(facet_name, search, search_query.hybrid.is_some());
if let Some(facet_query) = &facet_query {

View File

@ -882,7 +882,7 @@ async fn sort_unsortable_attribute() {
index.wait_task(1).await;
let expected_response = json!({
"message": "Attribute `title` is not sortable. Available sortable attributes are: `id`.",
"message": "Attribute `title` of index `test` is not sortable. Available sortable attributes are: `id`.",
"code": "invalid_search_sort",
"type": "invalid_request",
"link": "https://docs.meilisearch.com/errors#invalid_search_sort"

View File

@ -267,7 +267,7 @@ fn export_a_dump(
for result in index_mapping.iter(&rtxn)? {
let (uid, uuid) = result?;
let index_path = db_path.join("indexes").join(uuid.to_string());
let index = Index::new(EnvOpenOptions::new(), &index_path).with_context(|| {
let index = Index::new("", EnvOpenOptions::new(), &index_path).with_context(|| {
format!("While trying to open the index at path {:?}", index_path.display())
})?;

View File

@ -41,7 +41,7 @@ fn main() -> Result<(), Box<dyn Error>> {
options.map_size(100 * 1024 * 1024 * 1024); // 100 GB
std::fs::create_dir_all(&index_path).unwrap();
let index = Index::new(options, index_path).unwrap();
let index = Index::new(program_name.as_str(), options, index_path).unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -28,7 +28,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut options = EnvOpenOptions::new();
options.map_size(100 * 1024 * 1024 * 1024); // 100 GB
let index = Index::new(options, dataset)?;
let index = Index::new(program_name.as_str(), options, dataset)?;
let txn = index.read_txn()?;
let mut query = String::new();
while stdin().read_line(&mut query)? > 0 {

View File

@ -10,7 +10,7 @@ fn main() {
let mut options = EnvOpenOptions::new();
options.map_size(100 * 1024 * 1024 * 1024); // 100 GB
let index = Index::new(options, "data_movies.ms").unwrap();
let index = Index::new("", options, "data_movies.ms").unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -461,7 +461,7 @@ fn conditionally_lookup_for_error_message() {
for (list, suffix) in messages {
let err = UserError::InvalidSortableAttribute {
field: "name".to_string(),
index: "index".to_string(),
index: "index".to_string(),
valid_fields: list,
hidden_fields: false,
};

View File

@ -100,6 +100,8 @@ pub mod db_name {
#[derive(Clone)]
pub struct Index {
pub name: String,
/// The LMDB environment which this index is associated with.
pub(crate) env: heed::Env,
@ -171,6 +173,7 @@ pub struct Index {
impl Index {
pub fn new_with_creation_dates<P: AsRef<Path>>(
name: &str,
mut options: heed::EnvOpenOptions,
path: P,
created_at: OffsetDateTime,
@ -180,7 +183,8 @@ impl Index {
options.max_dbs(25);
let env = options.open(path)?;
let name = String::from(name);
let env = options.open(path)?;
let mut wtxn = env.write_txn()?;
let main = env.database_options().name(MAIN).create(&mut wtxn)?;
let word_docids = env.create_database(&mut wtxn, Some(WORD_DOCIDS))?;
@ -229,6 +233,7 @@ impl Index {
Index::set_creation_dates(&env, main, created_at, updated_at)?;
Ok(Index {
name,
env,
main,
external_documents_ids,
@ -258,9 +263,9 @@ impl Index {
})
}
pub fn new<P: AsRef<Path>>(options: heed::EnvOpenOptions, path: P) -> Result<Index> {
pub fn new<P: AsRef<Path>>(name: &str, options: heed::EnvOpenOptions, path: P) -> Result<Index> {
let now = OffsetDateTime::now_utc();
Self::new_with_creation_dates(options, path, now, now)
Self::new_with_creation_dates(name, options, path, now, now)
}
fn set_creation_dates(
@ -1212,8 +1217,8 @@ impl Index {
FacetDistribution::new(rtxn, self)
}
pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: &'a String) -> Search<'a> {
Search::new(rtxn, self, &index_uid)
pub fn search<'a>(&'a self, rtxn: &'a RoTxn) -> Search<'a> {
Search::new(rtxn, self)
}
/// Returns the index creation time.
@ -1548,7 +1553,7 @@ pub(crate) mod tests {
let mut options = EnvOpenOptions::new();
options.map_size(size);
let _tempdir = TempDir::new_in(".").unwrap();
let inner = Index::new(options, _tempdir.path()).unwrap();
let inner = Index::new("temp", options, _tempdir.path()).unwrap();
let indexer_config = IndexerConfig::default();
let index_documents_config = IndexDocumentsConfig::default();
Self { inner, indexer_config, index_documents_config, _tempdir }
@ -1864,7 +1869,7 @@ pub(crate) mod tests {
// ensure we get the right real searchable fields + user defined searchable fields
let rtxn = index.read_txn().unwrap();
let mut search = index.search(&rtxn, &index.to_string());
let mut search = index.search(&rtxn);
// exact match a document
let search_result = search

View File

@ -115,7 +115,6 @@ impl<'a> Search<'a> {
// TODO: find classier way to achieve that than to reset vector and query params
// create separate keyword and semantic searches
let mut search = Search {
index_uid: &self.index_uid,
query: self.query.clone(),
vector: self.vector.clone(),
filter: self.filter.clone(),

View File

@ -36,7 +36,6 @@ pub mod hybrid;
pub mod new;
pub struct Search<'a> {
index_uid: &'a String,
query: Option<String>,
vector: Option<Vec<f32>>,
// this should be linked to the String in the query
@ -58,9 +57,8 @@ pub struct Search<'a> {
}
impl<'a> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: &'a String) -> Search<'a> {
pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> Search<'a> {
Search {
index_uid,
query: None,
vector: None,
filter: None,
@ -70,7 +68,7 @@ impl<'a> Search<'a> {
searchable_attributes: None,
geo_strategy: new::GeoSortStrategy::default(),
terms_matching_strategy: TermsMatchingStrategy::default(),
scori ng_strategy: Default::default(),
scoring_strategy: Default::default(),
exhaustive_number_hits: false,
words_limit: 10,
rtxn,
@ -158,7 +156,7 @@ impl<'a> Search<'a> {
pub fn execute_for_candidates(&self, has_vector_search: bool) -> Result<RoaringBitmap> {
if has_vector_search {
let ctx = SearchContext::new(self.index, self.index_uid.clone(), self.rtxn);
let ctx = SearchContext::new(self.index, self.rtxn);
filtered_universe(&ctx, &self.filter)
} else {
Ok(self.execute()?.candidates)
@ -175,7 +173,7 @@ impl<'a> Search<'a> {
}
};
let mut ctx = SearchContext::new(self.index, self.index_uid.to_string(), self.rtxn);
let mut ctx = SearchContext::new(self.index, self.rtxn);
if let Some(searchable_attributes) = self.searchable_attributes {
ctx.searchable_attributes(searchable_attributes)?;
@ -226,7 +224,6 @@ impl<'a> Search<'a> {
impl fmt::Debug for Search<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Search {
index_uid,
query,
vector: _,
filter,
@ -245,7 +242,6 @@ impl fmt::Debug for Search<'_> {
embedder_name,
} = self;
f.debug_struct("Search")
.field("index_uid", index_uid)
.field("query", query)
.field("vector", &"[...]")
.field("filter", filter)

View File

@ -58,7 +58,6 @@ use crate::{
/// A structure used throughout the execution of a search query.
pub struct SearchContext<'ctx> {
pub index: &'ctx Index,
pub index_uid: String,
pub txn: &'ctx RoTxn<'ctx>,
pub db_cache: DatabaseCache<'ctx>,
pub word_interner: DedupInterner<String>,
@ -69,10 +68,9 @@ pub struct SearchContext<'ctx> {
}
impl<'ctx> SearchContext<'ctx> {
pub fn new(index: &'ctx Index, index_uid: String, txn: &'ctx RoTxn<'ctx>) -> Self {
pub fn new(index: &'ctx Index, txn: &'ctx RoTxn<'ctx>) -> Self {
Self {
index,
index_uid,
txn,
db_cache: <_>::default(),
word_interner: <_>::default(),
@ -708,7 +706,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec<AscDesc>>
return Err(UserError::InvalidSortableAttribute {
field: field.to_string(),
index: ctx.index_uid.clone(),
index: ctx.index.name.clone(),
valid_fields,
hidden_fields,
}
@ -720,7 +718,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec<AscDesc>>
return Err(UserError::InvalidSortableAttribute {
field: "_geo".to_string(),
index: ctx.index_uid.clone(),
index: ctx.index.name.clone(),
valid_fields,
hidden_fields,
}

View File

@ -13,7 +13,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
let path = tempfile::tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(10 * 1024 * 1024); // 10 MB
let index = Index::new(options, &path).unwrap();
let index = Index::new("", options, &path).unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -25,6 +25,7 @@ impl<'t, 'i> ClearDocuments<'t, 'i> {
self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?;
let Index {
name: _name,
env: _env,
main: _main,
external_documents_ids,

View File

@ -1033,15 +1033,15 @@ mod tests {
let rtxn = index.read_txn().unwrap();
// Search for a sub object value
let result = index.search(&rtxn, &String::from("test_index")).query(r#""value2""#).execute().unwrap();
let result = index.search(&rtxn).query(r#""value2""#).execute().unwrap();
assert_eq!(result.documents_ids, vec![0]);
// Search for a sub array value
let result = index.search(&rtxn, &String::from("test_index")).query(r#""fine""#).execute().unwrap();
let result = index.search(&rtxn).query(r#""fine""#).execute().unwrap();
assert_eq!(result.documents_ids, vec![1]);
// Search for a sub array sub object key
let result = index.search(&rtxn, &String::from("test_index")).query(r#""amazing""#).execute().unwrap();
let result = index.search(&rtxn).query(r#""amazing""#).execute().unwrap();
assert_eq!(result.documents_ids, vec![2]);
drop(rtxn);
@ -1348,7 +1348,7 @@ mod tests {
assert_eq!(facets, hashset!(S("title"), S("nested.object"), S("nested.machin")));
// testing the simple query search
let mut search = crate::Search::new(&rtxn, &index, &String::from("test_index"));
let mut search = crate::Search::new(&rtxn, &index);
search.query("document");
search.terms_matching_strategy(TermsMatchingStrategy::default());
// all documents should be returned
@ -1389,7 +1389,7 @@ mod tests {
assert!(documents_ids.is_empty()); // nested is not searchable
// testing the filters
let mut search = crate::Search::new(&rtxn, &index, &String::from("test_index"));
let mut search = crate::Search::new(&rtxn, &index);
search.filter(crate::Filter::from_str(r#"title = "The first document""#).unwrap().unwrap());
let crate::SearchResult { documents_ids, .. } = search.execute().unwrap();
assert_eq!(documents_ids, vec![1]);
@ -1453,7 +1453,7 @@ mod tests {
let rtxn = index.read_txn().unwrap();
// testing the simple query search
let mut search = crate::Search::new(&rtxn, &index, &String::from("test_index"));
let mut search = crate::Search::new(&rtxn, &index);
search.query("document");
search.terms_matching_strategy(TermsMatchingStrategy::default());
// all documents should be returned
@ -1565,7 +1565,7 @@ mod tests {
assert_eq!(hidden, hashset!(S("dog"), S("dog.race"), S("dog.race.bernese mountain")));
for (s, i) in [("zeroth", 0), ("first", 1), ("second", 2), ("third", 3)] {
let mut search = crate::Search::new(&rtxn, &index, &String::from("test_index"));
let mut search = crate::Search::new(&rtxn, &index);
let filter = format!(r#""dog.race.bernese mountain" = {s}"#);
search.filter(crate::Filter::from_str(&filter).unwrap().unwrap());
let crate::SearchResult { documents_ids, .. } = search.execute().unwrap();
@ -1613,7 +1613,7 @@ mod tests {
assert_eq!(facets, hashset!(S("dog.race"), S("dog.race.bernese mountain")));
let mut search = crate::Search::new(&rtxn, &index, &String::from("test_index"));
let mut search = crate::Search::new(&rtxn, &index);
search.sort_criteria(vec![crate::AscDesc::Asc(crate::Member::Field(S(
"dog.race.bernese mountain",
)))]);
@ -2610,7 +2610,7 @@ mod tests {
.unwrap();
let rtxn = index.read_txn().unwrap();
let res = index.search(&rtxn, &String::from("test_index")).vector([0.0, 1.0, 2.0].to_vec()).execute().unwrap();
let res = index.search(&rtxn).vector([0.0, 1.0, 2.0].to_vec()).execute().unwrap();
assert_eq!(res.documents_ids.len(), 3);
}
@ -2771,7 +2771,7 @@ mod tests {
// Ensuring all the returned IDs actually exists
let rtxn = index.read_txn().unwrap();
let res = index.search(&rtxn, &String::from("test_index")).execute().unwrap();
let res = index.search(&rtxn).execute().unwrap();
index.documents(&rtxn, res.documents_ids).unwrap();
}
@ -2908,7 +2908,7 @@ mod tests {
// Placeholder search with filter
let filter = Filter::from_str("label = sign").unwrap().unwrap();
let results = index.search(&wtxn, &String::from("test_index")).filter(filter).execute().unwrap();
let results = index.search(&wtxn).filter(filter).execute().unwrap();
assert!(results.documents_ids.is_empty());
wtxn.commit().unwrap();
@ -2965,7 +2965,7 @@ mod tests {
let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_4"]);
// Placeholder search
let results = index.search(&wtxn, &String::from("test_index")).execute().unwrap();
let results = index.search(&wtxn).execute().unwrap();
assert!(!results.documents_ids.is_empty());
for id in results.documents_ids.iter() {
assert!(
@ -3023,7 +3023,7 @@ mod tests {
let deleted_internal_ids = delete_documents(&mut wtxn, &index, &["1_7", "1_52"]);
// search for abstract
let results = index.search(&wtxn, &String::from("test_index")).query("abstract").execute().unwrap();
let results = index.search(&wtxn).query("abstract").execute().unwrap();
assert!(!results.documents_ids.is_empty());
for id in results.documents_ids.iter() {
assert!(
@ -3075,10 +3075,9 @@ mod tests {
let external_ids_to_delete = ["5", "6", "7", "12", "17", "19"];
let deleted_internal_ids = delete_documents(&mut wtxn, &index, &external_ids_to_delete);
let index_uid = String::from("test_index");
// Placeholder search with geo filter
let filter = Filter::from_str("_geoRadius(50.6924, 3.1763, 20000)").unwrap().unwrap();
let results = index.search(&wtxn, &index_uid).filter(filter).execute().unwrap();
let results = index.search(&wtxn).filter(filter).execute().unwrap();
assert!(!results.documents_ids.is_empty());
for id in results.documents_ids.iter() {
assert!(
@ -3303,8 +3302,7 @@ mod tests {
let words = index.words_fst(&txn).unwrap().into_stream().into_strs().unwrap();
insta::assert_snapshot!(format!("{words:?}"), @r###"["hello"]"###);
let index_uid = String::from("test_index");
let mut s = Search::new(&txn, &index, &index_uid);
let mut s = Search::new(&txn, &index);
s.query("hello");
let crate::SearchResult { documents_ids, .. } = s.execute().unwrap();
insta::assert_snapshot!(format!("{documents_ids:?}"), @"[0]");

View File

@ -1215,7 +1215,6 @@ mod tests {
#[test]
fn set_and_reset_searchable_fields() {
let index = TempIndex::new();
let index_uid = String::from("test_index");
// First we send 3 documents with ids from 1 to 3.
let mut wtxn = index.write_txn().unwrap();
@ -1244,12 +1243,12 @@ mod tests {
let rtxn = index.read_txn().unwrap();
// When we search for something that is not in
// the searchable fields it must not return any document.
let result = index.search(&rtxn, &index_uid).query("23").execute().unwrap();
let result = index.search(&rtxn).query("23").execute().unwrap();
assert!(result.documents_ids.is_empty());
// When we search for something that is in the searchable fields
// we must find the appropriate document.
let result = index.search(&rtxn, &index_uid).query(r#""kevin""#).execute().unwrap();
let result = index.search(&rtxn).query(r#""kevin""#).execute().unwrap();
let documents = index.documents(&rtxn, result.documents_ids).unwrap();
assert_eq!(documents.len(), 1);
assert_eq!(documents[0].1.get(0), Some(&br#""kevin""#[..]));
@ -1266,7 +1265,7 @@ mod tests {
let rtxn = index.read_txn().unwrap();
let searchable_fields = index.searchable_fields(&rtxn).unwrap();
assert_eq!(searchable_fields, None);
let result = index.search(&rtxn, &index_uid).query("23").execute().unwrap();
let result = index.search(&rtxn).query("23").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1);
let documents = index.documents(&rtxn, result.documents_ids).unwrap();
assert_eq!(documents[0].1.get(0), Some(&br#""kevin""#[..]));
@ -1469,8 +1468,7 @@ mod tests {
// Run an empty query just to ensure that the search results are ordered.
let rtxn = index.read_txn().unwrap();
let index_uid = String::from("test_index");
let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap();
let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap();
let documents = index.documents(&rtxn, documents_ids).unwrap();
// Fetch the documents "age" field in the ordre in which the documents appear.
@ -1513,8 +1511,7 @@ mod tests {
// Run an empty query just to ensure that the search results are ordered.
let rtxn = index.read_txn().unwrap();
let index_uid = String::from("test_index");
let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap();
let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap();
// There must be at least one document with a 34 as the age.
assert_eq!(documents_ids.len(), 3);
@ -1549,8 +1546,7 @@ mod tests {
// Run an empty query just to ensure that the search results are ordered.
let rtxn = index.read_txn().unwrap();
let index_uid = String::from("test_index");
let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap();
let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap();
// There must be at least one document with a 34 as the age.
assert_eq!(documents_ids.len(), 3);
@ -1613,19 +1609,18 @@ mod tests {
let expected = fst::Set::from_iter(&set).unwrap();
assert_eq!(stop_words.as_fst().as_bytes(), expected.as_fst().as_bytes());
let index_uid = String::from("test_index");
// when we search for something that is a non prefix stop_words it should be ignored
// thus we should get a placeholder search (all the results = 3)
let result = index.search(&rtxn, &index_uid).query("the ").execute().unwrap();
let result = index.search(&rtxn).query("the ").execute().unwrap();
assert_eq!(result.documents_ids.len(), 3);
let result = index.search(&rtxn, &index_uid).query("i ").execute().unwrap();
let result = index.search(&rtxn).query("i ").execute().unwrap();
assert_eq!(result.documents_ids.len(), 3);
let result = index.search(&rtxn, &index_uid).query("are ").execute().unwrap();
let result = index.search(&rtxn).query("are ").execute().unwrap();
assert_eq!(result.documents_ids.len(), 3);
let result = index.search(&rtxn, &index_uid).query("dog").execute().unwrap();
let result = index.search(&rtxn).query("dog").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2); // we have two maxims talking about doggos
let result = index.search(&rtxn, &index_uid).query("benoît").execute().unwrap();
let result = index.search(&rtxn).query("benoît").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1); // there is one benoit in our data
// now we'll reset the stop_words and ensure it's None
@ -1640,17 +1635,17 @@ mod tests {
assert!(stop_words.is_none());
// now we can search for the stop words
let result = index.search(&rtxn, &index_uid).query("the").execute().unwrap();
let result = index.search(&rtxn).query("the").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2);
let result = index.search(&rtxn, &index_uid).query("i").execute().unwrap();
let result = index.search(&rtxn).query("i").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1);
let result = index.search(&rtxn, &index_uid).query("are").execute().unwrap();
let result = index.search(&rtxn).query("are").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2);
// the rest of the search is still not impacted
let result = index.search(&rtxn, &index_uid).query("dog").execute().unwrap();
let result = index.search(&rtxn).query("dog").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2); // we have two maxims talking about doggos
let result = index.search(&rtxn, &index_uid).query("benoît").execute().unwrap();
let result = index.search(&rtxn).query("benoît").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1); // there is one benoit in our data
}
@ -1689,13 +1684,12 @@ mod tests {
let synonyms = index.synonyms(&rtxn).unwrap();
assert!(!synonyms.is_empty()); // at this point the index should return something
let index_uid = String::from("temp");
// Check that we can use synonyms
let result = index.search(&rtxn, &index_uid).query("blini").execute().unwrap();
let result = index.search(&rtxn).query("blini").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1);
let result = index.search(&rtxn, &index_uid).query("super like").execute().unwrap();
let result = index.search(&rtxn).query("super like").execute().unwrap();
assert_eq!(result.documents_ids.len(), 1);
let result = index.search(&rtxn, &index_uid).query("puppies").execute().unwrap();
let result = index.search(&rtxn).query("puppies").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2);
// Reset the synonyms
@ -1711,11 +1705,11 @@ mod tests {
assert!(synonyms.is_empty());
// Check that synonyms are no longer work
let result = index.search(&rtxn, &index_uid).query("blini").execute().unwrap();
let result = index.search(&rtxn).query("blini").execute().unwrap();
assert!(result.documents_ids.is_empty());
let result = index.search(&rtxn, &index_uid).query("super like").execute().unwrap();
let result = index.search(&rtxn).query("super like").execute().unwrap();
assert!(result.documents_ids.is_empty());
let result = index.search(&rtxn, &index_uid).query("puppies").execute().unwrap();
let result = index.search(&rtxn).query("puppies").execute().unwrap();
assert!(result.documents_ids.is_empty());
}
@ -1752,7 +1746,7 @@ mod tests {
assert!(!synonyms.is_empty()); // at this point the index should return something
// Check that we can use synonyms
let result = index.search(&rtxn, &index_uid).query("japanese").execute().unwrap();
let result = index.search(&rtxn).query("japanese").execute().unwrap();
assert_eq!(result.documents_ids.len(), 2);
}
@ -1905,9 +1899,8 @@ mod tests {
}
])).unwrap();
let index_uid = String::from("temp");
let rtxn = index.read_txn().unwrap();
let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).query("S").execute().unwrap();
let SearchResult { documents_ids, .. } = index.search(&rtxn).query("S").execute().unwrap();
let first_id = documents_ids[0];
let documents = index.documents(&rtxn, documents_ids).unwrap();
let (_, content) = documents.iter().find(|(id, _)| *id == first_id).unwrap();

View File

@ -13,7 +13,7 @@ fn test_facet_distribution_with_no_facet_values() {
let path = tempfile::tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(10 * 1024 * 1024); // 10 MB
let index = Index::new(options, &path).unwrap();
let index = Index::new("", options, &path).unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -31,7 +31,7 @@ pub fn setup_search_index_with_criteria(criteria: &[Criterion]) -> Index {
let path = tempfile::tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(10 * 1024 * 1024); // 10 MB
let index = Index::new(options, &path).unwrap();
let index = Index::new("", options, &path).unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -262,7 +262,7 @@ fn criteria_ascdesc() {
let path = tempfile::tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(12 * 1024 * 1024); // 10 MB
let index = Index::new(options, &path).unwrap();
let index = Index::new("", options, &path).unwrap();
let mut wtxn = index.write_txn().unwrap();
let config = IndexerConfig::default();

View File

@ -104,7 +104,7 @@ fn test_typo_disabled_on_word() {
let tmp = tempdir().unwrap();
let mut options = EnvOpenOptions::new();
options.map_size(4096 * 100);
let index = Index::new(options, tmp.path()).unwrap();
let index = Index::new("", options, tmp.path()).unwrap();
let mut builder = milli::documents::DocumentsBatchBuilder::new(Vec::new());
let doc1 = json!({