Browse Source

Fix result limit/offset mismatch

master
Dylan Baker 2 months ago
parent
commit
8d3e2a9c08
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      lib/search.rb

+ 6
- 4
lib/search.rb View File

@@ -1,8 +1,10 @@
1 1
 require 'sequel'
2 2
 
3
+RESULTS_PER_PAGE = 50
4
+
3 5
 def search(params)
4 6
   query = params[:q].strip
5
-  offset = (params[:page] - 1) * 10
7
+  offset = (params[:page] - 1) * RESULTS_PER_PAGE
6 8
   username = params[:username].strip
7 9
   from_date = params[:from_date].strip
8 10
   to_date = params[:to_date].strip
@@ -68,7 +70,7 @@ def search_threads(query, username, from_date, to_date, sort, offset)
68 70
       AND (created_at >= ? OR ? IS NULL)
69 71
       AND (created_at <= ? OR ? IS NULL)
70 72
     ORDER BY #{sort}
71
-    LIMIT 50
73
+    LIMIT #{RESULTS_PER_PAGE}
72 74
     OFFSET ?;
73 75
   SQL
74 76
 end
@@ -87,8 +89,8 @@ def search_posts(query, username, from_date, to_date, offset)
87 89
       AND ((LOWER(posts.creator) = LOWER(?)) OR (? = ''))
88 90
       AND (posts.created_at >= ? OR ? IS NULL)
89 91
       AND (posts.created_at <= ? OR ? IS NULL)
90
-    ORDER BY created_at DESC
91
-    LIMIT 50
92
+    ORDER BY posts.created_at DESC
93
+    LIMIT #{RESULTS_PER_PAGE}
92 94
     OFFSET ?;
93 95
   SQL
94 96
 end

Loading…
Cancel
Save