This commit is contained in:
Brandon Thomas committed 2024-06-30 14:43:59 -04:00
1 parent c8127d99fd
commit 1a0a71dca4
4 files changed
+61 -2

No files matched your search

Generated
+2
View File
@@ -2204,8 +2204,10 @@ dependencies = [
"elasticsearch",
"enums",
"errors",
"jsonpath_lib",
"log",
"my-workspace-hack",
"once_cell",
"regex",
"serde",
"serde_json",
+6 -2
View File
@@ -21,16 +21,20 @@ enums = { path = "../../_types/enums" }
errors = { path = "../errors" }
tokens = { path = "../../_types/tokens" }
# Workspace hack (faster compile times)
my-workspace-hack = { version = "0.1", path = "../../my-workspace-hack" }
# External
elasticsearch = "8.5.0-alpha.1"
jsonpath_lib = "0.3.0"
log = "0.4.14"
once_cell = "1.19.0"
# Serialization
chrono = { version = "0.4.22", features = ["serde"] }
regex = "1.10.2"
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.108"
my-workspace-hack = { version = "0.1", path = "../../my-workspace-hack" }
regex = "1.10.2"
[dev-dependencies]
# None yet
@@ -1,2 +1,3 @@
pub mod search_media_files;
pub mod search_model_weights;
pub mod search_tts_models;
@@ -0,0 +1,52 @@
use once_cell::sync::Lazy;
use serde_json::{json, Value};
static JSON_QUERY : Lazy<Value> = Lazy::new(|| {
const QUERY_TEMPLATE : &str = include_str!("../../../../../_elasticsearch/searches/media_files/search.json");
let json : Value = serde_json::from_str(QUERY_TEMPLATE)
.expect("json should parse");
// Replace this with an empty list so that we can attach predicates later.
let json= jsonpath_lib::replace_with(json, "$.query.bool.must[0].bool.must", &mut |_| {
//Some(json!([]))
None
}).expect("json node should delete");
json
});
pub fn search() {
let query = JSON_QUERY.clone();
println!("{}", query);
let mut must_node = jsonpath_lib::select(
&query,
"$.query.bool.must[0].bool.must").expect("json node should exist");
println!("{:?}", must_node);
let new_node = json!({
"match": {
"media_file_id": "1234"
}
});
must_node.push(&new_node);
println!("{:?}", must_node);
println!("{}", query);
}
#[cfg(test)]
mod tests {
#[test]
fn test() {
super::search();
assert_eq!(1, 2);
}
}