Skip to content

Commit c7dc21a

Browse files
authored
Fix incorrect comparison operator in comment (#10375)
* controllers/krate/search: Enrich comments with `ORDER BY` information This would help contributors determine the appropriate comparison operator for their search queries. * controllers/krate/search: Fix incorrect comparison operator in comment
1 parent 55464bc commit c7dc21a

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

src/controllers/krate/search.rs

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -462,12 +462,18 @@ impl FilterParams {
462462
let conditions: Vec<BoxedCondition<'_>> = match *seek_payload {
463463
SeekPayload::Name(Name { id }) => {
464464
// Equivalent of:
465-
// `WHERE name > name'`
465+
// ```
466+
// WHERE name > name'
467+
// ORDER BY name ASC
468+
// ```
466469
vec![Box::new(crates::name.nullable().gt(crate_name_by_id(id)))]
467470
}
468471
SeekPayload::New(New { created_at, id }) => {
469472
// Equivalent of:
470-
// `WHERE (created_at = created_at' AND id < id') OR created_at < created_at'`
473+
// ```
474+
// WHERE (created_at = created_at' AND id < id') OR created_at < created_at'
475+
// ORDER BY created_at DESC, id DESC
476+
// ```
471477
vec![
472478
Box::new(
473479
crates::created_at
@@ -480,7 +486,10 @@ impl FilterParams {
480486
}
481487
SeekPayload::RecentUpdates(RecentUpdates { updated_at, id }) => {
482488
// Equivalent of:
483-
// `WHERE (updated_at = updated_at' AND id < id') OR updated_at < updated_at'`
489+
// ```
490+
// WHERE (updated_at = updated_at' AND id < id') OR updated_at < updated_at'
491+
// ORDER BY updated_at DESC, id DESC
492+
// ```
484493
vec![
485494
Box::new(
486495
crates::updated_at
@@ -497,10 +506,16 @@ impl FilterParams {
497506
}) => {
498507
// Equivalent of:
499508
// for recent_downloads is not None:
500-
// `WHERE (recent_downloads = recent_downloads' AND id < id')
501-
// OR (recent_downloads < recent_downloads' OR recent_downloads IS NULL)`
509+
// ```
510+
// WHERE (recent_downloads = recent_downloads' AND id < id')
511+
// OR (recent_downloads < recent_downloads' OR recent_downloads IS NULL)
512+
// ORDER BY recent_downloads DESC NULLS LAST, id DESC
513+
// ```
502514
// for recent_downloads is None:
503-
// `WHERE (recent_downloads IS NULL AND id < id')`
515+
// ```
516+
// WHERE (recent_downloads IS NULL AND id < id')
517+
// ORDER BY recent_downloads DESC NULLS LAST, id DESC
518+
// ```
504519
match recent_downloads {
505520
Some(dl) => {
506521
vec![
@@ -530,7 +545,10 @@ impl FilterParams {
530545
}
531546
SeekPayload::Downloads(Downloads { downloads, id }) => {
532547
// Equivalent of:
533-
// `WHERE (downloads = downloads' AND id < id') OR downloads < downloads'`
548+
// ```
549+
// WHERE (downloads = downloads' AND id < id') OR downloads < downloads'
550+
// ORDER BY downloads DESC, id DESC
551+
// ```
534552
vec![
535553
Box::new(
536554
crate_downloads::downloads
@@ -543,8 +561,10 @@ impl FilterParams {
543561
}
544562
SeekPayload::Query(Query { exact_match, id }) => {
545563
// Equivalent of:
546-
// `WHERE (exact_match = exact_match' AND name < name') OR exact_match <
547-
// exact_match'`
564+
// ```
565+
// WHERE (exact_match = exact_match' AND name > name') OR exact_match < exact_match'
566+
// ORDER BY exact_match DESC, NAME ASC
567+
// ```
548568
let q_string = self.q_string.as_ref().expect("q_string should not be None");
549569
let name_exact_match = Crate::with_name(q_string);
550570
vec![
@@ -563,9 +583,12 @@ impl FilterParams {
563583
id,
564584
}) => {
565585
// Equivalent of:
566-
// `WHERE (exact_match = exact_match' AND rank = rank' AND name > name')
586+
// ```
587+
// WHERE (exact_match = exact_match' AND rank = rank' AND name > name')
567588
// OR (exact_match = exact_match' AND rank < rank')
568-
// OR exact_match < exact_match'`
589+
// OR exact_match < exact_match'
590+
// ORDER BY exact_match DESC, rank DESC, name ASC
591+
// ```
569592
let q_string = self.q_string.as_ref().expect("q_string should not be None");
570593
let q = sql::<TsQuery>("plainto_tsquery('english', ")
571594
.bind::<Text, _>(q_string.as_str())

0 commit comments

Comments
 (0)