summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorunwox <me@unwox.com>2024-10-23 23:46:42 +0600
committerunwox <me@unwox.com>2024-10-23 23:46:42 +0600
commit8daa0b56f8e53c34706870462b346749b824a9a7 (patch)
treefb9d0c919e1dbe887a0e8061d12d74b0107229f9 /bin
parent7d8280fc4890f5336eceb8c2fe59fa695c3c756a (diff)
shuffle query results so sites of the results are not grouped
Diffstat (limited to 'bin')
-rw-r--r--bin/serve.fnl9
1 files changed, 5 insertions, 4 deletions
diff --git a/bin/serve.fnl b/bin/serve.fnl
index 0c5ca6d..98e0aac 100644
--- a/bin/serve.fnl
+++ b/bin/serve.fnl
@@ -139,7 +139,7 @@
price_per AS \"price-per\",
year
FROM products
- ORDER BY RANDOM()
+ ORDER BY ROW_NUMBER() over (PARTITION BY site ORDER BY ROWID)
LIMIT ?"
[limit])))
@@ -186,7 +186,7 @@
(table.insert where-conds "products.price <= ?"))
(table.insert where-vars max-price))
- (local where-sql
+ (local where-sql
(if (< 0 (# where-conds))
(.. "AND " (array.join where-conds "\nAND "))
""))
@@ -209,7 +209,7 @@
(luna.db.query*
db
(string.format
- "SELECT highlight(search, 0, '<i>', '</i>') AS \"title\",
+ "SELECT products.title,
products.site,
products.description,
products.image,
@@ -225,7 +225,8 @@
LEFT JOIN product_tags ON product_tags.product = products.url
WHERE search.`table` = 'products'
%s
- ORDER BY rank
+ ORDER BY ROW_NUMBER() over (PARTITION BY products.site ORDER BY products.ROWID),
+ rank
LIMIT 48 OFFSET ?" where-sql)
(array.concat where-vars [(* (- page 1) 48)])))
:total (if (< 0 (# total))