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 {
625625
626626#[ get( "/search?<query>" , rank = 20 ) ]
627627async 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 ( )
Original file line number Diff line number Diff 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" ]
You can’t perform that action at this time.
0 commit comments