mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2024-11-10 09:32:19 +08:00
Do not insert empty keywords in FTS index
This commit is contained in:
parent
bd4129e160
commit
fe0ccb11bd
2 changed files with 21 additions and 11 deletions
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue