aboutsummaryrefslogtreecommitdiff
path: root/database/src
diff options
context:
space:
mode:
Diffstat (limited to 'database/src')
-rw-r--r--database/src/kv/index.rs10
-rw-r--r--database/src/kv/index_key.rs29
-rw-r--r--database/src/lib.rs2
-rw-r--r--database/src/query_syntax.rs16
4 files changed, 43 insertions, 14 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)])]),
));
}
}
diff --git a/database/src/lib.rs b/database/src/lib.rs
index b315fa6..465cb87 100644
--- a/database/src/lib.rs
+++ b/database/src/lib.rs
@@ -47,7 +47,7 @@ pub enum Sort {
None,
Random(u64),
Value(ValueSort),
- TextSearch(Path, String),
+ TextSearch(Vec<Path>, String),
}
#[derive(Debug, Clone, PartialEq)]
diff --git a/database/src/query_syntax.rs b/database/src/query_syntax.rs
index 9efc3d5..4b08307 100644
--- a/database/src/query_syntax.rs
+++ b/database/src/query_syntax.rs
@@ -76,7 +76,14 @@ impl Display for Sort {
)
}
Sort::TextSearch(path, value) => {
- write!(f, "TEXT SEARCH {path} = {value:?}")
+ write!(
+ f,
+ "TEXT SEARCH {} = {value:?}",
+ path.iter()
+ .map(|p| p.to_string())
+ .collect::<Vec<_>>()
+ .join(",")
+ )
}
}
}
@@ -144,10 +151,13 @@ impl FromStr for Sort {
} else if s == "RANDOM" {
Sort::Random(1)
} else if let Some(s) = s.strip_prefix("TEXT SEARCH ")
- && let Some((path, value)) = s.split_once(" = ")
+ && let Some((paths, value)) = s.split_once(" = ")
{
Sort::TextSearch(
- Path::from_str(path).map_err(|e| anyhow!("{e}"))?,
+ paths
+ .split(",")
+ .map(|p| Path::from_str(p).map_err(|e| anyhow!("{e}")))
+ .collect::<Result<Vec<_>, _>>()?,
value.to_owned(),
)
} else if let Some((order, rest)) = s.split_once(" BY ")