@@ -414,6 +414,69 @@ 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 (
444
+ r#"$ echo 'println!("Hello World!")' | evalrs
445
+ Compiling evalrs_temp v0.0.0 (file:///tmp/evalrs_temp.daiPxHtjV2VR)
446
+ Finished debug [unoptimized + debuginfo] target(s) in 0.51 secs
447
+ Running `target\debug\evalrs_temp.exe`
448
+ Hello World!"# ,
449
+ )
450
+ . description ( "description" )
451
+ . keyword ( "kw1" )
452
+ . expect_build ( conn) ;
453
+ // tempfile should appear 4th
454
+ let four = CrateBuilder :: new ( "tempfile" , user. id )
455
+ . readme ( "readme" )
456
+ . description ( "description" )
457
+ . keyword ( "kw1" )
458
+ . expect_build ( conn) ;
459
+ // mkstemp should appear 5th
460
+ let five = CrateBuilder :: new ( "mkstemp" , user. id )
461
+ . readme ( "readme" )
462
+ . description ( "description" )
463
+ . keyword ( "kw1" )
464
+ . expect_build ( conn) ;
465
+ vec ! [ one, two, three, four, five]
466
+ } ) ;
467
+ let search_temp = anon. search ( "q=temp" ) ;
468
+ assert_eq ! ( search_temp. meta. total, 5 ) ;
469
+ assert_eq ! ( search_temp. crates. len( ) , 5 ) ;
470
+ for ( lhs, rhs) in search_temp. crates . iter ( ) . zip ( ordered) {
471
+ assert_eq ! ( lhs. name, rhs. name) ;
472
+ }
473
+ let search_file = anon. search ( "q=file" ) ;
474
+ assert_eq ! ( search_file. meta. total, 2 ) ;
475
+ assert_eq ! ( search_file. crates. len( ) , 2 ) ;
476
+ assert_eq ! ( & search_file. crates[ 0 ] . name, "file" ) ;
477
+ assert_eq ! ( & search_file. crates[ 1 ] . name, "tempfile" ) ;
478
+ }
479
+
417
480
#[ test]
418
481
fn show ( ) {
419
482
let ( app, anon, user) = TestApp :: init ( ) . with_user ( ) ;
0 commit comments