Skip to content

Commit 7f3e505

Browse files
authored
Added search tags filtering (#1355)
1 parent 4c301ca commit 7f3e505

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pgml-dashboard/src/api/cms.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,10 @@ impl Collection {
625625

626626
#[get("/search?<query>", rank = 20)]
627627
async fn search(query: &str, site_search: &State<crate::utils::markdown::SiteSearch>) -> ResponseOk {
628-
let results = site_search.search(query, None).await.expect("Error performing search");
628+
let results = site_search
629+
.search(query, None, None)
630+
.await
631+
.expect("Error performing search");
629632

630633
let results: Vec<SearchResult> = results
631634
.into_iter()

pgml-dashboard/src/utils/markdown.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,12 @@ impl SiteSearch {
12861286
.collect()
12871287
}
12881288

1289-
pub async fn search(&self, query: &str, doc_type: Option<DocType>) -> anyhow::Result<Vec<Document>> {
1289+
pub async fn search(
1290+
&self,
1291+
query: &str,
1292+
doc_type: Option<DocType>,
1293+
doc_tags: Option<Vec<String>>,
1294+
) -> anyhow::Result<Vec<Document>> {
12901295
let mut search = serde_json::json!({
12911296
"query": {
12921297
// "full_text_search": {
@@ -1317,11 +1322,17 @@ impl SiteSearch {
13171322
},
13181323
"limit": 10
13191324
});
1325+
search["query"]["filter"]["$and"] = serde_json::json!({});
13201326
if let Some(doc_type) = doc_type {
1321-
search["query"]["filter"]["doc_type"] = serde_json::json!({
1327+
search["query"]["filter"]["$and"]["doc_type"] = serde_json::json!({
13221328
"$eq": doc_type
13231329
});
13241330
}
1331+
if let Some(doc_tags) = doc_tags {
1332+
search["query"]["filter"]["$and"]["tags"] = serde_json::json!({
1333+
"$in": doc_tags
1334+
});
1335+
}
13251336
let results = self.collection.search_local(search.into(), &self.pipeline).await?;
13261337

13271338
results["results"]

0 commit comments

Comments
 (0)
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