mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-31 00:59:57 +08:00
feat: introduce fuzzy search for native indexer (#14109)
This commit is contained in:
@@ -254,6 +254,11 @@ impl Node {
|
||||
let mut ritem = unsafe { rref.get_mut_unchecked() };
|
||||
let llen = litem.len();
|
||||
|
||||
let parent_kind = match &litem.parent {
|
||||
Some(Parent::Type(ty)) => ty.ty().map(|ty| ty.kind()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if litem.id.client != ritem.id.client
|
||||
// not same delete status
|
||||
|| litem.deleted() != ritem.deleted()
|
||||
@@ -277,6 +282,13 @@ impl Node {
|
||||
l.extend(r.drain(0..));
|
||||
}
|
||||
(Content::String(l), Content::String(r)) => {
|
||||
let allow_merge_string =
|
||||
matches!(parent_kind, Some(YTypeKind::Text | YTypeKind::XMLText));
|
||||
|
||||
if !allow_merge_string {
|
||||
return false;
|
||||
}
|
||||
|
||||
*l += r;
|
||||
}
|
||||
(Content::Any(l), Content::Any(r)) => {
|
||||
|
||||
@@ -4,21 +4,50 @@ impl_type!(Array);
|
||||
|
||||
impl ListType for Array {}
|
||||
|
||||
pub struct ArrayIter<'a>(ListIterator<'a>);
|
||||
pub struct ArrayIter<'a> {
|
||||
iter: ListIterator<'a>,
|
||||
pending: Option<PendingArrayValues>,
|
||||
}
|
||||
|
||||
enum PendingArrayValues {
|
||||
Any { values: Vec<Any>, index: usize },
|
||||
}
|
||||
|
||||
impl Iterator for ArrayIter<'_> {
|
||||
type Item = Value;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
for item in self.0.by_ref() {
|
||||
loop {
|
||||
if let Some(PendingArrayValues::Any { values, index }) = &mut self.pending {
|
||||
if *index < values.len() {
|
||||
let value = values[*index].clone();
|
||||
*index += 1;
|
||||
return Some(Value::Any(value));
|
||||
}
|
||||
self.pending = None;
|
||||
}
|
||||
|
||||
let item = self.iter.next()?;
|
||||
if let Some(item) = item.get() {
|
||||
if item.countable() {
|
||||
return Some(Value::from(&item.content));
|
||||
if !item.countable() {
|
||||
continue;
|
||||
}
|
||||
|
||||
match &item.content {
|
||||
Content::Any(values) if !values.is_empty() => {
|
||||
if values.len() > 1 {
|
||||
self.pending = Some(PendingArrayValues::Any {
|
||||
values: values.clone(),
|
||||
index: 1,
|
||||
});
|
||||
}
|
||||
|
||||
return Some(Value::Any(values[0].clone()));
|
||||
}
|
||||
_ => return Some(Value::from(&item.content)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +75,10 @@ impl Array {
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> ArrayIter<'_> {
|
||||
ArrayIter(self.iter_item())
|
||||
ArrayIter {
|
||||
iter: self.iter_item(),
|
||||
pending: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push<V: Into<Value>>(&mut self, val: V) -> JwstCodecResult {
|
||||
|
||||
Reference in New Issue
Block a user