aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2019-09-26 18:29:17 +0100
committerChristopher Baines <mail@cbaines.net>2019-09-26 18:29:17 +0100
commit465f262deddb30f542cd02407948f1fef9d68991 (patch)
tree0b31f2cb684d0762d4883deedd17aa24ae4136fc
parent759b75257ec981f52747da657e83f623d6880660 (diff)
downloaddata-service-465f262deddb30f542cd02407948f1fef9d68991.tar
data-service-465f262deddb30f542cd02407948f1fef9d68991.tar.gz
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.
-rw-r--r--guix-data-service/model/package.scm18
1 files changed, 17 insertions, 1 deletions
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))
"")))