From e6597cd57ad47fdf57d9a7103f6bd66fa197d1b4 Mon Sep 17 00:00:00 2001 From: Francesco Date: Mon, 12 Feb 2024 20:23:48 +0100 Subject: [PATCH 01/10] Add index name to non sortable search query --- meilisearch/src/analytics/segment_analytics.rs | 1 + meilisearch/src/routes/indexes/facet_search.rs | 1 + meilisearch/src/routes/indexes/search.rs | 15 +++++++++------ meilisearch/src/routes/multi_search.rs | 6 ++++-- meilisearch/src/search.rs | 12 +++++++++--- milli/src/error.rs | 5 +++-- milli/src/index.rs | 4 ++-- milli/src/search/hybrid.rs | 1 + milli/src/search/mod.rs | 10 +++++++--- milli/src/search/new/mod.rs | 6 +++++- 10 files changed, 42 insertions(+), 19 deletions(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index a38ddaab2..b0035f447 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -634,6 +634,7 @@ impl SearchAggregator { pub fn from_query(query: &SearchQuery, request: &HttpRequest) -> Self { let SearchQuery { q, + index_uid, vector, offset, limit, diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index a980fb278..bd9ff3dee 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -102,6 +102,7 @@ impl From for SearchQuery { SearchQuery { q, + index_uid: None, offset: DEFAULT_SEARCH_OFFSET(), limit: DEFAULT_SEARCH_LIMIT(), page: None, diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 3adfce970..90416e54d 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -128,6 +128,7 @@ impl From for SearchQuery { }; Self { + index_uid: None, q: other.q, vector: other.vector.map(CS::into_inner), offset: other.offset.0, @@ -203,9 +204,10 @@ 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, query, features, distribution)) - .await?; + let search_result = tokio::task::spawn_blocking(move || { + perform_search(&index, index_uid.to_string(), query, features, distribution) + }) + .await?; if let Ok(ref search_result) = search_result { aggregate.succeed(search_result); } @@ -242,9 +244,10 @@ 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, query, features, distribution)) - .await?; + let search_result = tokio::task::spawn_blocking(move || { + perform_search(&index, index_uid.to_string(), query, features, distribution) + }) + .await?; if let Ok(ref search_result) = search_result { aggregate.succeed(search_result); } diff --git a/meilisearch/src/routes/multi_search.rs b/meilisearch/src/routes/multi_search.rs index 86aa58e70..fb11d2c1a 100644 --- a/meilisearch/src/routes/multi_search.rs +++ b/meilisearch/src/routes/multi_search.rs @@ -54,6 +54,8 @@ pub async fn multi_search_with_post( { debug!(on_index = query_index, parameters = ?query, "Multi-search"); + let index_uid_name = &index_uid.clone(); + // Check index from API key if !index_scheduler.filters().is_index_authorized(&index_uid) { return Err(AuthenticationError::InvalidToken).with_index(query_index); @@ -80,13 +82,13 @@ pub async fn multi_search_with_post( .with_index(query_index)?; let search_result = tokio::task::spawn_blocking(move || { - perform_search(&index, query, features, distribution) + perform_search(&index, index_uid.to_string().clone(), query, features, distribution) }) .await .with_index(query_index)?; search_results.push(SearchResultWithIndex { - index_uid: index_uid.into_inner(), + index_uid: index_uid_name.to_string(), result: search_result.with_index(query_index)?, }); } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 27de36c6d..f434739b0 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -41,6 +41,7 @@ pub const DEFAULT_SEMANTIC_RATIO: fn() -> SemanticRatio = || SemanticRatio(0.5); #[derive(Debug, Clone, Default, PartialEq, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQuery { + pub index_uid: Option, #[deserr(default, error = DeserrJsonError)] pub q: Option, #[deserr(default, error = DeserrJsonError)] @@ -192,6 +193,7 @@ pub struct SearchQueryWithIndex { impl SearchQueryWithIndex { pub fn into_index_query(self) -> (IndexUid, SearchQuery) { + let index_uid_name = self.index_uid.clone().to_string().clone(); let SearchQueryWithIndex { index_uid, q, @@ -221,6 +223,7 @@ impl SearchQueryWithIndex { index_uid, SearchQuery { q, + index_uid: Some(index_uid_name), vector, offset, limit, @@ -378,12 +381,13 @@ pub fn add_search_rules(query: &mut SearchQuery, rules: IndexSearchRules) { fn prepare_search<'t>( index: &'t Index, + index_uid: &String, rtxn: &'t RoTxn, query: &'t SearchQuery, features: RoFeatures, distribution: Option, ) -> Result<(milli::Search<'t>, bool, usize, usize), MeilisearchHttpError> { - let mut search = index.search(rtxn); + let mut search = index.search(rtxn, index_uid.clone()); if query.vector.is_some() { features.check_vector("Passing `vector` as a query parameter")?; @@ -486,6 +490,7 @@ fn prepare_search<'t>( pub fn perform_search( index: &Index, + index_uid: String, query: SearchQuery, features: RoFeatures, distribution: Option, @@ -494,7 +499,7 @@ pub fn perform_search( let rtxn = index.read_txn()?; let (search, is_finite_pagination, max_total_hits, offset) = - prepare_search(index, &rtxn, &query, features, distribution)?; + prepare_search(index, &index_uid, &rtxn, &query, features, distribution)?; let milli::SearchResult { documents_ids, matching_words, candidates, document_scores, .. } = match &query.hybrid { @@ -725,7 +730,8 @@ pub fn perform_facet_search( let before_search = Instant::now(); let rtxn = index.read_txn()?; - let (search, _, _, _) = prepare_search(index, &rtxn, &search_query, features, None)?; + let (search, _, _, _) = + prepare_search(index, &"".to_string(), &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 { diff --git a/milli/src/error.rs b/milli/src/error.rs index 1147085dd..138dd6be8 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -122,8 +122,9 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco InvalidFilter(String), #[error("Invalid type for filter subexpression: expected: {}, found: {1}.", .0.join(", "))] InvalidFilterExpression(&'static [&'static str], Value), - #[error("Attribute `{}` is not sortable. {}", + #[error("Attribute `{}` of index `{}` is not sortable. {}", .field, + .index, match .valid_fields.is_empty() { true => "This index does not have configured sortable attributes.".to_string(), false => format!("Available sortable attributes are: `{}{}`.", @@ -132,7 +133,7 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco ), } )] - InvalidSortableAttribute { field: String, valid_fields: BTreeSet, hidden_fields: bool }, + InvalidSortableAttribute { field: String, index: String, valid_fields: BTreeSet, hidden_fields: bool }, #[error("Attribute `{}` is not facet-searchable. {}", .field, match .valid_fields.is_empty() { diff --git a/milli/src/index.rs b/milli/src/index.rs index 6ad39dcb1..b45a311fb 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1212,8 +1212,8 @@ impl Index { FacetDistribution::new(rtxn, self) } - pub fn search<'a>(&'a self, rtxn: &'a RoTxn) -> Search<'a> { - Search::new(rtxn, self) + pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: String) -> Search<'a> { + Search::new(rtxn, self, index_uid) } /// Returns the index creation time. diff --git a/milli/src/search/hybrid.rs b/milli/src/search/hybrid.rs index b4c79f7f5..f7c480396 100644 --- a/milli/src/search/hybrid.rs +++ b/milli/src/search/hybrid.rs @@ -115,6 +115,7 @@ 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.to_string().clone(), query: self.query.clone(), vector: self.vector.clone(), filter: self.filter.clone(), diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index e411bd032..0e30b6b0b 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -36,6 +36,7 @@ pub mod hybrid; pub mod new; pub struct Search<'a> { + index_uid: String, query: Option, vector: Option>, // this should be linked to the String in the query @@ -57,8 +58,9 @@ pub struct Search<'a> { } impl<'a> Search<'a> { - pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index) -> Search<'a> { + pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: String) -> Search<'a> { Search { + index_uid, query: None, vector: None, filter: None, @@ -156,7 +158,7 @@ impl<'a> Search<'a> { pub fn execute_for_candidates(&self, has_vector_search: bool) -> Result { if has_vector_search { - let ctx = SearchContext::new(self.index, self.rtxn); + let ctx = SearchContext::new(self.index, self.index_uid.to_string(), self.rtxn); filtered_universe(&ctx, &self.filter) } else { Ok(self.execute()?.candidates) @@ -173,7 +175,7 @@ impl<'a> Search<'a> { } }; - let mut ctx = SearchContext::new(self.index, self.rtxn); + let mut ctx = SearchContext::new(self.index, self.index_uid.to_string(), self.rtxn); if let Some(searchable_attributes) = self.searchable_attributes { ctx.searchable_attributes(searchable_attributes)?; @@ -224,6 +226,7 @@ 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, @@ -242,6 +245,7 @@ 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) diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index 7b3b1d5b2..e0405ec6b 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -58,6 +58,7 @@ 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, @@ -68,9 +69,10 @@ pub struct SearchContext<'ctx> { } impl<'ctx> SearchContext<'ctx> { - pub fn new(index: &'ctx Index, txn: &'ctx RoTxn<'ctx>) -> Self { + pub fn new(index: &'ctx Index, index_uid: String, txn: &'ctx RoTxn<'ctx>) -> Self { Self { index, + index_uid, txn, db_cache: <_>::default(), word_interner: <_>::default(), @@ -706,6 +708,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: field.to_string(), + index: ctx.index_uid.clone(), valid_fields, hidden_fields, } @@ -717,6 +720,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: "_geo".to_string(), + index: ctx.index_uid.clone(), valid_fields, hidden_fields, } From e288dd740648e4ac99e94235f0fa61359fc9c4fc Mon Sep 17 00:00:00 2001 From: Francesco Date: Tue, 13 Feb 2024 16:16:36 +0100 Subject: [PATCH 02/10] Added index name to unsortable error message --- meilisearch/src/analytics/segment_analytics.rs | 1 - meilisearch/src/routes/indexes/facet_search.rs | 14 ++++++++++---- meilisearch/src/routes/indexes/search.rs | 5 ++--- meilisearch/src/routes/multi_search.rs | 6 +++--- meilisearch/src/search.rs | 14 ++++++-------- milli/src/index.rs | 4 ++-- milli/src/search/hybrid.rs | 2 +- milli/src/search/mod.rs | 6 +++--- 8 files changed, 27 insertions(+), 25 deletions(-) diff --git a/meilisearch/src/analytics/segment_analytics.rs b/meilisearch/src/analytics/segment_analytics.rs index b0035f447..a38ddaab2 100644 --- a/meilisearch/src/analytics/segment_analytics.rs +++ b/meilisearch/src/analytics/segment_analytics.rs @@ -634,7 +634,6 @@ impl SearchAggregator { pub fn from_query(query: &SearchQuery, request: &HttpRequest) -> Self { let SearchQuery { q, - index_uid, vector, offset, limit, diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index bd9ff3dee..23c09def0 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -53,8 +53,8 @@ pub async fn search( req: HttpRequest, analytics: web::Data, ) -> Result { - let index_uid = IndexUid::try_from(index_uid.into_inner())?; - + let index_uid_string = index_uid.into_inner(); + let index_uid = IndexUid::try_from(index_uid_string.clone())?; let query = params.into_inner(); debug!(parameters = ?query, "Facet search"); @@ -72,7 +72,14 @@ 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, search_query, facet_query, facet_name, features) + perform_facet_search( + &index, + &index_uid_string, + search_query, + facet_query, + facet_name, + features, + ) }) .await?; @@ -102,7 +109,6 @@ impl From for SearchQuery { SearchQuery { q, - index_uid: None, offset: DEFAULT_SEARCH_OFFSET(), limit: DEFAULT_SEARCH_LIMIT(), page: None, diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 90416e54d..8152869a9 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -128,7 +128,6 @@ impl From for SearchQuery { }; Self { - index_uid: None, q: other.q, vector: other.vector.map(CS::into_inner), offset: other.offset.0, @@ -205,7 +204,7 @@ 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) + perform_search(&index, &index_uid.to_string(), query, features, distribution) }) .await?; if let Ok(ref search_result) = search_result { @@ -245,7 +244,7 @@ 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) + perform_search(&index, &index_uid.to_string(), query, features, distribution) }) .await?; if let Ok(ref search_result) = search_result { diff --git a/meilisearch/src/routes/multi_search.rs b/meilisearch/src/routes/multi_search.rs index fb11d2c1a..b074cf39d 100644 --- a/meilisearch/src/routes/multi_search.rs +++ b/meilisearch/src/routes/multi_search.rs @@ -54,7 +54,7 @@ pub async fn multi_search_with_post( { debug!(on_index = query_index, parameters = ?query, "Multi-search"); - let index_uid_name = &index_uid.clone(); + let index_uid_name = index_uid.to_string(); // Check index from API key if !index_scheduler.filters().is_index_authorized(&index_uid) { @@ -82,13 +82,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.to_string().clone(), query, features, distribution) + perform_search(&index, &index_uid_name.clone(), query, features, distribution) }) .await .with_index(query_index)?; search_results.push(SearchResultWithIndex { - index_uid: index_uid_name.to_string(), + index_uid: index_uid.to_string(), result: search_result.with_index(query_index)?, }); } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index f434739b0..43f05fff2 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -41,7 +41,6 @@ pub const DEFAULT_SEMANTIC_RATIO: fn() -> SemanticRatio = || SemanticRatio(0.5); #[derive(Debug, Clone, Default, PartialEq, Deserr)] #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] pub struct SearchQuery { - pub index_uid: Option, #[deserr(default, error = DeserrJsonError)] pub q: Option, #[deserr(default, error = DeserrJsonError)] @@ -193,7 +192,6 @@ pub struct SearchQueryWithIndex { impl SearchQueryWithIndex { pub fn into_index_query(self) -> (IndexUid, SearchQuery) { - let index_uid_name = self.index_uid.clone().to_string().clone(); let SearchQueryWithIndex { index_uid, q, @@ -219,11 +217,11 @@ impl SearchQueryWithIndex { attributes_to_search_on, hybrid, } = self; + ( index_uid, SearchQuery { q, - index_uid: Some(index_uid_name), vector, offset, limit, @@ -381,13 +379,13 @@ pub fn add_search_rules(query: &mut SearchQuery, rules: IndexSearchRules) { fn prepare_search<'t>( index: &'t Index, - index_uid: &String, + index_uid: &'t String, rtxn: &'t RoTxn, query: &'t SearchQuery, features: RoFeatures, distribution: Option, ) -> Result<(milli::Search<'t>, bool, usize, usize), MeilisearchHttpError> { - let mut search = index.search(rtxn, index_uid.clone()); + let mut search = index.search(rtxn, &index_uid); if query.vector.is_some() { features.check_vector("Passing `vector` as a query parameter")?; @@ -490,7 +488,7 @@ fn prepare_search<'t>( pub fn perform_search( index: &Index, - index_uid: String, + index_uid: &String, query: SearchQuery, features: RoFeatures, distribution: Option, @@ -722,6 +720,7 @@ pub fn perform_search( pub fn perform_facet_search( index: &Index, + index_uid: &String, search_query: SearchQuery, facet_query: Option, facet_name: String, @@ -729,9 +728,8 @@ pub fn perform_facet_search( ) -> Result { let before_search = Instant::now(); let rtxn = index.read_txn()?; - let (search, _, _, _) = - prepare_search(index, &"".to_string(), &rtxn, &search_query, features, None)?; + prepare_search(index, &index_uid, &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 { diff --git a/milli/src/index.rs b/milli/src/index.rs index b45a311fb..0a4548b29 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1212,8 +1212,8 @@ impl Index { FacetDistribution::new(rtxn, self) } - pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: String) -> Search<'a> { - Search::new(rtxn, self, index_uid) + pub fn search<'a>(&'a self, rtxn: &'a RoTxn, index_uid: &'a String) -> Search<'a> { + Search::new(rtxn, self, &index_uid) } /// Returns the index creation time. diff --git a/milli/src/search/hybrid.rs b/milli/src/search/hybrid.rs index f7c480396..3dab9b272 100644 --- a/milli/src/search/hybrid.rs +++ b/milli/src/search/hybrid.rs @@ -115,7 +115,7 @@ 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.to_string().clone(), + index_uid: &self.index_uid, query: self.query.clone(), vector: self.vector.clone(), filter: self.filter.clone(), diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 0e30b6b0b..0bbfd2cc0 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -36,7 +36,7 @@ pub mod hybrid; pub mod new; pub struct Search<'a> { - index_uid: String, + index_uid: &'a String, query: Option, vector: Option>, // this should be linked to the String in the query @@ -58,7 +58,7 @@ pub struct Search<'a> { } impl<'a> Search<'a> { - pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: String) -> Search<'a> { + pub fn new(rtxn: &'a heed::RoTxn, index: &'a Index, index_uid: &'a String) -> Search<'a> { Search { index_uid, query: None, @@ -158,7 +158,7 @@ impl<'a> Search<'a> { pub fn execute_for_candidates(&self, has_vector_search: bool) -> Result { if has_vector_search { - let ctx = SearchContext::new(self.index, self.index_uid.to_string(), self.rtxn); + let ctx = SearchContext::new(self.index, self.index_uid.clone(), self.rtxn); filtered_universe(&ctx, &self.filter) } else { Ok(self.execute()?.candidates) From c9708f7d0cd1f81a2f447bfab8c146921cca5a12 Mon Sep 17 00:00:00 2001 From: Francesco Allara Date: Tue, 13 Feb 2024 17:50:40 +0100 Subject: [PATCH 03/10] Fixing the tests --- milli/src/error.rs | 3 +- milli/src/index.rs | 2 +- milli/src/search/mod.rs | 2 +- milli/src/update/index_documents/mod.rs | 32 +++++++------- milli/src/update/settings.rs | 55 ++++++++++++++----------- 5 files changed, 52 insertions(+), 42 deletions(-) diff --git a/milli/src/error.rs b/milli/src/error.rs index 138dd6be8..5926e1814 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -452,7 +452,7 @@ impl std::fmt::Display for FaultSource { #[test] fn conditionally_lookup_for_error_message() { - let prefix = "Attribute `name` is not sortable."; + let prefix = "Attribute `name` of index `index` is not sortable."; let messages = vec![ (BTreeSet::new(), "This index does not have configured sortable attributes."), (BTreeSet::from(["age".to_string()]), "Available sortable attributes are: `age`."), @@ -461,6 +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(), valid_fields: list, hidden_fields: false, }; diff --git a/milli/src/index.rs b/milli/src/index.rs index 0a4548b29..356cdd77f 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1864,7 +1864,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); + let mut search = index.search(&rtxn, &index.to_string()); // exact match a document let search_result = search diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index 0bbfd2cc0..f30e9084a 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -70,7 +70,7 @@ impl<'a> Search<'a> { searchable_attributes: None, geo_strategy: new::GeoSortStrategy::default(), terms_matching_strategy: TermsMatchingStrategy::default(), - scoring_strategy: Default::default(), + scori ng_strategy: Default::default(), exhaustive_number_hits: false, words_limit: 10, rtxn, diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 36aa94964..1306316c6 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -1033,15 +1033,15 @@ mod tests { let rtxn = index.read_txn().unwrap(); // Search for a sub object value - let result = index.search(&rtxn).query(r#""value2""#).execute().unwrap(); + let result = index.search(&rtxn, &String::from("test_index")).query(r#""value2""#).execute().unwrap(); assert_eq!(result.documents_ids, vec![0]); // Search for a sub array value - let result = index.search(&rtxn).query(r#""fine""#).execute().unwrap(); + let result = index.search(&rtxn, &String::from("test_index")).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).query(r#""amazing""#).execute().unwrap(); + let result = index.search(&rtxn, &String::from("test_index")).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); + let mut search = crate::Search::new(&rtxn, &index, &String::from("test_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); + let mut search = crate::Search::new(&rtxn, &index, &String::from("test_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); + let mut search = crate::Search::new(&rtxn, &index, &String::from("test_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); + let mut search = crate::Search::new(&rtxn, &index, &String::from("test_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); + let mut search = crate::Search::new(&rtxn, &index, &String::from("test_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).vector([0.0, 1.0, 2.0].to_vec()).execute().unwrap(); + let res = index.search(&rtxn, &String::from("test_index")).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).execute().unwrap(); + let res = index.search(&rtxn, &String::from("test_index")).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).filter(filter).execute().unwrap(); + let results = index.search(&wtxn, &String::from("test_index")).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).execute().unwrap(); + let results = index.search(&wtxn, &String::from("test_index")).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).query("abstract").execute().unwrap(); + let results = index.search(&wtxn, &String::from("test_index")).query("abstract").execute().unwrap(); assert!(!results.documents_ids.is_empty()); for id in results.documents_ids.iter() { assert!( @@ -3075,9 +3075,10 @@ 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).filter(filter).execute().unwrap(); + let results = index.search(&wtxn, &index_uid).filter(filter).execute().unwrap(); assert!(!results.documents_ids.is_empty()); for id in results.documents_ids.iter() { assert!( @@ -3302,7 +3303,8 @@ mod tests { let words = index.words_fst(&txn).unwrap().into_stream().into_strs().unwrap(); insta::assert_snapshot!(format!("{words:?}"), @r###"["hello"]"###); - let mut s = Search::new(&txn, &index); + let index_uid = String::from("test_index"); + let mut s = Search::new(&txn, &index, &index_uid); s.query("hello"); let crate::SearchResult { documents_ids, .. } = s.execute().unwrap(); insta::assert_snapshot!(format!("{documents_ids:?}"), @"[0]"); diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 3cad79467..264638077 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -1215,6 +1215,7 @@ 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(); @@ -1243,12 +1244,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).query("23").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).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).query(r#""kevin""#).execute().unwrap(); + let result = index.search(&rtxn, &index_uid).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""#[..])); @@ -1265,7 +1266,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).query("23").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).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""#[..])); @@ -1468,7 +1469,8 @@ mod tests { // Run an empty query just to ensure that the search results are ordered. let rtxn = index.read_txn().unwrap(); - let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap(); + let index_uid = String::from("test_index"); + let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap(); let documents = index.documents(&rtxn, documents_ids).unwrap(); // Fetch the documents "age" field in the ordre in which the documents appear. @@ -1511,7 +1513,8 @@ mod tests { // Run an empty query just to ensure that the search results are ordered. let rtxn = index.read_txn().unwrap(); - let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap(); + let index_uid = String::from("test_index"); + let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap(); // There must be at least one document with a 34 as the age. assert_eq!(documents_ids.len(), 3); @@ -1546,7 +1549,8 @@ mod tests { // Run an empty query just to ensure that the search results are ordered. let rtxn = index.read_txn().unwrap(); - let SearchResult { documents_ids, .. } = index.search(&rtxn).execute().unwrap(); + let index_uid = String::from("test_index"); + let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).execute().unwrap(); // There must be at least one document with a 34 as the age. assert_eq!(documents_ids.len(), 3); @@ -1609,18 +1613,19 @@ 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).query("the ").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("the ").execute().unwrap(); assert_eq!(result.documents_ids.len(), 3); - let result = index.search(&rtxn).query("i ").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("i ").execute().unwrap(); assert_eq!(result.documents_ids.len(), 3); - let result = index.search(&rtxn).query("are ").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("are ").execute().unwrap(); assert_eq!(result.documents_ids.len(), 3); - let result = index.search(&rtxn).query("dog").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("dog").execute().unwrap(); assert_eq!(result.documents_ids.len(), 2); // we have two maxims talking about doggos - let result = index.search(&rtxn).query("benoît").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).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 @@ -1635,17 +1640,17 @@ mod tests { assert!(stop_words.is_none()); // now we can search for the stop words - let result = index.search(&rtxn).query("the").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("the").execute().unwrap(); assert_eq!(result.documents_ids.len(), 2); - let result = index.search(&rtxn).query("i").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("i").execute().unwrap(); assert_eq!(result.documents_ids.len(), 1); - let result = index.search(&rtxn).query("are").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).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).query("dog").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("dog").execute().unwrap(); assert_eq!(result.documents_ids.len(), 2); // we have two maxims talking about doggos - let result = index.search(&rtxn).query("benoît").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("benoît").execute().unwrap(); assert_eq!(result.documents_ids.len(), 1); // there is one benoit in our data } @@ -1684,12 +1689,13 @@ 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).query("blini").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("blini").execute().unwrap(); assert_eq!(result.documents_ids.len(), 1); - let result = index.search(&rtxn).query("super like").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("super like").execute().unwrap(); assert_eq!(result.documents_ids.len(), 1); - let result = index.search(&rtxn).query("puppies").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("puppies").execute().unwrap(); assert_eq!(result.documents_ids.len(), 2); // Reset the synonyms @@ -1705,11 +1711,11 @@ mod tests { assert!(synonyms.is_empty()); // Check that synonyms are no longer work - let result = index.search(&rtxn).query("blini").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("blini").execute().unwrap(); assert!(result.documents_ids.is_empty()); - let result = index.search(&rtxn).query("super like").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("super like").execute().unwrap(); assert!(result.documents_ids.is_empty()); - let result = index.search(&rtxn).query("puppies").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("puppies").execute().unwrap(); assert!(result.documents_ids.is_empty()); } @@ -1746,7 +1752,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).query("japanese").execute().unwrap(); + let result = index.search(&rtxn, &index_uid).query("japanese").execute().unwrap(); assert_eq!(result.documents_ids.len(), 2); } @@ -1899,8 +1905,9 @@ mod tests { } ])).unwrap(); + let index_uid = String::from("temp"); let rtxn = index.read_txn().unwrap(); - let SearchResult { documents_ids, .. } = index.search(&rtxn).query("S").execute().unwrap(); + let SearchResult { documents_ids, .. } = index.search(&rtxn, &index_uid).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(); From a082f14c69e890705f5212bd06844c89ad2ef251 Mon Sep 17 00:00:00 2001 From: Francesco Allara Date: Tue, 13 Feb 2024 21:33:09 +0100 Subject: [PATCH 04/10] Fix tests --- fuzzers/src/bin/fuzz-indexing.rs | 2 +- index-scheduler/src/index_mapper/index_map.rs | 10 ++-- index-scheduler/src/index_mapper/mod.rs | 2 + .../src/routes/indexes/facet_search.rs | 13 +---- meilisearch/src/routes/indexes/search.rs | 14 ++--- meilisearch/src/routes/multi_search.rs | 6 +- meilisearch/src/search.rs | 12 ++-- meilisearch/tests/search/errors.rs | 2 +- meilitool/src/main.rs | 2 +- milli/examples/index.rs | 2 +- milli/examples/search.rs | 2 +- milli/examples/settings.rs | 2 +- milli/src/error.rs | 2 +- milli/src/index.rs | 19 ++++--- milli/src/search/hybrid.rs | 1 - milli/src/search/mod.rs | 12 ++-- milli/src/search/new/mod.rs | 8 +-- milli/src/search/new/tests/integration.rs | 2 +- milli/src/update/clear_documents.rs | 1 + milli/src/update/index_documents/mod.rs | 32 +++++------ milli/src/update/settings.rs | 55 ++++++++----------- milli/tests/search/facet_distribution.rs | 2 +- milli/tests/search/mod.rs | 2 +- milli/tests/search/query_criteria.rs | 2 +- milli/tests/search/typo_tolerance.rs | 2 +- 25 files changed, 94 insertions(+), 115 deletions(-) diff --git a/fuzzers/src/bin/fuzz-indexing.rs b/fuzzers/src/bin/fuzz-indexing.rs index baf705709..64081aba9 100644 --- a/fuzzers/src/bin/fuzz-indexing.rs +++ b/fuzzers/src/bin/fuzz-indexing.rs @@ -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(); diff --git a/index-scheduler/src/index_mapper/index_map.rs b/index-scheduler/src/index_mapper/index_map.rs index f8080d23b..b4d2204d7 100644 --- a/index-scheduler/src/index_mapper/index_map.rs +++ b/index-scheduler/src/index_mapper/index_map.rs @@ -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)?) } } diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 14908120c..34e037266 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -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, diff --git a/meilisearch/src/routes/indexes/facet_search.rs b/meilisearch/src/routes/indexes/facet_search.rs index 23c09def0..a980fb278 100644 --- a/meilisearch/src/routes/indexes/facet_search.rs +++ b/meilisearch/src/routes/indexes/facet_search.rs @@ -53,8 +53,8 @@ pub async fn search( req: HttpRequest, analytics: web::Data, ) -> Result { - 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?; diff --git a/meilisearch/src/routes/indexes/search.rs b/meilisearch/src/routes/indexes/search.rs index 8152869a9..3adfce970 100644 --- a/meilisearch/src/routes/indexes/search.rs +++ b/meilisearch/src/routes/indexes/search.rs @@ -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); } diff --git a/meilisearch/src/routes/multi_search.rs b/meilisearch/src/routes/multi_search.rs index b074cf39d..86aa58e70 100644 --- a/meilisearch/src/routes/multi_search.rs +++ b/meilisearch/src/routes/multi_search.rs @@ -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)?, }); } diff --git a/meilisearch/src/search.rs b/meilisearch/src/search.rs index 43f05fff2..27de36c6d 100644 --- a/meilisearch/src/search.rs +++ b/meilisearch/src/search.rs @@ -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, ) -> 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, @@ -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, facet_name: String, @@ -728,8 +724,8 @@ pub fn perform_facet_search( ) -> Result { 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 { diff --git a/meilisearch/tests/search/errors.rs b/meilisearch/tests/search/errors.rs index 8be70d162..697156450 100644 --- a/meilisearch/tests/search/errors.rs +++ b/meilisearch/tests/search/errors.rs @@ -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" diff --git a/meilitool/src/main.rs b/meilitool/src/main.rs index f199df216..4af5107ff 100644 --- a/meilitool/src/main.rs +++ b/meilitool/src/main.rs @@ -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()) })?; diff --git a/milli/examples/index.rs b/milli/examples/index.rs index 781440b56..14eb45cf4 100644 --- a/milli/examples/index.rs +++ b/milli/examples/index.rs @@ -41,7 +41,7 @@ fn main() -> Result<(), Box> { 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(); diff --git a/milli/examples/search.rs b/milli/examples/search.rs index a94677771..5c9fe5f07 100644 --- a/milli/examples/search.rs +++ b/milli/examples/search.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), Box> { 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 { diff --git a/milli/examples/settings.rs b/milli/examples/settings.rs index c7f4780cb..bcf50058f 100644 --- a/milli/examples/settings.rs +++ b/milli/examples/settings.rs @@ -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(); diff --git a/milli/src/error.rs b/milli/src/error.rs index 5926e1814..d13fee75c 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -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, }; diff --git a/milli/src/index.rs b/milli/src/index.rs index 356cdd77f..4c148b28d 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -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>( + 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>(options: heed::EnvOpenOptions, path: P) -> Result { + pub fn new>(name: &str, options: heed::EnvOpenOptions, path: P) -> Result { 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 diff --git a/milli/src/search/hybrid.rs b/milli/src/search/hybrid.rs index 3dab9b272..b4c79f7f5 100644 --- a/milli/src/search/hybrid.rs +++ b/milli/src/search/hybrid.rs @@ -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(), diff --git a/milli/src/search/mod.rs b/milli/src/search/mod.rs index f30e9084a..e411bd032 100644 --- a/milli/src/search/mod.rs +++ b/milli/src/search/mod.rs @@ -36,7 +36,6 @@ pub mod hybrid; pub mod new; pub struct Search<'a> { - index_uid: &'a String, query: Option, vector: Option>, // 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 { 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) diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index e0405ec6b..3c7ece03a 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -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, @@ -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> 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> return Err(UserError::InvalidSortableAttribute { field: "_geo".to_string(), - index: ctx.index_uid.clone(), + index: ctx.index.name.clone(), valid_fields, hidden_fields, } diff --git a/milli/src/search/new/tests/integration.rs b/milli/src/search/new/tests/integration.rs index e2ea4580e..54cbd29fd 100644 --- a/milli/src/search/new/tests/integration.rs +++ b/milli/src/search/new/tests/integration.rs @@ -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(); diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index 6715939dc..a6024af9b 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -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, diff --git a/milli/src/update/index_documents/mod.rs b/milli/src/update/index_documents/mod.rs index 1306316c6..36aa94964 100644 --- a/milli/src/update/index_documents/mod.rs +++ b/milli/src/update/index_documents/mod.rs @@ -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]"); diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 264638077..3cad79467 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -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(); diff --git a/milli/tests/search/facet_distribution.rs b/milli/tests/search/facet_distribution.rs index 03405531d..02da34283 100644 --- a/milli/tests/search/facet_distribution.rs +++ b/milli/tests/search/facet_distribution.rs @@ -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(); diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index 9193ab762..71fbbea76 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -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(); diff --git a/milli/tests/search/query_criteria.rs b/milli/tests/search/query_criteria.rs index 65d403097..8b882b356 100644 --- a/milli/tests/search/query_criteria.rs +++ b/milli/tests/search/query_criteria.rs @@ -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(); diff --git a/milli/tests/search/typo_tolerance.rs b/milli/tests/search/typo_tolerance.rs index 863d2758a..3e5d9dc9f 100644 --- a/milli/tests/search/typo_tolerance.rs +++ b/milli/tests/search/typo_tolerance.rs @@ -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!({ From 9a058e96ee95a7fb17ed7e09b5f7c9fc6a62a185 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 14 Feb 2024 11:17:53 +0100 Subject: [PATCH 05/10] Make the index name optional --- index-scheduler/src/index_mapper/index_map.rs | 14 ++++++++++---- milli/src/error.rs | 14 +++++++++++--- milli/src/index.rs | 16 ++++++++++------ milli/src/search/new/mod.rs | 4 ++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/index-scheduler/src/index_mapper/index_map.rs b/index-scheduler/src/index_mapper/index_map.rs index b4d2204d7..6be82e147 100644 --- a/index-scheduler/src/index_mapper/index_map.rs +++ b/index-scheduler/src/index_mapper/index_map.rs @@ -167,7 +167,7 @@ impl IndexMap { /// pub fn create( &mut self, - name: &str, + name: &str, uuid: &Uuid, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, @@ -297,7 +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, + name: &str, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, enable_mdb_writemap: bool, @@ -311,9 +311,15 @@ fn create_or_open_index( } if let Some((created, updated)) = date { - Ok(Index::new_with_creation_dates(name, options, path, created, updated)?) + Ok(Index::new_with_creation_dates( + Some(String::from(name)), + options, + path, + created, + updated, + )?) } else { - Ok(Index::new(name, options, path)?) + Ok(Index::new(Some(String::from(name)), options, path)?) } } diff --git a/milli/src/error.rs b/milli/src/error.rs index d13fee75c..1aca14d51 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -122,9 +122,12 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco InvalidFilter(String), #[error("Invalid type for filter subexpression: expected: {}, found: {1}.", .0.join(", "))] InvalidFilterExpression(&'static [&'static str], Value), - #[error("Attribute `{}` of index `{}` is not sortable. {}", + #[error("Attribute `{}`{} is not sortable. {}", .field, - .index, + match .index_name.is_some() { + true => format!(" of index `{}`", index_name.clone().unwrap()), + false => String::from(""), + }, match .valid_fields.is_empty() { true => "This index does not have configured sortable attributes.".to_string(), false => format!("Available sortable attributes are: `{}{}`.", @@ -133,7 +136,12 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco ), } )] - InvalidSortableAttribute { field: String, index: String, valid_fields: BTreeSet, hidden_fields: bool }, + InvalidSortableAttribute { + field: String, + index_name: Option, + valid_fields: BTreeSet, + hidden_fields: bool, + }, #[error("Attribute `{}` is not facet-searchable. {}", .field, match .valid_fields.is_empty() { diff --git a/milli/src/index.rs b/milli/src/index.rs index 4c148b28d..ad78f3946 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -100,7 +100,7 @@ pub mod db_name { #[derive(Clone)] pub struct Index { - pub name: String, + pub name: Option, /// The LMDB environment which this index is associated with. pub(crate) env: heed::Env, @@ -173,7 +173,7 @@ pub struct Index { impl Index { pub fn new_with_creation_dates>( - name: &str, + name: Option, mut options: heed::EnvOpenOptions, path: P, created_at: OffsetDateTime, @@ -183,8 +183,8 @@ impl Index { options.max_dbs(25); - let name = String::from(name); - let env = options.open(path)?; + let name = 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))?; @@ -233,7 +233,7 @@ impl Index { Index::set_creation_dates(&env, main, created_at, updated_at)?; Ok(Index { - name, + name, env, main, external_documents_ids, @@ -263,7 +263,11 @@ impl Index { }) } - pub fn new>(name: &str, options: heed::EnvOpenOptions, path: P) -> Result { + pub fn new>( + name: Option, + options: heed::EnvOpenOptions, + path: P, + ) -> Result { let now = OffsetDateTime::now_utc(); Self::new_with_creation_dates(name, options, path, now, now) } diff --git a/milli/src/search/new/mod.rs b/milli/src/search/new/mod.rs index 3c7ece03a..18e67913e 100644 --- a/milli/src/search/new/mod.rs +++ b/milli/src/search/new/mod.rs @@ -706,7 +706,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: field.to_string(), - index: ctx.index.name.clone(), + index_name: ctx.index.name.clone(), valid_fields, hidden_fields, } @@ -718,7 +718,7 @@ fn check_sort_criteria(ctx: &SearchContext, sort_criteria: Option<&Vec> return Err(UserError::InvalidSortableAttribute { field: "_geo".to_string(), - index: ctx.index.name.clone(), + index_name: ctx.index.name.clone(), valid_fields, hidden_fields, } From b1bc50580735d5d51f4be43fc12a6cf901beeb5e Mon Sep 17 00:00:00 2001 From: Francesco Allara Date: Wed, 14 Feb 2024 11:49:27 +0100 Subject: [PATCH 06/10] Add index name to unsortable columns error message --- fuzzers/src/bin/fuzz-indexing.rs | 2 +- index-scheduler/src/index_mapper/index_map.rs | 10 +++++----- index-scheduler/src/index_mapper/mod.rs | 4 ++-- meilitool/src/main.rs | 2 +- milli/examples/index.rs | 2 +- milli/examples/search.rs | 2 +- milli/examples/settings.rs | 2 +- milli/src/error.rs | 2 +- milli/src/index.rs | 2 +- milli/src/search/new/tests/integration.rs | 2 +- milli/tests/search/facet_distribution.rs | 2 +- milli/tests/search/mod.rs | 2 +- milli/tests/search/query_criteria.rs | 2 +- milli/tests/search/typo_tolerance.rs | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/fuzzers/src/bin/fuzz-indexing.rs b/fuzzers/src/bin/fuzz-indexing.rs index 64081aba9..608933016 100644 --- a/fuzzers/src/bin/fuzz-indexing.rs +++ b/fuzzers/src/bin/fuzz-indexing.rs @@ -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(None, options, tempdir.path()).unwrap(); let indexer_config = IndexerConfig::default(); let index_documents_config = IndexDocumentsConfig::default(); diff --git a/index-scheduler/src/index_mapper/index_map.rs b/index-scheduler/src/index_mapper/index_map.rs index 6be82e147..cf8288461 100644 --- a/index-scheduler/src/index_mapper/index_map.rs +++ b/index-scheduler/src/index_mapper/index_map.rs @@ -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(None, &self.uuid, path, None, self.enable_mdb_writemap, self.map_size)?; } Ok(()) } @@ -167,7 +167,7 @@ impl IndexMap { /// pub fn create( &mut self, - name: &str, + name: Option, uuid: &Uuid, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, @@ -297,7 +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, + name: Option, path: &Path, date: Option<(OffsetDateTime, OffsetDateTime)>, enable_mdb_writemap: bool, @@ -312,14 +312,14 @@ fn create_or_open_index( if let Some((created, updated)) = date { Ok(Index::new_with_creation_dates( - Some(String::from(name)), + name, options, path, created, updated, )?) } else { - Ok(Index::new(Some(String::from(name)), options, path)?) + Ok(Index::new(name, options, path)?) } } diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 34e037266..95ddd4145 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -182,7 +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, + Some(name.to_string()), &uuid, &index_path, date, @@ -372,7 +372,7 @@ impl IndexMapper { let index_path = self.base_path.join(uuid.to_string()); break index_map.create( - name, + Some(name.to_string()), &uuid, &index_path, None, diff --git a/meilitool/src/main.rs b/meilitool/src/main.rs index 4af5107ff..1cbab32c5 100644 --- a/meilitool/src/main.rs +++ b/meilitool/src/main.rs @@ -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(None, EnvOpenOptions::new(), &index_path).with_context(|| { format!("While trying to open the index at path {:?}", index_path.display()) })?; diff --git a/milli/examples/index.rs b/milli/examples/index.rs index 14eb45cf4..466c0a853 100644 --- a/milli/examples/index.rs +++ b/milli/examples/index.rs @@ -41,7 +41,7 @@ fn main() -> Result<(), Box> { options.map_size(100 * 1024 * 1024 * 1024); // 100 GB std::fs::create_dir_all(&index_path).unwrap(); - let index = Index::new(program_name.as_str(), options, index_path).unwrap(); + let index = Index::new(Some(program_name), options, index_path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/examples/search.rs b/milli/examples/search.rs index 5c9fe5f07..1b31b8bf5 100644 --- a/milli/examples/search.rs +++ b/milli/examples/search.rs @@ -28,7 +28,7 @@ fn main() -> Result<(), Box> { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB - let index = Index::new(program_name.as_str(), options, dataset)?; + let index = Index::new(Some(program_name), options, dataset)?; let txn = index.read_txn()?; let mut query = String::new(); while stdin().read_line(&mut query)? > 0 { diff --git a/milli/examples/settings.rs b/milli/examples/settings.rs index bcf50058f..846e3b070 100644 --- a/milli/examples/settings.rs +++ b/milli/examples/settings.rs @@ -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(None, options, "data_movies.ms").unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/src/error.rs b/milli/src/error.rs index 1aca14d51..6326f696d 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -469,7 +469,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_name: Some("index".to_string()), valid_fields: list, hidden_fields: false, }; diff --git a/milli/src/index.rs b/milli/src/index.rs index ad78f3946..b000cde27 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -1557,7 +1557,7 @@ pub(crate) mod tests { let mut options = EnvOpenOptions::new(); options.map_size(size); let _tempdir = TempDir::new_in(".").unwrap(); - let inner = Index::new("temp", options, _tempdir.path()).unwrap(); + let inner = Index::new(Some("temp".to_string()), options, _tempdir.path()).unwrap(); let indexer_config = IndexerConfig::default(); let index_documents_config = IndexDocumentsConfig::default(); Self { inner, indexer_config, index_documents_config, _tempdir } diff --git a/milli/src/search/new/tests/integration.rs b/milli/src/search/new/tests/integration.rs index 54cbd29fd..a60821b19 100644 --- a/milli/src/search/new/tests/integration.rs +++ b/milli/src/search/new/tests/integration.rs @@ -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(Some("".to_string()), options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/facet_distribution.rs b/milli/tests/search/facet_distribution.rs index 02da34283..55bc78fb2 100644 --- a/milli/tests/search/facet_distribution.rs +++ b/milli/tests/search/facet_distribution.rs @@ -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(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/mod.rs b/milli/tests/search/mod.rs index 71fbbea76..3ecbe6d67 100644 --- a/milli/tests/search/mod.rs +++ b/milli/tests/search/mod.rs @@ -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(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/query_criteria.rs b/milli/tests/search/query_criteria.rs index 8b882b356..35c18426d 100644 --- a/milli/tests/search/query_criteria.rs +++ b/milli/tests/search/query_criteria.rs @@ -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(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); diff --git a/milli/tests/search/typo_tolerance.rs b/milli/tests/search/typo_tolerance.rs index 3e5d9dc9f..83024fb2f 100644 --- a/milli/tests/search/typo_tolerance.rs +++ b/milli/tests/search/typo_tolerance.rs @@ -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(None, options, tmp.path()).unwrap(); let mut builder = milli::documents::DocumentsBatchBuilder::new(Vec::new()); let doc1 = json!({ From f9cf0d06ec74e30f2d556233ace5a8064ddb58e6 Mon Sep 17 00:00:00 2001 From: Francesco Allara Date: Wed, 14 Feb 2024 11:53:37 +0100 Subject: [PATCH 07/10] Use none when there is no name available --- milli/src/search/new/tests/integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/milli/src/search/new/tests/integration.rs b/milli/src/search/new/tests/integration.rs index a60821b19..48e71f286 100644 --- a/milli/src/search/new/tests/integration.rs +++ b/milli/src/search/new/tests/integration.rs @@ -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(Some("".to_string()), options, &path).unwrap(); + let index = Index::new(None, options, &path).unwrap(); let mut wtxn = index.write_txn().unwrap(); let config = IndexerConfig::default(); From 8a7f8916c081e84978a4a31cf06a8397d4c984cd Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 14 Feb 2024 12:12:18 +0100 Subject: [PATCH 08/10] Fix clippy and rustfmt --- index-scheduler/src/index_mapper/mod.rs | 4 ++-- milli/src/index.rs | 1 - milli/src/update/clear_documents.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/index-scheduler/src/index_mapper/mod.rs b/index-scheduler/src/index_mapper/mod.rs index 95ddd4145..245de8363 100644 --- a/index-scheduler/src/index_mapper/mod.rs +++ b/index-scheduler/src/index_mapper/mod.rs @@ -182,7 +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( - Some(name.to_string()), + Some(name.to_string()), &uuid, &index_path, date, @@ -372,7 +372,7 @@ impl IndexMapper { let index_path = self.base_path.join(uuid.to_string()); break index_map.create( - Some(name.to_string()), + Some(name.to_string()), &uuid, &index_path, None, diff --git a/milli/src/index.rs b/milli/src/index.rs index b000cde27..12206ff5a 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -183,7 +183,6 @@ impl Index { options.max_dbs(25); - let name = name; let env = options.open(path)?; let mut wtxn = env.write_txn()?; let main = env.database_options().name(MAIN).create(&mut wtxn)?; diff --git a/milli/src/update/clear_documents.rs b/milli/src/update/clear_documents.rs index a6024af9b..a1cfbd70a 100644 --- a/milli/src/update/clear_documents.rs +++ b/milli/src/update/clear_documents.rs @@ -25,7 +25,7 @@ impl<'t, 'i> ClearDocuments<'t, 'i> { self.index.set_updated_at(self.wtxn, &OffsetDateTime::now_utc())?; let Index { - name: _name, + name: _name, env: _env, main: _main, external_documents_ids, From 5d82155060e725a041d81ab02e9335de7ef953c0 Mon Sep 17 00:00:00 2001 From: Francesco Date: Wed, 14 Feb 2024 13:29:57 +0100 Subject: [PATCH 09/10] Fix clippy and fmt issues --- benchmarks/benches/indexing.rs | 2 +- benchmarks/benches/utils.rs | 2 +- index-scheduler/src/index_mapper/index_map.rs | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/benchmarks/benches/indexing.rs b/benchmarks/benches/indexing.rs index 0c19b89cf..bebf11ba0 100644 --- a/benchmarks/benches/indexing.rs +++ b/benchmarks/benches/indexing.rs @@ -32,7 +32,7 @@ fn setup_index() -> Index { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.max_readers(10); - Index::new(options, path).unwrap() + Index::new(None, options, path).unwrap() } fn setup_settings<'t>( diff --git a/benchmarks/benches/utils.rs b/benchmarks/benches/utils.rs index b848560ad..ab52a9a6a 100644 --- a/benchmarks/benches/utils.rs +++ b/benchmarks/benches/utils.rs @@ -66,7 +66,7 @@ pub fn base_setup(conf: &Conf) -> Index { let mut options = EnvOpenOptions::new(); options.map_size(100 * 1024 * 1024 * 1024); // 100 GB options.max_readers(10); - let index = Index::new(options, conf.database_name).unwrap(); + let index = Index::new(None, options, conf.database_name).unwrap(); let config = IndexerConfig::default(); let mut wtxn = index.write_txn().unwrap(); diff --git a/index-scheduler/src/index_mapper/index_map.rs b/index-scheduler/src/index_mapper/index_map.rs index cf8288461..c3873e465 100644 --- a/index-scheduler/src/index_mapper/index_map.rs +++ b/index-scheduler/src/index_mapper/index_map.rs @@ -311,13 +311,7 @@ fn create_or_open_index( } if let Some((created, updated)) = date { - Ok(Index::new_with_creation_dates( - name, - options, - path, - created, - updated, - )?) + Ok(Index::new_with_creation_dates(name, options, path, created, updated)?) } else { Ok(Index::new(name, options, path)?) } From e6b7031988bb9f78fe82a88e48b57c1f0b69d9b9 Mon Sep 17 00:00:00 2001 From: Francesco Date: Thu, 29 Feb 2024 01:26:10 +0100 Subject: [PATCH 10/10] Merge --- index-scheduler/src/lib.rs | 3 +++ milli/src/index.rs | 12 ++---------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 7514a2a68..9989a4060 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -277,6 +277,9 @@ pub struct IndexSchedulerOptions { /// Structure which holds meilisearch's indexes and schedules the tasks /// to be performed on them. pub struct IndexScheduler { + /// A String representing the name of the index + pub(crate) name: String, + /// The LMDB environment which the DBs are associated with. pub(crate) env: Env, diff --git a/milli/src/index.rs b/milli/src/index.rs index 12206ff5a..6df7ea748 100644 --- a/milli/src/index.rs +++ b/milli/src/index.rs @@ -100,8 +100,6 @@ pub mod db_name { #[derive(Clone)] pub struct Index { - pub name: Option, - /// The LMDB environment which this index is associated with. pub(crate) env: heed::Env, @@ -173,7 +171,6 @@ pub struct Index { impl Index { pub fn new_with_creation_dates>( - name: Option, mut options: heed::EnvOpenOptions, path: P, created_at: OffsetDateTime, @@ -232,7 +229,6 @@ impl Index { Index::set_creation_dates(&env, main, created_at, updated_at)?; Ok(Index { - name, env, main, external_documents_ids, @@ -262,13 +258,9 @@ impl Index { }) } - pub fn new>( - name: Option, - options: heed::EnvOpenOptions, - path: P, - ) -> Result { + pub fn new>(options: heed::EnvOpenOptions, path: P) -> Result { let now = OffsetDateTime::now_utc(); - Self::new_with_creation_dates(name, options, path, now, now) + Self::new_with_creation_dates(options, path, now, now) } fn set_creation_dates(