@@ -414,6 +414,67 @@ fn exact_match_on_queries_with_sort() {
414
414
assert_eq ! ( json. crates[ 3 ] . name, "other_sort" ) ;
415
415
}
416
416
417
+ #[ test]
418
+ fn loose_search_order ( ) {
419
+ let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
420
+ let user = user. as_model ( ) ;
421
+
422
+ let ordered = app. db ( |conn| {
423
+ // exact match should be first
424
+ let one = CrateBuilder :: new ( "temp" , user. id )
425
+ . readme ( "readme" )
426
+ . description ( "description" )
427
+ . keyword ( "kw1" )
428
+ . expect_build ( conn) ;
429
+ // file shouldn't match at all
430
+ CrateBuilder :: new ( "file" , user. id )
431
+ . readme ( "readme" )
432
+ . description ( "description" )
433
+ . keyword ( "kw1" )
434
+ . expect_build ( conn) ;
435
+ // temp_udp should match second
436
+ let two = CrateBuilder :: new ( "temp_utp" , user. id )
437
+ . readme ( "readme" )
438
+ . description ( "description" )
439
+ . keyword ( "kw1" )
440
+ . expect_build ( conn) ;
441
+ // evalrs should match 3rd because of readme
442
+ let three = CrateBuilder :: new ( "evalrs" , user. id )
443
+ . readme ( r#"$ echo 'println!("Hello World!")' | evalrs
444
+ Compiling evalrs_temp v0.0.0 (file:///tmp/evalrs_temp.daiPxHtjV2VR)
445
+ Finished debug [unoptimized + debuginfo] target(s) in 0.51 secs
446
+ Running `target\debug\evalrs_temp.exe`
447
+ Hello World!"# )
448
+ . description ( "description" )
449
+ . keyword ( "kw1" )
450
+ . expect_build ( conn) ;
451
+ // tempfile should appear 4th
452
+ let four = CrateBuilder :: new ( "tempfile" , user. id )
453
+ . readme ( "readme" )
454
+ . description ( "description" )
455
+ . keyword ( "kw1" )
456
+ . expect_build ( conn) ;
457
+ // mkstemp should appear 5th
458
+ let five = CrateBuilder :: new ( "mkstemp" , user. id )
459
+ . readme ( "readme" )
460
+ . description ( "description" )
461
+ . keyword ( "kw1" )
462
+ . expect_build ( conn) ;
463
+ vec ! [ one, two, three, four, five]
464
+ } ) ;
465
+ let search_temp = anon. search ( "q=temp" ) ;
466
+ assert_eq ! ( search_temp. meta. total, 5 ) ;
467
+ assert_eq ! ( search_temp. crates. len( ) , 5 ) ;
468
+ for ( lhs, rhs) in search_temp. crates . iter ( ) . zip ( ordered) {
469
+ assert_eq ! ( lhs. name, rhs. name) ;
470
+ }
471
+ let search_file = anon. search ( "q=file" ) ;
472
+ assert_eq ! ( search_file. meta. total, 2 ) ;
473
+ assert_eq ! ( search_file. crates. len( ) , 2 ) ;
474
+ assert_eq ! ( & search_file. crates[ 0 ] . name, "file" ) ;
475
+ assert_eq ! ( & search_file. crates[ 1 ] . name, "tempfile" ) ;
476
+ }
477
+
417
478
#[ test]
418
479
fn show ( ) {
419
480
let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
0 commit comments