summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authormdecimus <mauro@stalw.art>2024-08-22 12:33:23 +0200
committermdecimus <mauro@stalw.art>2024-08-22 12:33:23 +0200
commitfe0ccb11bd3192c224615fe09efe47d04c29cfe9 (patch)
tree66d173f7098043561c9ed772cb836ba23025a3db /crates
parentbd4129e160f93b29b3e83abb92a0bb0540b4a331 (diff)
Do not insert empty keywords in FTS index
Diffstat (limited to 'crates')
-rw-r--r--crates/store/src/fts/index.rs30
-rw-r--r--crates/store/src/write/key.rs2
2 files changed, 21 insertions, 11 deletions
diff --git a/crates/store/src/fts/index.rs b/crates/store/src/fts/index.rs
index 4b0c6c63..6795a80a 100644
--- a/crates/store/src/fts/index.rs
+++ b/crates/store/src/fts/index.rs
@@ -95,11 +95,14 @@ impl<'x, T: Into<u8> + Display + Clone + std::fmt::Debug> FtsDocument<'x, T> {
}
pub fn index_keyword(&mut self, field: Field<T>, text: impl Into<Cow<'x, str>>) {
- self.parts.push(Text {
- field,
- text: text.into(),
- typ: Type::Keyword,
- });
+ let text = text.into();
+ if !text.is_empty() {
+ self.parts.push(Text {
+ field,
+ text,
+ typ: Type::Keyword,
+ });
+ }
}
}
@@ -146,11 +149,14 @@ impl Store {
position += 10;
}
Type::Keyword => {
- let field = u8::from(text.field);
- tokens
- .entry(BitmapHash::new(text.text.as_ref()))
- .or_default()
- .insert_keyword(TokenType::word(field));
+ let value = text.text.as_ref();
+ if !value.is_empty() {
+ let field = u8::from(text.field);
+ tokens
+ .entry(BitmapHash::new(value))
+ .or_default()
+ .insert_keyword(TokenType::word(field));
+ }
}
}
}
@@ -268,6 +274,10 @@ impl Store {
hash[..len].copy_from_slice(&key[U32_LEN..U32_LEN + len]);
(hash, len as u8)
}
+ 0 => {
+ // Temporary fix for empty keywords
+ (hash, 0)
+ }
invalid => {
return Err(trc::Error::corrupted_key(key, None, trc::location!())
.ctx(trc::Key::Reason, "Invalid bitmap key length")
diff --git a/crates/store/src/write/key.rs b/crates/store/src/write/key.rs
index d045d987..86649255 100644
--- a/crates/store/src/write/key.rs
+++ b/crates/store/src/write/key.rs
@@ -250,7 +250,7 @@ impl<T: ResolveId> ValueClass<T> {
let serializer = serializer.write(account_id).write(
hash.hash
.get(0..std::cmp::min(hash.len as usize, 8))
- .unwrap(),
+ .unwrap_or_default(),
);
if hash.len >= 8 {