From 465f262deddb30f542cd02407948f1fef9d68991 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 26 Sep 2019 18:29:17 +0100 Subject: Tweak the textual search to rank exact name matches higher Previously, if you searched for packages like Ruby or Guile, the actual Ruby and Guile packages would be low in the rankings, as the terms Ruby or Guile don't appear much in the descriptions. Therefore, change the ordering to make these exact matches appear higher up. --- guix-data-service/model/package.scm | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/guix-data-service/model/package.scm b/guix-data-service/model/package.scm index 49ebab0..b3327ca 100644 --- a/guix-data-service/model/package.scm +++ b/guix-data-service/model/package.scm @@ -118,7 +118,23 @@ WHERE packages.id IN ( WHERE guix_revisions.commit = $1 ) AND to_tsvector(name || ' ' || synopsis) @@ plainto_tsquery($2) -ORDER BY ts_rank_cd(to_tsvector(name || ' ' || synopsis), plainto_tsquery($2)) DESC" +ORDER BY ( + ts_rank_cd( + to_tsvector(name), + plainto_tsquery($2), + 2 -- divide rank by the document length + ) + * 4 -- as the name is more important + ) + + ts_rank_cd( + to_tsvector(synopsis), + plainto_tsquery($2), + 32 -- divide the rank by itself + 1 + ) DESC, + -- to make the order stable + name, + version +" (if limit-results (string-append "\nLIMIT " (number->string limit-results)) ""))) -- cgit v1.2.3