File tree 2 files changed +8
-11
lines changed
2 files changed +8
-11
lines changed Original file line number Diff line number Diff line change @@ -38,12 +38,6 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {
38
38
let conn = req. db_conn ( ) ?;
39
39
let ( offset, limit) = req. pagination ( 10 , 100 ) ?;
40
40
let params = req. query ( ) ;
41
- //extract the search param for loose searching
42
- let search_q = if let Some ( q) = params. get ( "q" ) {
43
- format ! ( "%{}%" , q)
44
- } else {
45
- String :: new ( )
46
- } ;
47
41
let sort = params
48
42
. get ( "sort" )
49
43
. map ( |s| & * * s)
@@ -64,10 +58,11 @@ pub fn search(req: &mut dyn Request) -> CargoResult<Response> {
64
58
has_filter = true ;
65
59
if !q_string. is_empty ( ) {
66
60
let sort = params. get ( "sort" ) . map ( |s| & * * s) . unwrap_or ( "relevance" ) ;
61
+
67
62
let q = plainto_tsquery ( q_string) ;
68
63
query = query. filter (
69
64
q. matches ( crates:: textsearchable_index_col)
70
- . or ( Crate :: like_name ( & search_q ) ) ,
65
+ . or ( Crate :: like_name ( & q_string ) ) ,
71
66
) ;
72
67
73
68
query = query. select ( (
Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ type CanonCrateName<T> = self::canon_crate_name::HelperType<T>;
87
87
type All = diesel:: dsl:: Select < crates:: table , AllColumns > ;
88
88
type WithName < ' a > = diesel:: dsl:: Eq < CanonCrateName < crates:: name > , CanonCrateName < & ' a str > > ;
89
89
/// The result of a loose search
90
- type LikeName < ' a > = diesel:: dsl:: Like < CanonCrateName < crates:: name > , CanonCrateName < & ' a str > > ;
90
+ type LikeName = diesel:: dsl:: Like < CanonCrateName < crates:: name > , CanonCrateName < String > > ;
91
91
type ByName < ' a > = diesel:: dsl:: Filter < All , WithName < ' a > > ;
92
92
type ByExactName < ' a > = diesel:: dsl:: Filter < All , diesel:: dsl:: Eq < crates:: name , & ' a str > > ;
93
93
@@ -236,9 +236,11 @@ impl<'a> NewCrate<'a> {
236
236
}
237
237
238
238
impl Crate {
239
- /// SQL filter with the `like` binary operator
240
- pub fn like_name ( name : & str ) -> LikeName < ' _ > {
241
- canon_crate_name ( crates:: name) . like ( canon_crate_name ( name) )
239
+ /// SQL filter with the `like` binary operator. Adds wildcards to the beginning and end to get
240
+ /// substring matches.
241
+ pub fn like_name ( name : & str ) -> LikeName {
242
+ let wildcard_name = format ! ( "%{}%" , name) ;
243
+ canon_crate_name ( crates:: name) . like ( canon_crate_name ( wildcard_name) )
242
244
}
243
245
/// SQL filter with the = binary operator
244
246
pub fn with_name ( name : & str ) -> WithName < ' _ > {
You can’t perform that action at this time.
0 commit comments