Skip to content

Commit 675dd1a

Browse files
committed
In a crate search query, order the results by name in addition to rank
Since `ts_rank_cd()` doesn't provide unique ordering using it with `LIMIT ... OFFSET` will lead to inconsistent results, as is apparent from rust-lang#162. Add ordering by name to break the ties.
1 parent 436893c commit 675dd1a

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/krate.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,8 @@ pub fn index(req: &mut Request) -> CargoResult<Response> {
476476
plainto_tsquery($1) q,
477477
ts_rank_cd(textsearchable_index_col, q) rank
478478
WHERE q @@ textsearchable_index_col
479-
ORDER BY rank DESC LIMIT $2 OFFSET $3".to_string(),
479+
ORDER BY rank DESC, crates.name ASC
480+
LIMIT $2 OFFSET $3".to_string(),
480481
"SELECT COUNT(crates.*) FROM crates,
481482
plainto_tsquery($1) q
482483
WHERE q @@ textsearchable_index_col".to_string())

0 commit comments

Comments
 (0)