Created
November 18, 2010 05:24
-
-
Save mtodd/704654 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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