Commit 43c0f238754c1e2848a7fdee832e7f0006262937

Authored by Stephen Crosby
1 parent 025c89ad
Exists in master and in 1 other branch production

use full-text search for problem search

This necessitates a mongo dependency upgrade because full-text searching
was not available until mongo2.4 and not considered production-ready
until mongo2.6. But this drastically improves search performance as the
database grows.
@@ -71,7 +71,7 @@ updates and notifications. @@ -71,7 +71,7 @@ updates and notifications.
71 The list of requirements to install Errbit are: 71 The list of requirements to install Errbit are:
72 72
73 * Ruby 2.1.0 or higher 73 * Ruby 2.1.0 or higher
74 -* MongoDB 2.2.0 or higher 74 +* MongoDB 2.6.0 or higher
75 75
76 Installation 76 Installation
77 ------------ 77 ------------
@@ -188,6 +188,8 @@ When upgrading Errbit, please run: @@ -188,6 +188,8 @@ When upgrading Errbit, please run:
188 git pull origin master # assuming origin is the github.com/errbit/errbit repo 188 git pull origin master # assuming origin is the github.com/errbit/errbit repo
189 bundle install 189 bundle install
190 rake db:migrate 190 rake db:migrate
  191 +rake db:mongoid:create_indexes
  192 +rake db:mongoid:remove_undefined_indexes
191 rake assets:precompile 193 rake assets:precompile
192 ``` 194 ```
193 195
app/models/problem.rb
@@ -42,6 +42,14 @@ class Problem @@ -42,6 +42,14 @@ class Problem
42 index :resolved_at => 1 42 index :resolved_at => 1
43 index :notices_count => 1 43 index :notices_count => 1
44 44
  45 + index({
  46 + error_class: "text",
  47 + where: "text",
  48 + message: "text",
  49 + app_name: "text",
  50 + environment: "text"
  51 + }, default_language: "english")
  52 +
45 belongs_to :app 53 belongs_to :app
46 has_many :errs, :inverse_of => :problem, :dependent => :destroy 54 has_many :errs, :inverse_of => :problem, :dependent => :destroy
47 has_many :comments, :inverse_of => :err, :dependent => :destroy 55 has_many :comments, :inverse_of => :err, :dependent => :destroy
@@ -231,13 +239,7 @@ class Problem @@ -231,13 +239,7 @@ class Problem
231 end 239 end
232 240
233 def self.search(value) 241 def self.search(value)
234 - any_of(  
235 - {:error_class => /#{value}/i},  
236 - {:where => /#{value}/i},  
237 - {:message => /#{value}/i},  
238 - {:app_name => /#{value}/i},  
239 - {:environment => /#{value}/i}  
240 - ) 242 + Problem.where({'$text' => {'$search' => value}})
241 end 243 end
242 244
243 private 245 private
spec/controllers/problems_controller_spec.rb
@@ -138,7 +138,7 @@ describe ProblemsController, type: 'controller' do @@ -138,7 +138,7 @@ describe ProblemsController, type: 'controller' do
138 end 138 end
139 139
140 it "searches problems for given string" do 140 it "searches problems for given string" do
141 - get :search, :search => "Most important" 141 + get :search, :search => "\"Most important\""
142 expect(controller.problems).to include(@problem1) 142 expect(controller.problems).to include(@problem1)
143 expect(controller.problems).to_not include(@problem2) 143 expect(controller.problems).to_not include(@problem2)
144 end 144 end
spec/spec_helper.rb
@@ -39,6 +39,7 @@ RSpec.configure do |config| @@ -39,6 +39,7 @@ RSpec.configure do |config|
39 39
40 config.before(:each) do 40 config.before(:each) do
41 Mongoid.default_client.database.collections.each(&:drop) 41 Mongoid.default_client.database.collections.each(&:drop)
  42 + Mongoid::Tasks::Database.create_indexes
42 end 43 end
43 44
44 config.include Haml, type: :helper 45 config.include Haml, type: :helper