pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 470 forks source link

How to check if sphinx has warnings? #1098

Closed joshweir closed 6 years ago

joshweir commented 6 years ago
results = MyModel.search 'pancakes'

How to determine if the above search resulted in sphinx warnings, and collect these warnings? Calling sphinx directly I would call: SHOW WARNINGS;. My understanding is if the call errors, an exception will be raised: ThinkingSphinx::SphinxError - or an exception within the ThinkingSphinx module namespace - but I couldn't find anything in the documentation about warnings.

pat commented 6 years ago

Warnings aren't something that's been neatly mapped to TS at this point, but the way to get the data is something like the following:

results = MyModel.search "pancakes", :populate => true
# or, instead of the populate argument, do something that involves
# looking at the contents of results, thus forcing the query to Sphinx
# to take place.

warnings = nil
ThinkingSphinx::Connection.take { |connection|
  # This query operates on the context of the most recent search call
  warnings = connection.execute("SHOW WARNINGS").to_a
}
warnings