Run /etc/init.d/postgresql start
before hitting the Run
button.
app/views/forem/forums/search.html.erb
<p>About <%= @rough_count %> results (<%= @duration.round(2) %> seconds)</p>
app/decorators/models/forem/topic_decorator.rb
Forem::Topic.class_eval do
include PgSearch
require 'benchmark'
pg_search_scope :search, against: [:subject], using: { tsearch: { dictionary: "english" } }, associated_against: { posts: [:text] }
module ResultsCount
def rough_count(count)
rounded_digits = String(count).size / 2
rounding_factor = 10 ** rounded_digits
(Integer(count) / rounding_factor) * rounding_factor
end
end
end
app/decorators/controllers/forem/topics_controller_decorator.rb
Forem::ForumsController.class_eval do
include ResultsCount
def search
@search = params[:keywords]
@topics = Forem::Topic.search(@search)
@duration = Benchmark.realtime do
@scope = PgSearch.multisearch(@search)
@results = @scope.page(params.fetch(:page, 1))
end
@rough_count = rough_count(@scope.count)
end
end