From 1a0a71dca45de56a7438877db95f11005e0eceb1 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 30 Jun 2024 14:43:59 -0400 Subject: [PATCH] es wip --- Cargo.lock | 2 + crates/lib/elasticsearch_schema/Cargo.toml | 8 ++- .../elasticsearch_schema/src/searches/mod.rs | 1 + .../src/searches/search_media_files.rs | 52 +++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 crates/lib/elasticsearch_schema/src/searches/search_media_files.rs diff --git a/Cargo.lock b/Cargo.lock index 0e6c55a370..f9f06328ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2204,8 +2204,10 @@ dependencies = [ "elasticsearch", "enums", "errors", + "jsonpath_lib", "log", "my-workspace-hack", + "once_cell", "regex", "serde", "serde_json", diff --git a/crates/lib/elasticsearch_schema/Cargo.toml b/crates/lib/elasticsearch_schema/Cargo.toml index 73bd18137f..3c87be505b 100644 --- a/crates/lib/elasticsearch_schema/Cargo.toml +++ b/crates/lib/elasticsearch_schema/Cargo.toml @@ -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 \ No newline at end of file diff --git a/crates/lib/elasticsearch_schema/src/searches/mod.rs b/crates/lib/elasticsearch_schema/src/searches/mod.rs index aaa6955486..8516810571 100644 --- a/crates/lib/elasticsearch_schema/src/searches/mod.rs +++ b/crates/lib/elasticsearch_schema/src/searches/mod.rs @@ -1,2 +1,3 @@ +pub mod search_media_files; pub mod search_model_weights; pub mod search_tts_models; \ No newline at end of file diff --git a/crates/lib/elasticsearch_schema/src/searches/search_media_files.rs b/crates/lib/elasticsearch_schema/src/searches/search_media_files.rs new file mode 100644 index 0000000000..05d0b0e968 --- /dev/null +++ b/crates/lib/elasticsearch_schema/src/searches/search_media_files.rs @@ -0,0 +1,52 @@ +use once_cell::sync::Lazy; +use serde_json::{json, Value}; + + +static JSON_QUERY : Lazy = 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); + } +} \ No newline at end of file