Permalink
Browse files

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.
  • Loading branch information...
stevecrozz committed Jul 23, 2015
1 parent 025c89a commit 43c0f238754c1e2848a7fdee832e7f0006262937
Showing with 14 additions and 9 deletions.
  1. +3 −1 README.md
  2. +9 −7 app/models/problem.rb
  3. +1 −1 spec/controllers/problems_controller_spec.rb
  4. +1 −0 spec/spec_helper.rb
View
@@ -71,7 +71,7 @@ updates and notifications.
The list of requirements to install Errbit are:
* Ruby 2.1.0 or higher
* MongoDB 2.2.0 or higher
* MongoDB 2.6.0 or higher
Installation
------------
@@ -188,6 +188,8 @@ When upgrading Errbit, please run:
git pull origin master # assuming origin is the github.com/errbit/errbit repo
bundle install
rake db:migrate
rake db:mongoid:create_indexes
rake db:mongoid:remove_undefined_indexes
rake assets:precompile
```
View
@@ -42,6 +42,14 @@ class Problem
index :resolved_at => 1
index :notices_count => 1
index({
error_class: "text",
where: "text",
message: "text",
app_name: "text",
environment: "text"
}, default_language: "english")
belongs_to :app
has_many :errs, :inverse_of => :problem, :dependent => :destroy
has_many :comments, :inverse_of => :err, :dependent => :destroy
@@ -231,13 +239,7 @@ def issue_type
end
def self.search(value)
any_of(
{:error_class => /#{value}/i},
{:where => /#{value}/i},
{:message => /#{value}/i},
{:app_name => /#{value}/i},
{:environment => /#{value}/i}
)
Problem.where({'$text' => {'$search' => value}})
end
private
@@ -138,7 +138,7 @@
end
it "searches problems for given string" do
get :search, :search => "Most important"
get :search, :search => "\"Most important\""
expect(controller.problems).to include(@problem1)
expect(controller.problems).to_not include(@problem2)
end
View
@@ -39,6 +39,7 @@
config.before(:each) do
Mongoid.default_client.database.collections.each(&:drop)
Mongoid::Tasks::Database.create_indexes
end
config.include Haml, type: :helper

0 comments on commit 43c0f23

Please sign in to comment.