mysql - How to show sphinx search result with php? -
i installed sphinx search on localhost (wamp). want show results example in 1 simple html table. tried connect php sphinx search, think done it, when printed result 0.... not true. not understand in query part need put word want search? tried search in command windows, working, not know how show on web page. , want use mysql. php looks this:
require ( "sphinx/api/sphinxapi.php" ); $s = new sphinxclient; $s->setserver("localhost", 9306); $s->setmatchmode(sph_match_any); $s->setmaxquerytime(3); $result = $s->query("test"); var_dump($result);
here mini conf file:
source src1 { type = mysql sql_host = localhost sql_user = root sql_pass = sql_db = test sql_port = 3306 # optional, default 3306 sql_query = \ select id, group_id, unix_timestamp(date_added) date_added, title, content \ documents sql_attr_uint = group_id sql_attr_timestamp = date_added sql_query_info = select * documents id=$id } index test1 { source = src1 path = c:/wamp/www/sphinx/data/test1 docinfo = extern charset_type = sbcs } indexer { mem_limit = 32m } searchd { listen = 9312 listen = 9306:mysql41 log = c:/wamp/www/sphinx/log/searchd.log query_log = c:/wamp/www/sphinx/log/query.log read_timeout = 5 max_children = 30 pid_file = c:/wamp/www/sphinx/log/searchd.pid max_matches = 1000 seamless_rotate = 1 preopen_indexes = 1 unlink_old = 1 workers = threads # rt work binlog_path = c:/wamp/www/sphinx/data }
your connection , query might this:
$link = mysql_connect ( '127.0.0.1:9306', '', '' ); $db_selected = mysql_select_db ( 'main', $link );
and mysql queries (as them normally)
$sql = "select * main match('$queryterm') order date desc limit 0,50"; $result = mysql_query ( $sql );
or can retrieve meta info if want(see sphinx document meta)
$metainfo = mysql_query('show meta'); while ( $meta = mysql_fetch_array ( $metainfo ) ) { $srchmeta[]=$meta; //or whatever want here }
Comments
Post a Comment