pat / riddle

Ruby Client API for Sphinx
MIT License
136 stars 68 forks source link

Riddle escape not working #57

Closed lephyrius closed 11 years ago

lephyrius commented 11 years ago

Im using:

gem 'riddle', github: 'pat/riddle' , ref: 'c1f8824ae9'
gem 'mysql2', '~> 0.3.12b5'

And TS3. I get this error:

Mysql2::Error: index game_core,game_delta: query error: no field 'terraria' found in schema

The search term is: "@terraria" Here is the relevant stack trace:

vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/connection.rb:58:in `query'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/connection.rb:58:in `query_all'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search/batch_inquirer.rb:16:in `results'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/middlewares/inquirer.rb:9:in `block in call'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/notifications.rb:123:in `block in instrument'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/notifications.rb:123:in `instrument'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search/context.rb:22:in `log'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/middlewares/inquirer.rb:8:in `call'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/middlewares/geographer.rb:9:in `call'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/middlewares/sphinxql.rb:11:in `call'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/middlewares/stale_id_filter.rb:10:in `call'
vendor/bundle/ruby/1.9.1/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in `call'
vendor/bundle/ruby/1.9.1/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in `call'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search.rb:58:in `populate'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search.rb:38:in `meta'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/masks/pagination_mask.rb:42:in `total_entries'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search.rb:96:in `block in method_missing'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search.rb:95:in `each'
vendor/bundle/ruby/1.9.1/gems/thinking-sphinx-3.0.0/lib/thinking_sphinx/search.rb:95:in `method_missing'

The code is simple:

ThinkingSphinx.search Riddle.escape(@search_term), options

I hope I put this at the right place if so I can create a new one in the TS issue tracker.

pat commented 11 years ago

What does a straight Riddle.escape('@terraria') output in the console?

lephyrius commented 11 years ago

Here is that:

1.9.3p327 :001 > Riddle.escape('@terraria')
 => "\\@terraria" 
pat commented 11 years ago

So it turns out Riddle.escape isn't quite as thorough as I'd hoped. For some reason, Sphinx requires certain characters to be double-escaped: @ becomes \\@.

You could write some code to handle that yourself, though I've found in my quick testing that running a query through Riddle.escape twice does the trick: Riddle.escape(Riddle.escape('@terraria'))

lephyrius commented 11 years ago

Is this something that will be fixed in future riddle? Then I might go with this as a temporary solution:

Riddle.escape(Riddle.escape('@terraria'))

Otherwise I might need to code my own cleaner. Is there any URL I can find the chars that need to be double escaped in sphinx?

pat commented 11 years ago

I've added Riddle::Query.escape - as the behaviour's different between the older binary protocol (Riddle.escape) and SphinxQL/MySQL41 protocol (Riddle::Query.escape). It's part of the new 1.5.5 release.