14 require_once
'hce_node_api.inc.php';
19 defined(
'SPHINX_JSON_USE_BASE64') or define('SPHINX_JSON_USE_BASE64', 0);
23 defined('HCE_SPHINX_CMD_TYPE_ADMIN') or define('HCE_SPHINX_CMD_TYPE_ADMIN', 2);
27 defined('HCE_SPHINX_TIMEOUT') or define('HCE_SPHINX_TIMEOUT', 1500);
31 defined('HCE_SPHINX_ERROR_OK') or define('HCE_SPHINX_ERROR_OK', 0);
32 defined('HCE_SPHINX_ERROR_CREATE_MESSAGE') or define('HCE_SPHINX_ERROR_CREATE_MESSAGE', -100);
33 defined('HCE_SPHINX_ERROR_PARSE_RESPONSE') or define('HCE_SPHINX_ERROR_PARSE_RESPONSE', -101);
34 defined('HCE_SPHINX_ERROR_CREATE_CONNECTION') or define('HCE_SPHINX_ERROR_CREATE_CONNECTION', -102);
35 defined('HCE_SPHINX_ERROR_EMPTY_COMMAND') or define('HCE_SPHINX_ERROR_EMPTY_COMMAND', -103);
36 defined('HCE_SPHINX_ERROR_MESSAGE_NOT_FOUND') or define('HCE_SPHINX_ERROR_MESSAGE_NOT_FOUND', -104);
37 defined('HCE_SPHINX_ERROR_WRONG_PARAMETERS') or define('HCE_SPHINX_ERROR_WRONG_PARAMETERS', -105);
42 defined('HCE_SPHINX_CMD_INDEX_CREATE') or define('HCE_SPHINX_CMD_INDEX_CREATE', 'INDEX_CREATE');
43 defined('HCE_SPHINX_CMD_INDEX_CHECK') or define('HCE_SPHINX_CMD_INDEX_CHECK', 'INDEX_CHECK');
44 defined('HCE_SPHINX_CMD_INDEX_STORE_DATA_FILE') or define('HCE_SPHINX_CMD_INDEX_STORE_DATA_FILE', 'INDEX_STORE_DATA_FILE');
45 defined('HCE_SPHINX_CMD_INDEX_STORE_SCHEMA_FILE') or define('HCE_SPHINX_CMD_INDEX_STORE_SCHEMA_FILE', 'INDEX_STORE_SCHEMA_FILE');
46 defined('HCE_SPHINX_CMD_INDEX_REBUILD') or define('HCE_SPHINX_CMD_INDEX_REBUILD', 'INDEX_REBUILD');
47 defined('HCE_SPHINX_CMD_INDEX_SET_DATA_DIR') or define('HCE_SPHINX_CMD_INDEX_SET_DATA_DIR', 'INDEX_SET_DATA_DIR');
48 defined('HCE_SPHINX_CMD_INDEX_START') or define('HCE_SPHINX_CMD_INDEX_START', 'INDEX_START');
49 defined('HCE_SPHINX_CMD_INDEX_STOP') or define('HCE_SPHINX_CMD_INDEX_STOP', 'INDEX_STOP');
50 defined('HCE_SPHINX_CMD_INDEX_MERGE') or define('HCE_SPHINX_CMD_INDEX_MERGE', 'INDEX_MERGE');
51 defined('HCE_SPHINX_CMD_INDEX_DELETE_DATA_FILE') or define('HCE_SPHINX_CMD_INDEX_DELETE_DATA_FILE', 'INDEX_DELETE_DATA_FILE');
52 defined('HCE_SPHINX_CMD_INDEX_DELETE_SCHEMA_FILE') or define('HCE_SPHINX_CMD_INDEX_DELETE_SCHEMA_FILE', 'INDEX_DELETE_SCHEMA_FILE');
53 defined('HCE_SPHINX_CMD_INDEX_APPEND_DATA_FILE') or define('HCE_SPHINX_CMD_INDEX_APPEND_DATA_FILE', 'INDEX_APPEND_DATA_FILE');
54 defined('HCE_SPHINX_CMD_INDEX_DELETE_DOC') or define('HCE_SPHINX_CMD_INDEX_DELETE_DOC', 'INDEX_DELETE_DOC');
55 defined('HCE_SPHINX_CMD_INDEX_DELETE_DOC_NUMBER') or define('HCE_SPHINX_CMD_INDEX_DELETE_DOC_NUMBER', 'INDEX_DELETE_DOC_NUMBER');
56 defined('HCE_SPHINX_CMD_INDEX_PACK_DOC_DATA') or define('HCE_SPHINX_CMD_INDEX_PACK_DOC_DATA', 'INDEX_PACK_DOC_DATA');
57 defined('HCE_SPHINX_CMD_INDEX_REMOVE') or define('HCE_SPHINX_CMD_INDEX_REMOVE', 'INDEX_REMOVE');
58 defined('HCE_SPHINX_CMD_INDEX_COPY') or define('HCE_SPHINX_CMD_INDEX_COPY', 'INDEX_COPY');
59 defined('HCE_SPHINX_CMD_INDEX_RENAME') or define('HCE_SPHINX_CMD_INDEX_RENAME', 'INDEX_RENAME');
60 defined('HCE_SPHINX_CMD_INDEX_SET_CONFIG_VAR') or define('HCE_SPHINX_CMD_INDEX_SET_CONFIG_VAR', 'INDEX_SET_CONFIG_VAR');
61 defined('HCE_SPHINX_CMD_INDEX_MAX_DOC_ID') or define('HCE_SPHINX_CMD_INDEX_MAX_DOC_ID', 'INDEX_MAX_DOC_ID');
62 defined('HCE_SPHINX_CMD_INDEX_STATUS') or define('HCE_SPHINX_CMD_INDEX_STATUS', 'INDEX_STATUS');
63 defined('HCE_SPHINX_CMD_INDEX_STATUS_SEARCHD') or define('HCE_SPHINX_CMD_INDEX_STATUS_SEARCHD', 'INDEX_STATUS_SEARCHD');
64 defined('HCE_SPHINX_CMD_INDEX_DATA_LIST') or define('HCE_SPHINX_CMD_INDEX_DATA_LIST', 'INDEX_DATA_LIST');
65 defined('HCE_SPHINX_CMD_INDEX_CONNECT') or define('HCE_SPHINX_CMD_INDEX_CONNECT', 'INDEX_CONNECT');
66 defined('HCE_SPHINX_CMD_INDEX_DISCONNECT') or define('HCE_SPHINX_CMD_INDEX_DISCONNECT', 'INDEX_DISCONNECT');
71 defined('HCE_SPHINX_SEARCH_FIELD_Q') or define('HCE_SPHINX_SEARCH_FIELD_Q', 'q');
72 defined('HCE_SPHINX_SEARCH_FIELD_FILTERS') or define('HCE_SPHINX_SEARCH_FIELD_FILTERS', 'filters');
73 defined('HCE_SPHINX_SEARCH_FIELD_PARAMETERS') or define('HCE_SPHINX_SEARCH_FIELD_PARAMETERS', 'parameters');
74 defined('HCE_SPHINX_SEARCH_FIELD_QUERY_ID') or define('HCE_SPHINX_SEARCH_FIELD_QUERY_ID', 'queryId');
75 defined('HCE_SPHINX_SEARCH_FIELD_JSON_TYPE') or define('HCE_SPHINX_SEARCH_FIELD_JSON_TYPE', 'JsonType');
76 defined('HCE_SPHINX_SEARCH_FIELD_TYPE') or define('HCE_SPHINX_SEARCH_FIELD_TYPE', 'type');
77 defined('HCE_SPHINX_SEARCH_FIELD_DATA') or define('HCE_SPHINX_SEARCH_FIELD_DATA', 'data');
78 defined('HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS') or define('HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS', 'max_results');
79 defined('HCE_SPHINX_SEARCH_FIELD_SORT_MODE') or define('HCE_SPHINX_SEARCH_FIELD_SORT_MODE', 'sort_mode');
80 defined('HCE_SPHINX_SEARCH_FIELD_SORT_BY') or define('HCE_SPHINX_SEARCH_FIELD_SORT_BY', 'sort_by');
81 defined('HCE_SPHINX_SEARCH_FIELD_TYPE_MASK') or define('HCE_SPHINX_SEARCH_FIELD_TYPE_MASK', 'type_mask');
82 defined('HCE_SPHINX_SEARCH_FIELD_ID') or define('HCE_SPHINX_SEARCH_FIELD_ID', '
id');
83 defined('HCE_SPHINX_SEARCH_FIELD_ORDER') or define('HCE_SPHINX_SEARCH_FIELD_ORDER', 'order');
84 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_ALG') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_ALG', 'algorithm');
85 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_ALG_0') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_ALG_0', '0');
86 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_FIELDS') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_FIELDS', 'fields');
87 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_BY') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_BY', 'order_by');
88 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_BY_ASC') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_BY_ASC', '1');
89 defined('HCE_SPHINX_SEARCH_FIELD_ORDER_BY_DESC') or define('HCE_SPHINX_SEARCH_FIELD_ORDER_BY_DESC', '2');
90 defined('HCE_SPHINX_SEARCH_FIELD_OFFSET') or define('HCE_SPHINX_SEARCH_FIELD_OFFSET', 'offset');
91 defined('HCE_SPHINX_SEARCH_FIELD_LIMIT') or define('HCE_SPHINX_SEARCH_FIELD_LIMIT', 'limit');
92 defined('HCE_SPHINX_SEARCH_FIELD_CUTOFF') or define('HCE_SPHINX_SEARCH_FIELD_CUTOFF', 'cutoff');
93 defined('HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS') or define('HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS', 'return_jason_ext_fields');
94 defined('HCE_SPHINX_SEARCH_FIELD_FILTER_TYPE') or define('HCE_SPHINX_SEARCH_FIELD_FILTER_TYPE', 'type');
95 defined('HCE_SPHINX_SEARCH_FIELD_FILTER_ATTRIB') or define('HCE_SPHINX_SEARCH_FIELD_FILTER_ATTRIB', 'attribute');
96 defined('HCE_SPHINX_SEARCH_FIELD_FILTER_VALUES') or define('HCE_SPHINX_SEARCH_FIELD_FILTER_VALUES', 'values');
97 defined('HCE_SPHINX_SEARCH_FIELD_FILTER_EXCLUDE') or define('HCE_SPHINX_SEARCH_FIELD_FILTER_EXCLUDE', 'exclude');
98 for($i=0; $i<6; $i++){
99 defined(
'HCE_SPHINX_SEARCH_FIELD_ORDER_BY_'.$i) or define(
'HCE_SPHINX_SEARCH_FIELD_ORDER_BY_'.$i, $i.
'');
101 defined(
'HCE_SPHINX_SEARCH_FIELD_TTL') or define('HCE_SPHINX_SEARCH_FIELD_TTL', 'ttl');
102 defined('HCE_SPHINX_SEARCH_FIELD_TTL_DEFAULT') or define('HCE_SPHINX_SEARCH_FIELD_TTL_DEFAULT', '1000');
103 defined('HCE_SPHINX_SEARCH_FIELD_TIMEOUT') or define('HCE_SPHINX_SEARCH_FIELD_TIMEOUT', 'timeout');
104 defined('HCE_SPHINX_SEARCH_FIELD_TIMEOUT_DEFAULT') or define('HCE_SPHINX_SEARCH_FIELD_TIMEOUT_DEFAULT', '10000');
105 defined('HCE_SPHINX_SEARCH_FIELD_JSON_TYPE_DEFAULT') or define('HCE_SPHINX_SEARCH_FIELD_JSON_TYPE_DEFAULT', '15');
106 defined('HCE_SPHINX_SEARCH_FIELD_ERROR') or define('HCE_SPHINX_SEARCH_FIELD_ERROR', 'error');
111 defined('HCE_SPHINX_FO_SEARCH') or define('HCE_SPHINX_FO_SEARCH', '0');
112 defined('HCE_SPHINX_FO_INDEX') or define('HCE_SPHINX_FO_INDEX', '1');
113 defined('HCE_SPHINX_FO_ADMIN') or define('HCE_SPHINX_FO_ADMIN', '2');
114 defined('HCE_SPHINX_SEARCH_RET_TYPE_MI_INFO') or define('HCE_SPHINX_SEARCH_RET_TYPE_MI_INFO', 1);
115 defined('HCE_SPHINX_SEARCH_RET_TYPE_RI_INFO') or define('HCE_SPHINX_SEARCH_RET_TYPE_RI_INFO', 2);
116 defined('HCE_SPHINX_SEARCH_RET_TYPE_AT_INFO') or define('HCE_SPHINX_SEARCH_RET_TYPE_AT_INFO', 4);
117 defined('HCE_SPHINX_SEARCH_RET_TYPE_WI_INFO') or define('HCE_SPHINX_SEARCH_RET_TYPE_WI_INFO', 8);
118 defined('HCE_SPHINX_SEARCH_MAX_RESULTS_FROM_NODE_DEFAULT') or define('HCE_SPHINX_SEARCH_MAX_RESULTS_FROM_NODE_DEFAULT', '10');
119 defined('HCE_SPHINX_SEARCH_SORT_BY_DEFAULT') or define('HCE_SPHINX_SEARCH_SORT_BY_DEFAULT', '');
121 defined('HCE_SPHINX_SEARCH_SORT_MODE_NONE') or define('HCE_SPHINX_SEARCH_SORT_MODE_NONE', '0');
122 defined('HCE_SPHINX_SEARCH_SORT_MODE_ASC') or define('HCE_SPHINX_SEARCH_SORT_MODE_ASC', '1');
123 defined('HCE_SPHINX_SEARCH_SORT_MODE_DESC') or define('HCE_SPHINX_SEARCH_SORT_MODE_DESC', '2');
128 defined('HCE_SPHINX_SEARCH_RESULTS_MI') or define('HCE_SPHINX_SEARCH_RESULTS_MI', 'MI');
129 defined('HCE_SPHINX_SEARCH_RESULTS_AT') or define('HCE_SPHINX_SEARCH_RESULTS_AT', 'At');
130 defined('HCE_SPHINX_SEARCH_RESULTS_WI') or define('HCE_SPHINX_SEARCH_RESULTS_WI', 'WI');
131 defined('HCE_SPHINX_SEARCH_RESULTS_RI') or define('HCE_SPHINX_SEARCH_RESULTS_RI', 'RI');
132 defined('HCE_SPHINX_SEARCH_RESULTS_ID') or define('HCE_SPHINX_SEARCH_RESULTS_ID', 'Id');
133 defined('HCE_SPHINX_SEARCH_RESULTS_WEIGHT') or define('HCE_SPHINX_SEARCH_RESULTS_WEIGHT', 'W');
134 defined('HCE_SPHINX_SEARCH_RESULTS_SWEIGHT') or define('HCE_SPHINX_SEARCH_RESULTS_SWEIGHT', 'sw');
147 $ret=array(HCE_SPHINX_SEARCH_FIELD_ERROR=>HCE_SPHINX_ERROR_OK,
'response'=>null,
'hce_connection_array'=>null);
149 if(strlen($request_array[
'request'])>0){
150 if($connection_array===null){
152 $ret[
'hce_connection_array']=
hce_connection_create(array(
'host'=>HCE_HOST_ADMIN_DEFAULT,
'port'=>HCE_PORT_ADMIN_DEFAULT,
'type'=>HCE_CONNECTION_TYPE_ADMIN,
156 $ret[
'hce_connection_array']=$connection_array;
158 if(isset($ret[
'hce_connection_array'][HCE_SPHINX_SEARCH_FIELD_ERROR]) && $ret[
'hce_connection_array'][HCE_SPHINX_SEARCH_FIELD_ERROR]==HCE_PROTOCOL_ERROR_OK){
160 if(empty($request_array[
'id'])){
164 hce_message_send($ret[
'hce_connection_array'], array(
'id'=>$request_array[
'id'],
'body'=>$request_array[
'request']));
170 if($hce_responses[HCE_SPHINX_SEARCH_FIELD_ERROR]==HCE_PROTOCOL_ERROR_OK){
172 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=HCE_SPHINX_ERROR_MESSAGE_NOT_FOUND;
173 foreach($hce_responses[
'messages'] as $hce_message){
175 if($hce_message[
'id']==$request_array[
'id']){
176 $ret[
'response']=$hce_message[
'body'];
177 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=HCE_SPHINX_ERROR_OK;
182 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=$hce_responses[HCE_SPHINX_SEARCH_FIELD_ERROR];
186 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=HCE_SPHINX_ERROR_CREATE_CONNECTION;
188 if($connection_array===null){
194 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=HCE_SPHINX_ERROR_EMPTY_COMMAND;
208 return json_encode(array(
'command'=>$command,
'options'=>json_encode(
$parameters_array)));
218 return json_decode($response_body,
true);
228 return hce_admin_message_create(HCE_HANDLER_DATA_PROCESSOR_DATA, HCE_ADMIN_CMD_SPHINX, json_encode(array(
'type'=>HCE_SPHINX_CMD_TYPE_ADMIN,
'data'=>$admin_request_body)));
244 $ret=HCE_SPHINX_ERROR_CREATE_MESSAGE;
247 if($response[HCE_SPHINX_SEARCH_FIELD_ERROR]==HCE_SPHINX_ERROR_OK){
249 if($ret===null || !is_array($ret)){
251 $ret=HCE_SPHINX_ERROR_PARSE_RESPONSE;
254 $ret=$response[HCE_SPHINX_SEARCH_FIELD_ERROR];
272 $ret=array(HCE_SPHINX_SEARCH_FIELD_TYPE=>HCE_SPHINX_FO_SEARCH, HCE_SPHINX_SEARCH_FIELD_DATA=>null);
273 $ret1=array(HCE_SPHINX_SEARCH_FIELD_TYPE=>HCE_HANDLER_TYPE_SPHINX, HCE_SPHINX_SEARCH_FIELD_DATA=>null, HCE_SPHINX_SEARCH_FIELD_TTL=>HCE_SPHINX_SEARCH_FIELD_TTL_DEFAULT);
278 !isset(
$parameters_array[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][0][HCE_SPHINX_SEARCH_FIELD_QUERY_ID]) ||
279 !isset(
$parameters_array[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][1][HCE_SPHINX_SEARCH_FIELD_JSON_TYPE])
281 $ret=HCE_SPHINX_ERROR_WRONG_PARAMETERS;
283 if(SPHINX_JSON_USE_BASE64){
292 if(SPHINX_JSON_USE_BASE64){
293 $ret1[HCE_SPHINX_SEARCH_FIELD_DATA]=base64_encode(json_encode($ret));
295 $ret1[HCE_SPHINX_SEARCH_FIELD_DATA]=json_encode($ret);
299 return json_encode($ret);
317 $ret=array(HCE_SPHINX_SEARCH_FIELD_Q=>null,
318 HCE_SPHINX_SEARCH_FIELD_FILTERS=>null,
319 HCE_SPHINX_SEARCH_FIELD_PARAMETERS=>array(array(HCE_SPHINX_SEARCH_FIELD_QUERY_ID=>null),
320 array(HCE_SPHINX_SEARCH_FIELD_JSON_TYPE=>HCE_SPHINX_SEARCH_FIELD_JSON_TYPE_DEFAULT),
321 array(HCE_SPHINX_SEARCH_FIELD_SORT_BY=>HCE_SPHINX_SEARCH_SORT_BY_DEFAULT),
322 array(HCE_SPHINX_SEARCH_FIELD_ORDER_BY=>HCE_SPHINX_SEARCH_FIELD_ORDER_BY_0),
323 array(HCE_SPHINX_SEARCH_FIELD_OFFSET=>
'0'),
324 array(HCE_SPHINX_SEARCH_FIELD_LIMIT=>
'0'),
325 array(HCE_SPHINX_SEARCH_FIELD_CUTOFF=>
'0'),
326 array(HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS=>array()),
327 array(HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS=>HCE_SPHINX_SEARCH_MAX_RESULTS_FROM_NODE_DEFAULT),
328 array(HCE_SPHINX_SEARCH_FIELD_TIMEOUT=>HCE_SPHINX_SEARCH_FIELD_TIMEOUT_DEFAULT)
331 HCE_SPHINX_SEARCH_FIELD_ORDER=>array(array(HCE_SPHINX_SEARCH_FIELD_ORDER_ALG=>HCE_SPHINX_SEARCH_FIELD_ORDER_ALG_0), array(HCE_SPHINX_SEARCH_FIELD_ORDER_FIELDS=>array()))
335 if($parameters===null){
336 $parameters=array(HCE_SPHINX_SEARCH_FIELD_ID=>null, HCE_SPHINX_SEARCH_FIELD_TYPE_MASK=>null, HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS=>HCE_SPHINX_SEARCH_MAX_RESULTS_FROM_NODE_DEFAULT,
337 HCE_SPHINX_SEARCH_FIELD_SORT_MODE=>HCE_SPHINX_SEARCH_SORT_MODE_ASC, HCE_SPHINX_SEARCH_FIELD_SORT_BY=>HCE_SPHINX_SEARCH_SORT_BY_DEFAULT);
340 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_ID])){
344 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_TYPE_MASK])){
346 $parameters[HCE_SPHINX_SEARCH_FIELD_TYPE_MASK]=HCE_SPHINX_SEARCH_RET_TYPE_MI_INFO;
348 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_SORT_MODE])){
350 $parameters[HCE_SPHINX_SEARCH_FIELD_SORT_MODE]=HCE_SPHINX_SEARCH_SORT_MODE_ASC;
352 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_SORT_BY])){
354 $parameters[HCE_SPHINX_SEARCH_FIELD_SORT_BY]=HCE_SPHINX_SEARCH_SORT_BY_DEFAULT;
356 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_OFFSET])){
358 $parameters[HCE_SPHINX_SEARCH_FIELD_OFFSET]=
'0';
360 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_LIMIT])){
362 $parameters[HCE_SPHINX_SEARCH_FIELD_LIMIT]=
'0';
364 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_CUTOFF])){
366 $parameters[HCE_SPHINX_SEARCH_FIELD_CUTOFF]=
'0';
368 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS])){
370 $parameters[HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS]=array();
372 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_FILTERS])){
374 $parameters[HCE_SPHINX_SEARCH_FIELD_FILTERS]=array();
376 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_ORDER_BY])){
378 $parameters[HCE_SPHINX_SEARCH_FIELD_ORDER_BY]=HCE_SPHINX_SEARCH_FIELD_ORDER_BY_0;
386 if(!isset($parameters[HCE_SPHINX_SEARCH_FIELD_TIMEOUT])){
388 $parameters[HCE_SPHINX_SEARCH_FIELD_TIMEOUT]=HCE_SPHINX_SEARCH_FIELD_TIMEOUT_DEFAULT;
393 $order=array(array(HCE_SPHINX_SEARCH_FIELD_ORDER_ALG=>HCE_SPHINX_SEARCH_FIELD_ORDER_ALG_0),
394 array(HCE_SPHINX_SEARCH_FIELD_ORDER_FIELDS=>array()),
395 array(HCE_SPHINX_SEARCH_FIELD_ORDER_BY=>HCE_SPHINX_SEARCH_FIELD_ORDER_BY_DESC));
400 $ret[HCE_SPHINX_SEARCH_FIELD_FILTERS]=$parameters[HCE_SPHINX_SEARCH_FIELD_FILTERS];
403 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][0][HCE_SPHINX_SEARCH_FIELD_QUERY_ID]=$parameters[HCE_SPHINX_SEARCH_FIELD_ID];
404 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][1][HCE_SPHINX_SEARCH_FIELD_JSON_TYPE]=$parameters[HCE_SPHINX_SEARCH_FIELD_TYPE_MASK];
405 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][2][HCE_SPHINX_SEARCH_FIELD_SORT_BY]=$parameters[HCE_SPHINX_SEARCH_FIELD_SORT_BY];
406 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][3][HCE_SPHINX_SEARCH_FIELD_ORDER_BY]=$parameters[HCE_SPHINX_SEARCH_FIELD_ORDER_BY];
407 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][4][HCE_SPHINX_SEARCH_FIELD_OFFSET]=$parameters[HCE_SPHINX_SEARCH_FIELD_OFFSET];
408 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][5][HCE_SPHINX_SEARCH_FIELD_LIMIT]=$parameters[HCE_SPHINX_SEARCH_FIELD_LIMIT];
409 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][6][HCE_SPHINX_SEARCH_FIELD_CUTOFF]=$parameters[HCE_SPHINX_SEARCH_FIELD_CUTOFF];
410 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][7][HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS]=$parameters[HCE_SPHINX_SEARCH_FIELD_RET_EXT_FIELDS];
411 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][8][HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS]=$parameters[HCE_SPHINX_SEARCH_FIELD_MAX_RESULTS];
413 $ret[HCE_SPHINX_SEARCH_FIELD_PARAMETERS][9][HCE_SPHINX_SEARCH_FIELD_TIMEOUT]=$parameters[HCE_SPHINX_SEARCH_FIELD_TIMEOUT];
416 $ret[HCE_SPHINX_SEARCH_FIELD_ORDER]=
$order;
430 $ret=array(HCE_SPHINX_SEARCH_FIELD_ERROR=>0, HCE_SPHINX_SEARCH_FIELD_DATA=>null, HCE_SPHINX_SEARCH_FIELD_TYPE=>0, HCE_SPHINX_SEARCH_FIELD_TTL=>0);
432 $tmp=@json_decode($response_body,
true);
435 if(isset($tmp[HCE_SPHINX_SEARCH_FIELD_TYPE])){
436 $ret[HCE_SPHINX_SEARCH_FIELD_TYPE]=$tmp[HCE_SPHINX_SEARCH_FIELD_TYPE];
440 if(isset($tmp[HCE_SPHINX_SEARCH_FIELD_TTL])){
441 $ret[HCE_SPHINX_SEARCH_FIELD_TTL]=$tmp[HCE_SPHINX_SEARCH_FIELD_TTL];
445 if(isset($tmp[HCE_SPHINX_SEARCH_FIELD_TYPE]) && $tmp[HCE_SPHINX_SEARCH_FIELD_TYPE]==HCE_HANDLER_TYPE_SPHINX){
446 if(isset($tmp[HCE_SPHINX_SEARCH_FIELD_DATA])){
447 if(SPHINX_JSON_USE_BASE64){
448 $ret[HCE_SPHINX_SEARCH_FIELD_DATA]=json_decode(base64_decode($tmp[HCE_SPHINX_SEARCH_FIELD_DATA]),
true);
450 $ret[HCE_SPHINX_SEARCH_FIELD_DATA]=json_decode($tmp[HCE_SPHINX_SEARCH_FIELD_DATA],
true);
454 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=2;
458 $ret[HCE_SPHINX_SEARCH_FIELD_ERROR]=1;
474 if(isset($result[HCE_SPHINX_SEARCH_FIELD_DATA])){
475 if($struct_name==HCE_SPHINX_SEARCH_RESULTS_MI && isset($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_MI])){
478 $mi=$result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_MI];
479 if(isset($mi[$index])){
480 if($field_name==HCE_SPHINX_SEARCH_RESULTS_WEIGHT || $field_name==HCE_SPHINX_SEARCH_RESULTS_ID){
481 $ret=$mi[$index][$field_name];
483 foreach($mi[$index][HCE_SPHINX_SEARCH_RESULTS_AT] as $attribute){
484 if(isset($attribute[$field_name])){
485 $ret=$attribute[$field_name];
492 $ret=count($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_MI]);
494 }elseif($struct_name==HCE_SPHINX_SEARCH_RESULTS_RI && isset($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI])){
495 if($index!==null && isset($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI][$index][$field_name])){
496 $ret=$result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI][$index][$field_name];
498 $ret=count($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI]);
500 }elseif($struct_name==HCE_SPHINX_SEARCH_RESULTS_WI && $index!==null && isset($result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI][$index][HCE_SPHINX_SEARCH_RESULTS_WI])){
501 $ret=$result[HCE_SPHINX_SEARCH_FIELD_DATA][HCE_SPHINX_SEARCH_RESULTS_RI][$index][HCE_SPHINX_SEARCH_RESULTS_WI];