mirror of
https://github.com/basecamp/once-campfire.git
synced 2026-10-07 07:10:10 +09:00
edaab3e5d1
Search showed the last 100 matches by created_at, so SQLite collected every message containing the words and sorted them before keeping a page. A common word in a large account meant sorting most of its history on every search. Ordering by the full-text index's rowid, which is the message id, lets SQLite walk the index from the newest match and stop once the page is full. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JVFo3Lt9T8M5NR7KxVvsZ2
33 lines
711 B
Ruby
33 lines
711 B
Ruby
class SearchesController < ApplicationController
|
|
before_action :set_messages
|
|
|
|
def index
|
|
@query = query if query.present?
|
|
@recent_searches = Current.user.searches.ordered
|
|
@return_to_room = last_room_visited
|
|
end
|
|
|
|
def create
|
|
Current.user.searches.record(query)
|
|
redirect_to searches_url(q: query)
|
|
end
|
|
|
|
def clear
|
|
Current.user.searches.destroy_all
|
|
redirect_to searches_url
|
|
end
|
|
|
|
private
|
|
def set_messages
|
|
if query.present?
|
|
@messages = Current.user.reachable_messages.search(query).with_presentation.last_page_of_matches(100)
|
|
else
|
|
@messages = Message.none
|
|
end
|
|
end
|
|
|
|
def query
|
|
params[:q]&.gsub(/[^[:word:]]/, " ")
|
|
end
|
|
end
|