+5
-1
app/server.rb
+5
-1
app/server.rb
···
102
102
103
103
if params[:query]
104
104
query = params[:query].gsub('%', "\\%")
105
+
words = query.strip.split(/ +/)
105
106
106
107
likes = user.likes
107
108
.joins(:post)
108
109
.includes(:post => :user)
109
-
.where("text ILIKE ?", "%#{query}%")
110
+
.where(
111
+
(["(text ~* ?)"] * (words.length)).join(" AND "),
112
+
*(words.map { |x| "\\y#{x}\\y" })
113
+
)
110
114
.order('likes.time DESC, likes.id DESC')
111
115
.limit(PAGE_LIMIT)
112
116