Commit 43c0f238754c1e2848a7fdee832e7f0006262937
1 parent
025c89ad
Exists in
master
and in
1 other branch
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.
Showing
4 changed files
with
14 additions
and
9 deletions
Show diff stats
README.md
... | ... | @@ -71,7 +71,7 @@ updates and notifications. |
71 | 71 | The list of requirements to install Errbit are: |
72 | 72 | |
73 | 73 | * Ruby 2.1.0 or higher |
74 | -* MongoDB 2.2.0 or higher | |
74 | +* MongoDB 2.6.0 or higher | |
75 | 75 | |
76 | 76 | Installation |
77 | 77 | ------------ |
... | ... | @@ -188,6 +188,8 @@ When upgrading Errbit, please run: |
188 | 188 | git pull origin master # assuming origin is the github.com/errbit/errbit repo |
189 | 189 | bundle install |
190 | 190 | rake db:migrate |
191 | +rake db:mongoid:create_indexes | |
192 | +rake db:mongoid:remove_undefined_indexes | |
191 | 193 | rake assets:precompile |
192 | 194 | ``` |
193 | 195 | ... | ... |
app/models/problem.rb
... | ... | @@ -42,6 +42,14 @@ class Problem |
42 | 42 | index :resolved_at => 1 |
43 | 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 | 53 | belongs_to :app |
46 | 54 | has_many :errs, :inverse_of => :problem, :dependent => :destroy |
47 | 55 | has_many :comments, :inverse_of => :err, :dependent => :destroy |
... | ... | @@ -231,13 +239,7 @@ class Problem |
231 | 239 | end |
232 | 240 | |
233 | 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 | 243 | end |
242 | 244 | |
243 | 245 | private | ... | ... |
spec/controllers/problems_controller_spec.rb
... | ... | @@ -138,7 +138,7 @@ describe ProblemsController, type: 'controller' do |
138 | 138 | end |
139 | 139 | |
140 | 140 | it "searches problems for given string" do |
141 | - get :search, :search => "Most important" | |
141 | + get :search, :search => "\"Most important\"" | |
142 | 142 | expect(controller.problems).to include(@problem1) |
143 | 143 | expect(controller.problems).to_not include(@problem2) |
144 | 144 | end | ... | ... |
spec/spec_helper.rb