From 93c220bf5775e8915efd651afabdc222c491e703 Mon Sep 17 00:00:00 2001 From: yorkart Date: Tue, 3 Dec 2024 22:03:17 +0800 Subject: [PATCH 1/2] bugfix: fix missing stats when search interrupted --- crates/searcher/src/searcher/glue.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/searcher/src/searcher/glue.rs b/crates/searcher/src/searcher/glue.rs index 006afad34..d1cd65145 100644 --- a/crates/searcher/src/searcher/glue.rs +++ b/crates/searcher/src/searcher/glue.rs @@ -37,7 +37,11 @@ where pub(crate) fn run(mut self) -> Result<(), S::Error> { if self.core.begin()? { - while self.fill()? && self.core.match_by_line(self.rdr.buffer())? { + while self.fill()? { + if !self.core.match_by_line(self.rdr.buffer())? { + self.consumed_remain(); + break; + } } } self.core.finish( @@ -46,6 +50,12 @@ where ) } + fn consumed_remain(&mut self) { + let buf = &self.rdr.buffer()[0..self.core.pos()]; + let consumed = self.core.roll(buf); + self.rdr.consume(consumed); + } + fn fill(&mut self) -> Result { assert!(self.rdr.buffer()[self.core.pos()..].is_empty()); From bffc12545570f9d7f78d103c9d9378ef20f12c46 Mon Sep 17 00:00:00 2001 From: yorkart Date: Wed, 4 Dec 2024 10:53:18 +0800 Subject: [PATCH 2/2] fix: fix test fail --- crates/searcher/src/searcher/glue.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/searcher/src/searcher/glue.rs b/crates/searcher/src/searcher/glue.rs index d1cd65145..ac968ca7f 100644 --- a/crates/searcher/src/searcher/glue.rs +++ b/crates/searcher/src/searcher/glue.rs @@ -51,8 +51,7 @@ where } fn consumed_remain(&mut self) { - let buf = &self.rdr.buffer()[0..self.core.pos()]; - let consumed = self.core.roll(buf); + let consumed = self.core.pos(); self.rdr.consume(consumed); }