From 6539d04c1973881db06d77b346315b5d8e38dfca Mon Sep 17 00:00:00 2001 From: SilasMarvin <19626586+SilasMarvin@users.noreply.github.com> Date: Mon, 4 Mar 2024 14:04:31 -0800 Subject: [PATCH] Added search tags filtering --- pgml-dashboard/src/api/cms.rs | 5 ++++- pgml-dashboard/src/utils/markdown.rs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pgml-dashboard/src/api/cms.rs b/pgml-dashboard/src/api/cms.rs index 3f49a934f..37dec465b 100644 --- a/pgml-dashboard/src/api/cms.rs +++ b/pgml-dashboard/src/api/cms.rs @@ -625,7 +625,10 @@ impl Collection { #[get("/search?", rank = 20)] async fn search(query: &str, site_search: &State) -> ResponseOk { - let results = site_search.search(query, None).await.expect("Error performing search"); + let results = site_search + .search(query, None, None) + .await + .expect("Error performing search"); let results: Vec = results .into_iter() diff --git a/pgml-dashboard/src/utils/markdown.rs b/pgml-dashboard/src/utils/markdown.rs index fc8bcae86..6872c509e 100644 --- a/pgml-dashboard/src/utils/markdown.rs +++ b/pgml-dashboard/src/utils/markdown.rs @@ -1286,7 +1286,12 @@ impl SiteSearch { .collect() } - pub async fn search(&self, query: &str, doc_type: Option) -> anyhow::Result> { + pub async fn search( + &self, + query: &str, + doc_type: Option, + doc_tags: Option>, + ) -> anyhow::Result> { let mut search = serde_json::json!({ "query": { // "full_text_search": { @@ -1317,11 +1322,17 @@ impl SiteSearch { }, "limit": 10 }); + search["query"]["filter"]["$and"] = serde_json::json!({}); if let Some(doc_type) = doc_type { - search["query"]["filter"]["doc_type"] = serde_json::json!({ + search["query"]["filter"]["$and"]["doc_type"] = serde_json::json!({ "$eq": doc_type }); } + if let Some(doc_tags) = doc_tags { + search["query"]["filter"]["$and"]["tags"] = serde_json::json!({ + "$in": doc_tags + }); + } let results = self.collection.search_local(search.into(), &self.pipeline).await?; results["results"] pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy