diff --git a/milli/examples/search.rs b/milli/examples/search.rs index c9a3c1438..030390822 100644 --- a/milli/examples/search.rs +++ b/milli/examples/search.rs @@ -50,7 +50,6 @@ fn main() -> Result<(), Box> { let docs = execute_search( &mut ctx, &(!query.trim().is_empty()).then(|| query.trim().to_owned()), - // what a the from which when there is TermsMatchingStrategy::Last, false, &None, diff --git a/milli/src/search/new/db_cache.rs b/milli/src/search/new/db_cache.rs index ad843b045..cf5332700 100644 --- a/milli/src/search/new/db_cache.rs +++ b/milli/src/search/new/db_cache.rs @@ -309,13 +309,14 @@ impl<'ctx> SearchContext<'ctx> { let fids = match self.db_cache.word_fids.entry(word) { Entry::Occupied(fids) => fids.get().clone(), Entry::Vacant(entry) => { - let key = self.word_interner.get(word).as_bytes(); + let mut key = self.word_interner.get(word).as_bytes().to_owned(); + key.push(0); let mut fids = vec![]; let remap_key_type = self .index .word_fid_docids .remap_types::() - .prefix_iter(self.txn, key)? + .prefix_iter(self.txn, &key)? .remap_key_type::(); for result in remap_key_type { let ((_, fid), value) = result?; @@ -334,13 +335,14 @@ impl<'ctx> SearchContext<'ctx> { let fids = match self.db_cache.word_prefix_fids.entry(word_prefix) { Entry::Occupied(fids) => fids.get().clone(), Entry::Vacant(entry) => { - let key = self.word_interner.get(word_prefix).as_bytes(); + let mut key = self.word_interner.get(word_prefix).as_bytes().to_owned(); + key.push(0); let mut fids = vec![]; let remap_key_type = self .index .word_prefix_fid_docids .remap_types::() - .prefix_iter(self.txn, key)? + .prefix_iter(self.txn, &key)? .remap_key_type::(); for result in remap_key_type { let ((_, fid), value) = result?; diff --git a/milli/src/search/new/logger/visual.rs b/milli/src/search/new/logger/visual.rs index 72e33f339..7834f7e46 100644 --- a/milli/src/search/new/logger/visual.rs +++ b/milli/src/search/new/logger/visual.rs @@ -11,8 +11,8 @@ use crate::search::new::interner::Interned; use crate::search::new::query_graph::QueryNodeData; use crate::search::new::query_term::LocatedQueryTermSubset; use crate::search::new::ranking_rule_graph::{ - Edge, ProximityCondition, ProximityGraph, RankingRuleGraph, RankingRuleGraphTrait, - TypoCondition, TypoGraph, + AttributeCondition, AttributeGraph, Edge, ProximityCondition, ProximityGraph, RankingRuleGraph, + RankingRuleGraphTrait, TypoCondition, TypoGraph, }; use crate::search::new::ranking_rules::BoxRankingRule; use crate::search::new::{QueryGraph, QueryNode, RankingRule, SearchContext, SearchLogger}; @@ -29,12 +29,15 @@ pub enum SearchEvents { ProximityPaths { paths: Vec>> }, TypoGraph { graph: RankingRuleGraph }, TypoPaths { paths: Vec>> }, + AttributeGraph { graph: RankingRuleGraph }, + AttributePaths { paths: Vec>> }, } enum Location { Words, Typo, Proximity, + Attribute, Other, } @@ -81,6 +84,7 @@ impl SearchLogger for VisualSearchLogger { "words" => Location::Words, "typo" => Location::Typo, "proximity" => Location::Proximity, + "attribute" => Location::Attribute, _ => Location::Other, }); } @@ -152,6 +156,15 @@ impl SearchLogger for VisualSearchLogger { self.events.push(SearchEvents::ProximityPaths { paths: paths.clone() }); } } + Location::Attribute => { + if let Some(graph) = state.downcast_ref::>() { + self.events.push(SearchEvents::AttributeGraph { graph: graph.clone() }); + } + if let Some(paths) = state.downcast_ref::>>>() + { + self.events.push(SearchEvents::AttributePaths { paths: paths.clone() }); + } + } Location::Other => {} } } @@ -314,6 +327,10 @@ impl<'ctx> DetailedLoggerFinish<'ctx> { SearchEvents::TypoPaths { paths } => { self.write_rr_graph_paths::(paths)?; } + SearchEvents::AttributeGraph { graph } => self.write_rr_graph(&graph)?, + SearchEvents::AttributePaths { paths } => { + self.write_rr_graph_paths::(paths)?; + } } Ok(()) } diff --git a/milli/src/search/new/tests/attribute.rs b/milli/src/search/new/tests/attribute.rs index f9b29881b..b248f7953 100644 --- a/milli/src/search/new/tests/attribute.rs +++ b/milli/src/search/new/tests/attribute.rs @@ -1,9 +1,4 @@ -use std::collections::HashMap; - -use crate::{ - index::tests::TempIndex, search::new::tests::collect_field_values, Criterion, Search, - SearchResult, TermsMatchingStrategy, -}; +use crate::{index::tests::TempIndex, Criterion, Search, SearchResult, TermsMatchingStrategy}; fn create_index() -> TempIndex { let index = TempIndex::new(); @@ -24,21 +19,75 @@ fn create_index() -> TempIndex { .add_documents(documents!([ { "id": 0, - "title": "the quick brown fox jumps over the lazy dog", - "description": "Pack my box with five dozen liquor jugs", - "plot": "How vexingly quick daft zebras jump", + "title": "", + "description": "", + "plot": "the quick brown fox jumps over the lazy dog", }, { "id": 1, - "title": "Pack my box with five dozen liquor jugs", + "title": "", "description": "the quick brown foxes jump over the lazy dog", - "plot": "How vexingly quick daft zebras jump", + "plot": "", }, { "id": 2, - "title": "How vexingly quick daft zebras jump", - "description": "Pack my box with five dozen liquor jugs", - "plot": "the quick brown fox jumps over the lazy dog", + "title": "the quick brown fox jumps over the lazy dog", + "description": "", + "plot": "", + }, + { + "id": 3, + "title": "the", + "description": "quick brown fox jumps over the lazy dog", + "plot": "", + }, + { + "id": 4, + "title": "the quick", + "description": "brown fox jumps over the lazy dog", + "plot": "", + }, + { + "id": 5, + "title": "the quick brown", + "description": "fox jumps over the lazy dog", + "plot": "", + }, + { + "id": 6, + "title": "the quick brown fox", + "description": "jumps over the lazy dog", + "plot": "", + }, + { + "id": 7, + "title": "the quick", + "description": "brown fox jumps", + "plot": "over the lazy dog", + }, + { + "id": 8, + "title": "the quick brown", + "description": "fox", + "plot": "jumps over the lazy dog", + }, + { + "id": 9, + "title": "the quick brown", + "description": "fox jumps", + "plot": "over the lazy dog", + }, + { + "id": 10, + "title": "", + "description": "the quick brown fox", + "plot": "jumps over the lazy dog", + }, + { + "id": 11, + "title": "the quick", + "description": "", + "plot": "brown fox jumps over the lazy dog", } ])) .unwrap(); @@ -46,13 +95,14 @@ fn create_index() -> TempIndex { } #[test] -fn test_attributes_are_ranked_correctly() { +fn test_attributes_simple() { let index = create_index(); + let txn = index.read_txn().unwrap(); let mut s = Search::new(&txn, &index); s.terms_matching_strategy(TermsMatchingStrategy::All); - s.query("the quick brown fox"); + s.query("the quick brown fox jumps over the lazy dog"); let SearchResult { documents_ids, .. } = s.execute().unwrap(); - insta::assert_snapshot!(format!("{documents_ids:?}"), @"[0, 1, 2]"); + insta::assert_snapshot!(format!("{documents_ids:?}"), @"[2, 6, 5, 4, 3, 9, 7, 8, 11, 10, 0]"); }