@@ -119,8 +119,7 @@ impl ExistsDocSet {
119
119
120
120
impl DocSet for ExistsDocSet {
121
121
fn advance ( & mut self ) -> DocId {
122
- self . doc += 1 ;
123
- self . find_next ( )
122
+ self . seek ( self . doc + 1 )
124
123
}
125
124
126
125
fn size_hint ( & self ) -> u32 {
@@ -130,17 +129,25 @@ impl DocSet for ExistsDocSet {
130
129
fn doc ( & self ) -> DocId {
131
130
self . doc
132
131
}
132
+
133
+ #[ inline( always) ]
134
+ fn seek ( & mut self , target : DocId ) -> DocId {
135
+ self . doc = target;
136
+ self . find_next ( )
137
+ }
133
138
}
134
139
135
140
#[ cfg( test) ]
136
141
mod tests {
137
142
use std:: net:: Ipv6Addr ;
143
+ use std:: ops:: Bound ;
138
144
139
145
use common:: DateTime ;
140
146
use time:: OffsetDateTime ;
141
147
142
148
use crate :: collector:: Count ;
143
149
use crate :: query:: exist_query:: ExistsQuery ;
150
+ use crate :: query:: { BooleanQuery , RangeQuery } ;
144
151
use crate :: schema:: { Facet , FacetOptions , Schema , FAST , INDEXED , STRING , TEXT } ;
145
152
use crate :: { doc, Index , Searcher } ;
146
153
@@ -179,6 +186,27 @@ mod tests {
179
186
assert_eq ! ( count_existing_fields( & searcher, "multi" ) ?, 10 ) ;
180
187
assert_eq ! ( count_existing_fields( & searcher, "never" ) ?, 0 ) ;
181
188
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
+
182
210
Ok ( ( ) )
183
211
}
184
212
0 commit comments