Skip to content
Browse files

Don't swallow all Elasticsearch exceptions

  • Loading branch information...
1 parent 46a903c commit 045b52f724a7e95f25193e777958c9f5d056c257 @rwdaigle committed Oct 22, 2012
Showing with 16 additions and 15 deletions.
  1. +16 −15 app/models/gist.rb
View
31 app/models/gist.rb
@@ -47,13 +47,13 @@ def import(gh_gist)
end
end
+ # Clean me up!
def search(user, q)
log({ns: self, fn: __method__, query: q, measure: true, at: 'search'}, user)
- results = []
- begin
- results = with_cache(search_cache_key(user, q)) do
- if(!q.blank?)
- log({ns: self, fn: __method__, query: q, measure: true}, user) do
+ results = with_cache(search_cache_key(user, q)) do
+ if(!q.blank?)
+ log({ns: self, fn: __method__, query: q, measure: true}, user) do
+ begin
tire.search do
query { string q }
fields [:description, :url, :public, :gh_updated_at, :id, :comment_count, :'files.filename', :'files.language']
@@ -62,20 +62,21 @@ def search(user, q)
highlight :description, :options => { :tag => "<em>" }
size 15
end
+ rescue Tire::Search::SearchRequestFailed => e
+ if(e.message.include?("SearchParseException")) # Swallow malformed queries
+ return []
+ else
+ raise
+ end
end
- else
- []
end
+ else
+ []
end
-
- log({ns: self, fn: __method__, query: q, measure: true, at: 'search-results'}, {:'result-count' => results.size}, user)
-
- rescue Exception => e
- Airbrake.notify(e, :params => { :query => q }.merge(user.to_log))
- log_exception({ns: self, fn: __method__, query: q, measure: true, at: 'exception'}, user)
- ensure
- return results
end
+
+ log({ns: self, fn: __method__, query: q, measure: true, at: 'search-results'}, {:'result-count' => results.size}, user)
+ results
end
def reindex(gists = scoped)

0 comments on commit 045b52f

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