Skip to content

Commit 8028bae

Browse files
committed
rename seek_exact
1 parent c21bfbd commit 8028bae

File tree

10 files changed

+39
-32
lines changed

10 files changed

+39
-32
lines changed

src/docset.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,22 @@ pub trait DocSet: Send {
5353

5454
/// Seeks to the target if possible and returns true if the target is in the DocSet.
5555
///
56-
/// Implementations may choose to advance past the target if target does not exist.
57-
///
5856
/// DocSets that already have an efficient `seek` method don't need to implement `seek_exact`.
5957
/// All wrapper DocSets should forward `seek_exact` to the underlying DocSet.
6058
///
6159
/// ## API Behaviour
6260
/// If `seek_exact` is returning true, a call to `doc()` has to return target.
63-
/// If `seek_exact` is returning false, a call to `doc()` may return any doc and should not be
64-
/// used until `seek_exact` returns true again. The DocSet is considered to be in an invalid
65-
/// state until `seek_exact` returns true again.
61+
/// If `seek_exact` is returning false, a call to `doc()` may return any doc between
62+
/// the last doc that matched and target or a doc that is a valid next hit after target.
63+
/// The DocSet is considered to be in an invalid state until `seek_exact` returns true again.
6664
///
67-
/// target needs to be equal or larger than `doc` when in a valid state.
65+
/// `target` needs to be equal or larger than `doc` when in a valid state.
6866
///
6967
/// Consecutive calls are not allowed to have decreasing `target` values.
7068
///
7169
/// # Warning
7270
/// This is an advanced API used by intersection. The API contract is tricky, avoid using it.
73-
fn seek_exact(&mut self, target: DocId) -> bool {
71+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
7472
let current_doc = self.doc();
7573
if current_doc < target {
7674
self.seek(target);
@@ -175,8 +173,8 @@ impl DocSet for &mut dyn DocSet {
175173
(**self).seek(target)
176174
}
177175

178-
fn seek_exact(&mut self, target: DocId) -> bool {
179-
(**self).seek_exact(target)
176+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
177+
(**self).seek_into_the_danger_zone(target)
180178
}
181179

182180
fn doc(&self) -> u32 {
@@ -211,9 +209,9 @@ impl<TDocSet: DocSet + ?Sized> DocSet for Box<TDocSet> {
211209
unboxed.seek(target)
212210
}
213211

214-
fn seek_exact(&mut self, target: DocId) -> bool {
212+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
215213
let unboxed: &mut TDocSet = self.borrow_mut();
216-
unboxed.seek_exact(target)
214+
unboxed.seek_into_the_danger_zone(target)
217215
}
218216

219217
fn fill_buffer(&mut self, buffer: &mut [DocId; COLLECT_BLOCK_BUFFER_LEN]) -> usize {

src/postings/compression/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const COMPRESSED_BLOCK_MAX_SIZE: usize = COMPRESSION_BLOCK_SIZE * u32::SIZE_IN_B
77
mod vint;
88

99
/// Returns the size in bytes of a compressed block, given `num_bits`.
10+
#[inline]
1011
pub fn compressed_block_size(num_bits: u8) -> usize {
1112
(num_bits as usize) * COMPRESSION_BLOCK_SIZE / 8
1213
}

src/query/boost_query.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ impl<S: Scorer> DocSet for BoostScorer<S> {
104104
fn seek(&mut self, target: DocId) -> DocId {
105105
self.underlying.seek(target)
106106
}
107-
fn seek_exact(&mut self, target: DocId) -> bool {
108-
self.underlying.seek_exact(target)
107+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
108+
self.underlying.seek_into_the_danger_zone(target)
109109
}
110110

111111
fn fill_buffer(&mut self, buffer: &mut [DocId; COLLECT_BLOCK_BUFFER_LEN]) -> usize {

src/query/disjunction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ impl<T: Scorer> DocSet for ScorerWrapper<T> {
6767
self.current_doc = doc_id;
6868
doc_id
6969
}
70-
fn seek_exact(&mut self, target: DocId) -> bool {
71-
let found = self.scorer.seek_exact(target);
70+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
71+
let found = self.scorer.seek_into_the_danger_zone(target);
7272
self.current_doc = self.scorer.doc();
7373
found
7474
}

src/query/intersection.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,17 @@ impl<TDocSet: DocSet, TOtherDocSet: DocSet> DocSet for Intersection<TDocSet, TOt
115115
// of the two rarest `DocSet` in the intersection.
116116

117117
loop {
118-
if right.seek_exact(candidate) {
118+
if right.seek_into_the_danger_zone(candidate) {
119119
break;
120120
}
121-
// `left.advance().max(right.doc())` yielded a regression in the search game
122-
// benchmark It may make sense in certain scenarios though.
123-
candidate = left.advance();
121+
let right_doc = right.doc();
122+
// TODO: Think about which value would make sense here
123+
// It depends on the DocSet implementation, when a seek would outweigh an advance.
124+
if right_doc > candidate.wrapping_add(100) {
125+
candidate = left.seek(right_doc);
126+
} else {
127+
candidate = left.advance();
128+
}
124129
if candidate == TERMINATED {
125130
return TERMINATED;
126131
}
@@ -131,7 +136,7 @@ impl<TDocSet: DocSet, TOtherDocSet: DocSet> DocSet for Intersection<TDocSet, TOt
131136
if self
132137
.others
133138
.iter_mut()
134-
.all(|docset| docset.seek_exact(candidate))
139+
.all(|docset| docset.seek_into_the_danger_zone(candidate))
135140
{
136141
debug_assert_eq!(candidate, self.left.doc());
137142
debug_assert_eq!(candidate, self.right.doc());
@@ -158,13 +163,13 @@ impl<TDocSet: DocSet, TOtherDocSet: DocSet> DocSet for Intersection<TDocSet, TOt
158163
///
159164
/// Some implementations may choose to advance past the target if beneficial for performance.
160165
/// The return value is `true` if the target is in the docset, and `false` otherwise.
161-
fn seek_exact(&mut self, target: DocId) -> bool {
162-
self.left.seek_exact(target)
163-
&& self.right.seek_exact(target)
166+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
167+
self.left.seek_into_the_danger_zone(target)
168+
&& self.right.seek_into_the_danger_zone(target)
164169
&& self
165170
.others
166171
.iter_mut()
167-
.all(|docset| docset.seek_exact(target))
172+
.all(|docset| docset.seek_into_the_danger_zone(target))
168173
}
169174

170175
fn doc(&self) -> DocId {

src/query/phrase_prefix_query/phrase_prefix_scorer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ impl<TPostings: Postings> DocSet for PhrasePrefixScorer<TPostings> {
193193
self.advance()
194194
}
195195

196-
fn seek_exact(&mut self, target: DocId) -> bool {
197-
if self.phrase_scorer.seek_exact(target) {
196+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
197+
if self.phrase_scorer.seek_into_the_danger_zone(target) {
198198
self.matches_prefix()
199199
} else {
200200
false

src/query/phrase_query/phrase_scorer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,9 @@ impl<TPostings: Postings> DocSet for PhraseScorer<TPostings> {
530530
self.advance()
531531
}
532532

533-
fn seek_exact(&mut self, target: DocId) -> bool {
533+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
534534
debug_assert!(target >= self.doc());
535-
if self.intersection_docset.seek_exact(target) && self.phrase_match() {
535+
if self.intersection_docset.seek_into_the_danger_zone(target) && self.phrase_match() {
536536
return true;
537537
}
538538
false

src/query/reqopt_scorer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ where
5656
self.req_scorer.seek(target)
5757
}
5858

59-
fn seek_exact(&mut self, target: DocId) -> bool {
59+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
6060
self.score_cache = None;
61-
self.req_scorer.seek_exact(target)
61+
self.req_scorer.seek_into_the_danger_zone(target)
6262
}
6363

6464
fn doc(&self) -> DocId {

src/query/term_query/term_scorer.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,17 @@ impl TermScorer {
9898
}
9999

100100
impl DocSet for TermScorer {
101+
#[inline]
101102
fn advance(&mut self) -> DocId {
102103
self.postings.advance()
103104
}
104105

106+
#[inline]
105107
fn seek(&mut self, target: DocId) -> DocId {
106108
self.postings.seek(target)
107109
}
108110

111+
#[inline]
109112
fn doc(&self) -> DocId {
110113
self.postings.doc()
111114
}

src/query/union/buffered_union.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,11 @@ where
197197
}
198198
}
199199

200-
fn seek_exact(&mut self, target: DocId) -> bool {
200+
fn seek_into_the_danger_zone(&mut self, target: DocId) -> bool {
201201
let is_hit = self
202202
.docsets
203203
.iter_mut()
204-
.all(|docset| docset.seek_exact(target));
204+
.all(|docset| docset.seek_into_the_danger_zone(target));
205205
// The API requires the DocSet to be in a valid state when `seek_exact` returns true.
206206
if is_hit {
207207
self.seek(target);

0 commit comments

Comments
 (0)