File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -168,6 +168,14 @@ pub fn search(req: &mut dyn RequestExt) -> EndpointResult {
168
168
. filter ( follows:: user_id. eq ( user_id) ) ,
169
169
) ,
170
170
) ;
171
+ } else if params. get ( "ids[]" ) . is_some ( ) {
172
+ let query_bytes = req. query_string ( ) . unwrap_or ( "" ) . as_bytes ( ) ;
173
+ let ids: Vec < _ > = url:: form_urlencoded:: parse ( query_bytes)
174
+ . filter ( |( key, _) | key == "ids[]" )
175
+ . map ( |( _, value) | value. to_string ( ) )
176
+ . collect ( ) ;
177
+
178
+ query = query. filter ( crates:: name. eq ( any ( ids) ) ) ;
171
179
}
172
180
173
181
if !include_yanked {
Original file line number Diff line number Diff line change @@ -403,6 +403,26 @@ fn exact_match_on_queries_with_sort() {
403
403
assert_eq ! ( json. crates[ 3 ] . name, "other_sort" ) ;
404
404
}
405
405
406
+ #[ test]
407
+ fn multiple_ids ( ) {
408
+ let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
409
+ let user = user. as_model ( ) ;
410
+
411
+ app. db ( |conn| {
412
+ CrateBuilder :: new ( "foo" , user. id ) . expect_build ( conn) ;
413
+ CrateBuilder :: new ( "bar" , user. id ) . expect_build ( conn) ;
414
+ CrateBuilder :: new ( "baz" , user. id ) . expect_build ( conn) ;
415
+ CrateBuilder :: new ( "other" , user. id ) . expect_build ( conn) ;
416
+ } ) ;
417
+
418
+ let json =
419
+ anon. search ( "ids%5B%5D=foo&ids%5B%5D=bar&ids%5B%5D=baz&ids%5B%5D=baz&ids%5B%5D=unknown" ) ;
420
+ assert_eq ! ( json. meta. total, 3 ) ;
421
+ assert_eq ! ( json. crates[ 0 ] . name, "bar" ) ;
422
+ assert_eq ! ( json. crates[ 1 ] . name, "baz" ) ;
423
+ assert_eq ! ( json. crates[ 2 ] . name, "foo" ) ;
424
+ }
425
+
406
426
#[ test]
407
427
fn loose_search_order ( ) {
408
428
let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
You can’t perform that action at this time.
0 commit comments