Skip to content

Commit bb37243

Browse files
committed
Use TermSet for ES terms query
1 parent adaf75a commit bb37243

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

quickwit/quickwit-query/src/elastic_query_dsl/term_query.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub struct TermQueryParams {
7575
case_insensitive: bool,
7676
}
7777

78+
#[cfg(test)]
7879
pub fn term_query_from_field_value(field: impl ToString, value: impl ToString) -> TermQuery {
7980
TermQuery {
8081
field: field.to_string(),

quickwit/quickwit-query/src/elastic_query_dsl/terms_query.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use std::collections::{BTreeSet, HashMap};
16+
1517
use serde::Deserialize;
1618

17-
use crate::elastic_query_dsl::bool_query::BoolQuery;
1819
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
19-
use crate::elastic_query_dsl::term_query::term_query_from_field_value;
2020
use crate::elastic_query_dsl::{ConvertibleToQueryAst, ElasticQueryDslInner};
2121
use crate::not_nan_f32::NotNaNf32;
22-
use crate::query_ast::QueryAst;
22+
use crate::query_ast::{QueryAst, TermSetQuery};
2323

2424
#[derive(PartialEq, Eq, Debug, Deserialize, Clone)]
2525
#[serde(try_from = "TermsQueryForSerialization")]
@@ -87,15 +87,14 @@ impl TryFrom<TermsQueryForSerialization> for TermsQuery {
8787

8888
impl ConvertibleToQueryAst for TermsQuery {
8989
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
90-
let term_queries: Vec<ElasticQueryDslInner> = self
91-
.values
92-
.into_iter()
93-
.map(|value| term_query_from_field_value(self.field.clone(), value))
94-
.map(ElasticQueryDslInner::from)
95-
.collect();
96-
let mut union = BoolQuery::union(term_queries);
97-
union.boost = self.boost;
98-
union.convert_to_query_ast()
90+
let mut terms_per_field = HashMap::new();
91+
let values_set: BTreeSet<String> = self.values.into_iter().collect();
92+
terms_per_field.insert(self.field, values_set);
93+
94+
let term_set_query = TermSetQuery { terms_per_field };
95+
let query_ast: QueryAst = term_set_query.into();
96+
97+
Ok(query_ast.boost(self.boost))
9998
}
10099
}
101100

0 commit comments

Comments
 (0)