Skip to content

Commit 5c89e3d

Browse files
author
Adam Reichold
committed
Add method to take clauses out of boolean query
This helps with rewriting, for example to replace the default score combiner used by boolean queries, insofer it avoids the need to `box_clone` the sub queries.
1 parent 5379c99 commit 5c89e3d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/query/boolean_query/boolean_query.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::mem;
2+
13
use super::boolean_weight::BooleanWeight;
24
use crate::query::{EnableScoring, Occur, Query, SumCombiner, TermQuery, Weight};
35
use crate::schema::{IndexRecordOption, Term};
@@ -254,8 +256,13 @@ impl BooleanQuery {
254256
}
255257

256258
/// Deconstructed view of the clauses making up this query.
257-
pub fn clauses(&self) -> &[(Occur, Box<dyn Query>)] {
258-
&self.subqueries[..]
259+
pub fn clauses(&self) -> impl Iterator<Item = &(Occur, Box<dyn Query>)> {
260+
self.subqueries.iter()
261+
}
262+
263+
/// Take the clauses making up this query for reuse.
264+
pub fn take_clauses(&mut self) -> impl Iterator<Item = (Occur, Box<dyn Query>)> {
265+
mem::take(&mut self.subqueries).into_iter()
259266
}
260267
}
261268

0 commit comments

Comments
 (0)