Skip to content

Commit f2681ad

Browse files
committed
feat: Add support for short request format
Signed-off-by: Darkheir <raphael.cohen@sekoia.io>
1 parent 4c019ee commit f2681ad

File tree

4 files changed

+72
-8
lines changed

4 files changed

+72
-8
lines changed

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@
1414

1515
use serde::Deserialize;
1616

17-
use crate::elastic_query_dsl::ConvertibleToQueryAst;
1817
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
18+
use crate::elastic_query_dsl::{ConvertibleToQueryAst, StringOrStructForSerialization};
1919
use crate::query_ast::{QueryAst, WildcardQuery as AstWildcardQuery};
2020

21+
#[derive(Deserialize, Clone, Eq, PartialEq, Debug)]
22+
#[serde(from = "OneFieldMap<StringOrStructForSerialization<PrefixQueryParams>>")]
23+
pub(crate) struct PrefixQuery {
24+
pub(crate) field: String,
25+
pub(crate) params: PrefixQueryParams,
26+
}
27+
2128
#[derive(Deserialize, Debug, Default, Eq, PartialEq, Clone)]
2229
#[serde(deny_unknown_fields)]
2330
pub struct PrefixQueryParams {
2431
value: String,
2532
}
2633

27-
pub type PrefixQuery = OneFieldMap<PrefixQueryParams>;
28-
2934
impl ConvertibleToQueryAst for PrefixQuery {
3035
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
3136
let wildcard = format!(
3237
"{}*",
33-
self.value
38+
self.params
3439
.value
3540
.replace("\\", "\\\\")
3641
.replace("*", "\\*")
@@ -45,6 +50,24 @@ impl ConvertibleToQueryAst for PrefixQuery {
4550
}
4651
}
4752

53+
impl From<OneFieldMap<StringOrStructForSerialization<PrefixQueryParams>>> for PrefixQuery {
54+
fn from(
55+
match_query_params: OneFieldMap<StringOrStructForSerialization<PrefixQueryParams>>,
56+
) -> Self {
57+
let OneFieldMap { field, value } = match_query_params;
58+
PrefixQuery {
59+
field,
60+
params: value.inner,
61+
}
62+
}
63+
}
64+
65+
impl From<String> for PrefixQueryParams {
66+
fn from(value: String) -> PrefixQueryParams {
67+
PrefixQueryParams { value }
68+
}
69+
}
70+
4871
#[cfg(test)]
4972
mod tests {
5073
use super::*;

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,52 @@
1414

1515
use serde::Deserialize;
1616

17-
use crate::elastic_query_dsl::ConvertibleToQueryAst;
1817
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
18+
use crate::elastic_query_dsl::{ConvertibleToQueryAst, StringOrStructForSerialization};
1919
use crate::query_ast::{QueryAst, WildcardQuery as AstWildcardQuery};
2020

21+
#[derive(Deserialize, Clone, Eq, PartialEq, Debug)]
22+
#[serde(from = "OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>")]
23+
pub(crate) struct WildcardQuery {
24+
pub(crate) field: String,
25+
pub(crate) params: WildcardQueryParams,
26+
}
27+
2128
#[derive(Deserialize, Debug, Default, Eq, PartialEq, Clone)]
2229
#[serde(deny_unknown_fields)]
2330
pub struct WildcardQueryParams {
2431
value: String,
2532
}
2633

27-
pub type WildcardQuery = OneFieldMap<WildcardQueryParams>;
28-
2934
impl ConvertibleToQueryAst for WildcardQuery {
3035
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
3136
Ok(AstWildcardQuery {
3237
field: self.field,
33-
value: self.value.value,
38+
value: self.params.value,
3439
lenient: true,
3540
}
3641
.into())
3742
}
3843
}
3944

45+
impl From<OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>> for WildcardQuery {
46+
fn from(
47+
match_query_params: OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>,
48+
) -> Self {
49+
let OneFieldMap { field, value } = match_query_params;
50+
WildcardQuery {
51+
field,
52+
params: value.inner,
53+
}
54+
}
55+
}
56+
57+
impl From<String> for WildcardQueryParams {
58+
fn from(value: String) -> WildcardQueryParams {
59+
WildcardQueryParams { value }
60+
}
61+
}
62+
4063
#[cfg(test)]
4164
mod tests {
4265
use super::*;

quickwit/rest-api-tests/scenarii/es_compatibility/0029-wildcard.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ expected:
1717
hits:
1818
total:
1919
value: 2
20+
---
21+
json:
22+
query:
23+
wildcard:
24+
actor.login: jad?nk
25+
expected:
26+
hits:
27+
total:
28+
value: 2

quickwit/rest-api-tests/scenarii/es_compatibility/0030-prefix.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ expected:
1717
hits:
1818
total:
1919
value: 10
20+
---
21+
json:
22+
query:
23+
prefix:
24+
actor.login: jado
25+
expected:
26+
hits:
27+
total:
28+
value: 2

0 commit comments

Comments
 (0)