File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -625,7 +625,10 @@ impl Collection {
625
625
626
626
#[ get( "/search?<query>" , rank = 20 ) ]
627
627
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" ) ;
629
632
630
633
let results: Vec < SearchResult > = results
631
634
. into_iter ( )
Original file line number Diff line number Diff line change @@ -1286,7 +1286,12 @@ impl SiteSearch {
1286
1286
. collect ( )
1287
1287
}
1288
1288
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 > > {
1290
1295
let mut search = serde_json:: json!( {
1291
1296
"query" : {
1292
1297
// "full_text_search": {
@@ -1317,11 +1322,17 @@ impl SiteSearch {
1317
1322
} ,
1318
1323
"limit" : 10
1319
1324
} ) ;
1325
+ search[ "query" ] [ "filter" ] [ "$and" ] = serde_json:: json!( { } ) ;
1320
1326
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!( {
1322
1328
"$eq" : doc_type
1323
1329
} ) ;
1324
1330
}
1331
+ if let Some ( doc_tags) = doc_tags {
1332
+ search[ "query" ] [ "filter" ] [ "$and" ] [ "tags" ] = serde_json:: json!( {
1333
+ "$in" : doc_tags
1334
+ } ) ;
1335
+ }
1325
1336
let results = self . collection . search_local ( search. into ( ) , & self . pipeline ) . await ?;
1326
1337
1327
1338
results[ "results" ]
You can’t perform that action at this time.
0 commit comments