diff options
Diffstat (limited to 'database/src/kv')
| -rw-r--r-- | database/src/kv/index.rs | 10 | ||||
| -rw-r--r-- | database/src/kv/index_key.rs | 29 |
2 files changed, 29 insertions, 10 deletions
diff --git a/database/src/kv/index.rs b/database/src/kv/index.rs index 591aeee..5ceab1c 100644 --- a/database/src/kv/index.rs +++ b/database/src/kv/index.rs @@ -59,11 +59,13 @@ pub fn update_index( } } } - SortKey::Text(path) => { + SortKey::Text(paths) => { let mut tokens = HashSet::new(); - for val in path.get_matching_values(ob) { - for tok in text_tokenizer(str::from_utf8(val).unwrap()) { - tokens.insert(tok); + for path in paths { + for val in path.get_matching_values(ob) { + for tok in text_tokenizer(str::from_utf8(val).unwrap()) { + tokens.insert(tok); + } } } for tok in &tokens { diff --git a/database/src/kv/index_key.rs b/database/src/kv/index_key.rs index ec8f183..ad51e02 100644 --- a/database/src/kv/index_key.rs +++ b/database/src/kv/index_key.rs @@ -23,7 +23,7 @@ pub enum SortKey { Count, Random, Value(Path, MultiBehaviour), - Text(Path), + Text(Vec<Path>), } impl Sort { @@ -106,7 +106,15 @@ impl SortKey { _ => unreachable!(), } }), - 3 => SortKey::Text(read_path(b)), + 3 => { + let num_paths = b[0]; + *b = &b[1..]; + let mut paths = Vec::new(); + for _ in 0..num_paths { + paths.push(read_path(b)); + } + SortKey::Text(paths) + } _ => unreachable!(), } } @@ -126,9 +134,12 @@ impl SortKey { MultiBehaviour::Count => 4, }); } - SortKey::Text(path) => { + SortKey::Text(paths) => { out.push(3); - write_path(path, out); + out.push(paths.len() as u8); + for path in paths { + write_path(path, out); + } } } } @@ -165,7 +176,13 @@ impl Display for SortKey { SortKey::Random => write!(f, "random"), SortKey::Count => write!(f, "count"), SortKey::Value(path, multi) => write!(f, "value({path}, {multi})"), - SortKey::Text(path) => write!(f, "text({path})"), + SortKey::Text(paths) => { + write!(f, "text(")?; + for p in paths { + write!(f, "{p} ")?; + } + write!(f, ")") + } } } } @@ -222,7 +239,7 @@ mod test { )); t(IndexKey( Binning(vec![BinningComponent::Has(Path(vec![Tag(123), Tag(456)]))]), - SortKey::Text(Path(vec![Tag(789)])), + SortKey::Text(vec![Path(vec![Tag(789)])]), )); } } |