From ffa7cdf397bf0913d90e68b3402dfbaf49aef4a7 Mon Sep 17 00:00:00 2001 From: Kat Lim Ruiz Date: Thu, 3 Apr 2025 08:35:16 -0500 Subject: [PATCH] agreed with Remi, about the final json structure, having "type" tag and using "clauses" is more accurate --- query-grammar/src/lib.rs | 2 +- query-grammar/src/user_input_ast.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/query-grammar/src/lib.rs b/query-grammar/src/lib.rs index 2ba7c589e..c7c41df14 100644 --- a/query-grammar/src/lib.rs +++ b/query-grammar/src/lib.rs @@ -39,7 +39,7 @@ mod tests { let json = serde_json::to_string(&ast).unwrap(); assert_eq!( json, - r#"{"clause":[["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}],["should",{"type":"literal","field_name":"title","phrase":"x","delimiter":"none","slop":0,"prefix":false}]]}"# + r#"{"type":"bool","clauses":[["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}],["should",{"type":"literal","field_name":"title","phrase":"x","delimiter":"none","slop":0,"prefix":false}]]}"# ); } diff --git a/query-grammar/src/user_input_ast.rs b/query-grammar/src/user_input_ast.rs index bd079175f..dff85b4b3 100644 --- a/query-grammar/src/user_input_ast.rs +++ b/query-grammar/src/user_input_ast.rs @@ -206,8 +206,8 @@ pub enum UserInputAst { #[derive(Serialize)] #[serde(tag = "type", rename_all = "snake_case")] enum UserInputAstSerde { - Clause { - clause: Vec<(Option, UserInputAst)>, + Bool { + clauses: Vec<(Option, UserInputAst)>, }, Boost { underlying: Box, @@ -220,7 +220,7 @@ enum UserInputAstSerde { impl From for UserInputAstSerde { fn from(ast: UserInputAst) -> Self { match ast { - UserInputAst::Clause(clause) => UserInputAstSerde::Clause { clause }, + UserInputAst::Clause(clause) => UserInputAstSerde::Bool { clauses: clause }, UserInputAst::Boost(underlying, boost) => { UserInputAstSerde::Boost { underlying, boost } } @@ -414,7 +414,7 @@ mod tests { let json = serde_json::to_string(&boost_ast).unwrap(); assert_eq!( json, - r#"{"type":"boost","underlying":{"type":"clause","clause":[["must",{"type":"all"}],["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}]]},"boost":2.5}"# + r#"{"type":"boost","underlying":{"type":"bool","clauses":[["must",{"type":"all"}],["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}]]},"boost":2.5}"# ); } @@ -439,7 +439,7 @@ mod tests { let json = serde_json::to_string(&clause).unwrap(); assert_eq!( json, - r#"{"type":"clause","clause":[["must",{"type":"all"}],["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}]]}"# + r#"{"type":"bool","clauses":[["must",{"type":"all"}],["should",{"type":"literal","field_name":"title","phrase":"hello","delimiter":"none","slop":0,"prefix":false}]]}"# ); } }