Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'add-elasticsearch-indexing'

Conflicts:
	Gemfile.lock
	app/views/shared/_navigation.html.haml
  • Loading branch information...
commit 15d998abdb2db7be3ff1b6ba51773085de6f791e 2 parents af65165 + d44b887
@elandesign elandesign authored
View
1  Gemfile
@@ -4,6 +4,7 @@ gem 'rails', '3.2.6'
gem 'nokogiri'
gem 'mongoid', '~> 2.4.10'
+gem 'tire'
gem 'haml'
gem 'htmlentities', "~> 4.3.0"
View
8 Gemfile.lock
@@ -86,6 +86,7 @@ GEM
libxml-ruby (~> 2.0)
has_scope (0.5.1)
hashie (1.2.0)
+ hashr (0.0.21)
hike (1.2.1)
hoptoad_notifier (2.4.11)
activesupport
@@ -246,6 +247,12 @@ GEM
rack (>= 1.0.0)
thor (0.15.2)
tilt (1.3.3)
+ tire (0.4.2)
+ activemodel (>= 3.0)
+ hashr (~> 0.0.19)
+ multi_json (~> 1.0)
+ rake
+ rest-client (~> 1.6)
treetop (1.4.10)
polyglot
polyglot (>= 0.3.1)
@@ -313,6 +320,7 @@ DEPENDENCIES
ruby-fogbugz
therubyracer
thin
+ tire
twitter-bootstrap-rails
uglifier (>= 1.0.3)
unicorn
View
20 app/assets/stylesheets/errbit.css
@@ -122,6 +122,26 @@ a.action { float: right; font-size: 0.9em;}
-webkit-border-top-right-radius: 12px;
border: 1px solid #bbb;
}
+#nav-bar li.search {
+ background-color: transparent;
+ border: none;
+ border-top-left-radius: 0;
+ border-top-right-radius: 0;
+ -moz-border-top-left-radius: 0;
+ -moz-border-top-right-radius: 0;
+ -webkit-border-top-left-radius: 0;
+ -webkit-border-top-right-radius: 0;
+}
+#nav-bar li.search input {
+ padding: 0 5px;
+ margin: 0;
+ width: auto;
+ border: none;
+ line-height: 34px;
+ position: relative;
+ top: -15px;
+ left: 15px;
+}
#nav-bar li.active {
border-color: #fff;
background: #FFF url(images/button-bg.png) 0 -2px repeat-x;
View
15 app/controllers/errs_controller.rb
@@ -1,8 +1,8 @@
class ErrsController < ApplicationController
include ActionView::Helpers::TextHelper
- before_filter :find_app, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several]
- before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several]
+ before_filter :find_app, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search]
+ before_filter :find_problem, :except => [:index, :all, :destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several, :search]
before_filter :find_selected_problems, :only => [:destroy_several, :resolve_several, :unresolve_several, :merge_several, :unmerge_several]
before_filter :set_sorting_params, :only => [:index, :all]
before_filter :set_tracker_params, :only => [:create_issue]
@@ -20,6 +20,17 @@ def index
end
end
+ def search
+ raise "Elastic Search is not enabled" unless Errbit::Config.elasticsearch_enabled
+ visible_apps = current_user.admin? ? App.all : current_user.apps
+ if params[:app_id]
+ visible_apps = visible_apps.where(:_id => params[:app_id])
+ end
+ @search = Search.new(params, :apps => visible_apps.map(&:id))
+ @problems = @search.results
+ @selected_problems = params[:problems] || []
+ end
+
def all
app_scope = current_user.admin? ? App.all : current_user.apps
@problems = Problem.for_apps(app_scope).ordered_by(@sort, @order).page(params[:page]).per(current_user.per_page)
View
10 app/helpers/application_helper.rb
@@ -82,6 +82,16 @@ def create_percentage_table_from_tallies(tallies, options={})
render "errs/tally_table", :rows => rows
end
+ def search_path
+ if params[:controller] == 'apps' && params[:action] == 'show'
+ search_app_errs_path(:app_id => params[:id])
+ elsif params[:app_id]
+ search_app_errs_path(:app_id => params[:app_id])
+ else
+ search_errs_path
+ end
+ end
+
private
def total_from_tallies(tallies)
tallies.values.inject(0) {|sum, n| sum + n}
View
1  app/helpers/sort_helper.rb
@@ -2,6 +2,7 @@
module SortHelper
def link_for_sort(name, field=nil)
+ return name if params[:action] == 'search'
field ||= name.underscore
current = (@sort == field)
order = (current && (@order == "asc")) ? "desc" : "asc"
View
18 app/models/problem.rb
@@ -42,6 +42,24 @@ class Problem
scope :ordered, order_by(:last_notice_at.desc)
scope :for_apps, lambda {|apps| where(:app_id.in => apps.all.map(&:id))}
+ include Tire::Model::Search
+ mapping do
+ indexes :app_id, :index => :not_analyzed
+ indexes :app_name, :index => :not_analyzed
+ indexes :error_class, :analyzer => :snowball
+ indexes :where, :analyzer => :snowball
+ indexes :message, :analyzer => :snowball
+ indexes :environment, :index => :not_analyzed
+ indexes :resolved, :index => :not_analyzed
+ indexes :last_notice_at, :index => :not_analyzed
+ end
+
+ after_save :update_index, :if => lambda { Errbit::Config.elasticsearch_enabled }
+ after_destroy :update_index, :if => lambda { Errbit::Config.elasticsearch_enabled }
+
+ def update_index
+ tire.update_index
+ end
def self.in_env(env)
env.present? ? where(:environment => env) : scoped
View
30 app/models/search.rb
@@ -0,0 +1,30 @@
+class Search
+
+ attr_reader :terms, :show_resolved
+
+ def initialize(params, options = {})
+ @apps = options[:apps] || []
+ @terms = params[:terms]
+ @show_resolved = params[:resolved].present?
+ build_search
+ end
+
+ def results
+ @search.results
+ end
+
+ private
+
+ def build_search
+ @search = Tire.search('problems', :load => true) do |search|
+ search.query do |query|
+ query.boolean do |it|
+ it.must { |have| have.terms :app_id, @apps }
+ it.must { |have| have.string "#{self.terms}*" }
+ it.must { |have| have.term :resolved, false } unless self.show_resolved
+ end
+ end
+ end
+ end
+
+end
View
7 app/views/errs/search.html.haml
@@ -0,0 +1,7 @@
+- content_for :title, 'Search Results'
+- content_for :action_bar do
+ - if params[:resolved].present?
+ = link_to 'hide resolved', params.except(:resolved), {:class => 'button'}
+ - else
+ = link_to 'show resolved', params.merge({:resolved => true}), {:class => 'button'}
+= render 'table', :errs => @problems
View
5 app/views/shared/_navigation.html.haml
@@ -18,5 +18,6 @@
%li.divider-vertical
- if user_signed_in? && current_user.admin?
%li.users{:class => active_if_here(:users)}= link_to 'Users', users_path
- %form{:class => 'navbar-search pull-left'}
- %input{:type => 'text', :class => 'search-query span2', :placeholder => 'Search'}
+ - if Errbit::Config.elasticsearch_enabled
+ = form_tag search_path, {:method => :get, :class => 'navbar-search pull-left'} do
+ %input{:type => 'text', :class => 'search-query span2', :placeholder => 'Search', :name => 'terms', :value => @search.present? ? @search.terms : ''}
View
4 config/config.example.yml
@@ -39,6 +39,10 @@ user_has_username: false
# but you want to leave a short comment.
allow_comments_with_issue_tracker: true
+# Index any problems in ElasticSearch
+elasticsearch_enabled: true
+elasticsearch_url: http://localhost:9200
+
# Setup your deploy options for capistrano.
deployment:
hosts:
View
6 config/initializers/tire.rb
@@ -0,0 +1,6 @@
+if Errbit::Config.elasticsearch_enabled
+ Tire.configure do
+ url Errbit::Config.elasticsearch_url
+ logger Rails.root.join("log", "elasticsearch.#{Rails.env}.log") unless Rails.env.production?
+ end
+end
View
5 config/routes.rb
@@ -21,6 +21,7 @@
post :merge_several
post :unmerge_several
get :all
+ get :search
end
end
@@ -35,6 +36,10 @@
post :create_issue
delete :unlink_issue
end
+
+ collection do
+ get :search
+ end
end
resources :deploys, :only => [:index]
View
5 spec/spec_helper.rb
@@ -21,6 +21,10 @@
config.run_all_when_everything_filtered = true
config.alias_example_to :fit, :focused => true
+ config.before(:all) do
+ Problem.index_name('test_' + Problem.model_name.plural)
+ end
+
config.before(:each) do
DatabaseCleaner[:mongoid].strategy = :truncation
DatabaseCleaner.clean
@@ -28,4 +32,5 @@
config.include WebMock::API
end
+Errbit::Config.elasticsearch_enabled = false
OmniAuth.config.test_mode = true

0 comments on commit 15d998a

Please sign in to comment.
Something went wrong with that request. Please try again.