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:
01source someSource
02{
03  type   = mysql
04  sql_host  = localhost
05  sql_user  = root
06  sql_pass  = crack\!t
07  sql_db   = mffl
08  sql_port  = 3306
09 
10  sql_query  = \
11  select store_id+1000,store_id as id,'store' as type,title,title as data,body from store union \
12  select brand_id+2000,brand_id as id,'brand' as type,title,title as data,body from brand union \
13  select style_id+3000,style_id as id,'keyword' as type,title,title as data,body from keyword
14   
15  sql_attr_uint  = id
16  sql_attr_uint  = sort
17  sql_attr_string  = type
18  sql_field_string = title
19  sql_field_string = data
20}
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