Skip to content

Commit 82a1022

Browse files
committed
And faster seek implementation.
1 parent e4e5225 commit 82a1022

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/query/exist_query.rs

+30-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,7 @@ impl ExistsDocSet {
119119

120120
impl DocSet for ExistsDocSet {
121121
fn advance(&mut self) -> DocId {
122-
self.doc += 1;
123-
self.find_next()
122+
self.seek(self.doc + 1)
124123
}
125124

126125
fn size_hint(&self) -> u32 {
@@ -130,17 +129,25 @@ impl DocSet for ExistsDocSet {
130129
fn doc(&self) -> DocId {
131130
self.doc
132131
}
132+
133+
#[inline(always)]
134+
fn seek(&mut self, target: DocId) -> DocId {
135+
self.doc = target;
136+
self.find_next()
137+
}
133138
}
134139

135140
#[cfg(test)]
136141
mod tests {
137142
use std::net::Ipv6Addr;
143+
use std::ops::Bound;
138144

139145
use common::DateTime;
140146
use time::OffsetDateTime;
141147

142148
use crate::collector::Count;
143149
use crate::query::exist_query::ExistsQuery;
150+
use crate::query::{BooleanQuery, RangeQuery};
144151
use crate::schema::{Facet, FacetOptions, Schema, FAST, INDEXED, STRING, TEXT};
145152
use crate::{doc, Index, Searcher};
146153

@@ -179,6 +186,27 @@ mod tests {
179186
assert_eq!(count_existing_fields(&searcher, "multi")?, 10);
180187
assert_eq!(count_existing_fields(&searcher, "never")?, 0);
181188

189+
// exercise seek
190+
let query = BooleanQuery::intersection(vec![
191+
Box::new(RangeQuery::new_u64_bounds(
192+
"all".to_string(),
193+
Bound::Included(50),
194+
Bound::Unbounded,
195+
)),
196+
Box::new(ExistsQuery::new_exists_query("even".to_string())),
197+
]);
198+
assert_eq!(searcher.search(&query, &Count)?, 25);
199+
200+
let query = BooleanQuery::intersection(vec![
201+
Box::new(RangeQuery::new_u64_bounds(
202+
"all".to_string(),
203+
Bound::Included(0),
204+
Bound::Excluded(50),
205+
)),
206+
Box::new(ExistsQuery::new_exists_query("odd".to_string())),
207+
]);
208+
assert_eq!(searcher.search(&query, &Count)?, 25);
209+
182210
Ok(())
183211
}
184212

0 commit comments

Comments
 (0)