Mar 17, 2011

f Comment

How Do You Escape Special Characters In Sphinx Configuration?

Amazon My database password contains bang character (!) and when I specify the password in sphinx config I keep getting errors. Why?

SOLUTION
It goes without saying that it must have something to do with escaping special characters! How nasty is that? And the Sphinx user manual does not really mention how to deal with special characters. Anyway the solution is that you simply use backslash (\) to escape special characters. Suppose my host is localhost and user name is root and password is crack!t, then here's a typical 'source' block in sphinx configuration:
source someSource
{
  type   = mysql
  sql_host  = localhost
  sql_user  = root
  sql_pass  = crack\!t
  sql_db   = mffl
  sql_port  = 3306 

  sql_query  = \
  select store_id+1000,store_id as id,'store' as type,title,title as data,body from store union \
  select brand_id+2000,brand_id as id,'brand' as type,title,title as data,body from brand union \
  select style_id+3000,style_id as id,'keyword' as type,title,title as data,body from keyword 
  
  sql_attr_uint  = id
  sql_attr_uint  = sort
  sql_attr_string  = type
  sql_field_string = title
  sql_field_string = data
}
Note how I escape the exclamation mark in sql_pass with a backslash (\) haha!

If you have any questions let me know and I will do my best to help you!
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael