Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ pub struct TermQueryParams {
case_insensitive: bool,
}

#[cfg(test)]
pub fn term_query_from_field_value(field: impl ToString, value: impl ToString) -> TermQuery {
TermQuery {
field: field.to_string(),
Expand Down
23 changes: 11 additions & 12 deletions quickwit/quickwit-query/src/elastic_query_dsl/terms_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::collections::{BTreeSet, HashMap};

use serde::Deserialize;

use crate::elastic_query_dsl::bool_query::BoolQuery;
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
use crate::elastic_query_dsl::term_query::term_query_from_field_value;
use crate::elastic_query_dsl::{ConvertibleToQueryAst, ElasticQueryDslInner};
use crate::not_nan_f32::NotNaNf32;
use crate::query_ast::QueryAst;
use crate::query_ast::{QueryAst, TermSetQuery};

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

impl ConvertibleToQueryAst for TermsQuery {
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
let term_queries: Vec<ElasticQueryDslInner> = self
.values
.into_iter()
.map(|value| term_query_from_field_value(self.field.clone(), value))
.map(ElasticQueryDslInner::from)
.collect();
let mut union = BoolQuery::union(term_queries);
union.boost = self.boost;
union.convert_to_query_ast()
let mut terms_per_field = HashMap::new();
let values_set: BTreeSet<String> = self.values.into_iter().collect();
terms_per_field.insert(self.field, values_set);

let term_set_query = TermSetQuery { terms_per_field };
let query_ast: QueryAst = term_set_query.into();

Ok(query_ast.boost(self.boost))
}
}

Expand Down
Loading