Skip to content

Commit 0da0f62

Browse files
committed
feat: Add support for short request format
Signed-off-by: Darkheir <[email protected]>
1 parent 4c019ee commit 0da0f62

File tree

4 files changed

+82
-7
lines changed

4 files changed

+82
-7
lines changed

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,29 @@
1414

1515
use serde::Deserialize;
1616

17-
use crate::elastic_query_dsl::ConvertibleToQueryAst;
17+
use crate::elastic_query_dsl::{ConvertibleToQueryAst, StringOrStructForSerialization};
1818
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
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>;
2834

2935
impl ConvertibleToQueryAst for PrefixQuery {
3036
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
3137
let wildcard = format!(
3238
"{}*",
33-
self.value
39+
self.params
3440
.value
3541
.replace("\\", "\\\\")
3642
.replace("*", "\\*")
@@ -45,6 +51,28 @@ impl ConvertibleToQueryAst for PrefixQuery {
4551
}
4652
}
4753

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

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

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

1515
use serde::Deserialize;
1616

17-
use crate::elastic_query_dsl::ConvertibleToQueryAst;
17+
use crate::elastic_query_dsl::{
18+
ConvertibleToQueryAst, StringOrStructForSerialization,
19+
};
1820
use crate::elastic_query_dsl::one_field_map::OneFieldMap;
1921
use crate::query_ast::{QueryAst, WildcardQuery as AstWildcardQuery};
2022

23+
#[derive(Deserialize, Clone, Eq, PartialEq, Debug)]
24+
#[serde(from = "OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>")]
25+
pub(crate) struct WildcardQuery {
26+
pub(crate) field: String,
27+
pub(crate) params: WildcardQueryParams,
28+
}
29+
2130
#[derive(Deserialize, Debug, Default, Eq, PartialEq, Clone)]
2231
#[serde(deny_unknown_fields)]
2332
pub struct WildcardQueryParams {
2433
value: String,
2534
}
2635

27-
pub type WildcardQuery = OneFieldMap<WildcardQueryParams>;
28-
2936
impl ConvertibleToQueryAst for WildcardQuery {
3037
fn convert_to_query_ast(self) -> anyhow::Result<QueryAst> {
3138
Ok(AstWildcardQuery {
3239
field: self.field,
33-
value: self.value.value,
40+
value: self.params.value,
3441
lenient: true,
3542
}
3643
.into())
3744
}
3845
}
3946

47+
impl From<OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>>
48+
for WildcardQuery
49+
{
50+
fn from(
51+
match_query_params: OneFieldMap<StringOrStructForSerialization<WildcardQueryParams>>,
52+
) -> Self {
53+
let OneFieldMap { field, value } = match_query_params;
54+
WildcardQuery {
55+
field,
56+
params: value.inner,
57+
}
58+
}
59+
}
60+
61+
impl From<String> for WildcardQueryParams {
62+
fn from(value: String) -> WildcardQueryParams {
63+
WildcardQueryParams {
64+
value,
65+
}
66+
}
67+
}
68+
4069
#[cfg(test)]
4170
mod tests {
4271
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)