feat: introduce fuzzy search for native indexer (#14109)

This commit is contained in:
DarkSky
2025-12-25 04:40:23 +08:00
committed by GitHub
parent b6dc68eddf
commit e8693a3a25
24 changed files with 237 additions and 537 deletions
@@ -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 {