Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mtodd/704654 to your computer and use it in GitHub Desktop.
Save mtodd/704654 to your computer and use it in GitHub Desktop.
diff --git a/lib/thinking_sphinx.rb b/lib/thinking_sphinx.rb
index 5437116..b6dbff6 100644
--- a/lib/thinking_sphinx.rb
+++ b/lib/thinking_sphinx.rb
@@ -53,6 +53,16 @@ module ThinkingSphinx
end
end
+ # A SphinxError occurs when Sphinx responds with an error due to problematic
+ # queries or indexes.
+ class SphinxError < RuntimeError
+ attr_accessor :results
+ def initialize(message = nil, results = nil)
+ super(message)
+ self.results = results
+ end
+ end
+
# The current version of Thinking Sphinx.
#
# @return [String] The version number as a string
diff --git a/lib/thinking_sphinx/search.rb b/lib/thinking_sphinx/search.rb
index 7b62ef9..e4e36de 100644
--- a/lib/thinking_sphinx/search.rb
+++ b/lib/thinking_sphinx/search.rb
@@ -348,6 +348,14 @@ module ThinkingSphinx
runtime = Benchmark.realtime {
@results = client.query query, indexes, comment
}
+
+ unless @results[:error].nil?
+ log "Sphinx Daemon returned error: #{@results[:error]}", :error,
+ "Sphinx (#{sprintf("%f", runtime)}s)"
+ raise ThinkingSphinx::SphinxError,
+ @results[:error], @results unless @results[:error].nil?
+ end
+
log "Found #{@results[:total_found]} results", :debug,
"Sphinx (#{sprintf("%f", runtime)}s)"
rescue Errno::ECONNREFUSED => err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment