/** * Returns an array of 'items' corresponding to the search id. * It can be either a quick search or a regular search. * * @param int $search_id * @param bool $super_order_by * @param string $images_where optional aditional restriction on images table * @return array */ function get_search_results($search_id, $super_order_by, $images_where = '') { $search = get_search_array($search_id); if (!isset($search['q'])) { $result['items'] = get_regular_search_results($search, $images_where); return $result; } else { return get_quick_search_results($search['q'], array('super_order_by' => $super_order_by, 'images_where' => $images_where)); } }
/** * API method * Returns a list of elements corresponding to a query search * @param mixed[] $params * @option string query * @option int per_page * @option int page * @option string order (optional) */ function ws_images_search($params, $service) { include_once PHPWG_ROOT_PATH . 'include/functions_search.inc.php'; $images = array(); $where_clauses = ws_std_image_sql_filter($params, 'i.'); $order_by = ws_std_image_sql_order($params, 'i.'); $super_order_by = false; if (!empty($order_by)) { global $conf; $conf['order_by'] = 'ORDER BY ' . $order_by; $super_order_by = true; // quick_search_result might be faster } $search_result = get_quick_search_results($params['query'], array('super_order_by' => $super_order_by, 'images_where' => implode(' AND ', $where_clauses))); $image_ids = array_slice($search_result['items'], $params['page'] * $params['per_page'], $params['per_page']); if (count($image_ids)) { $query = ' SELECT * FROM ' . IMAGES_TABLE . ' WHERE id IN (' . implode(',', $image_ids) . ') ;'; $result = pwg_query($query); $image_ids = array_flip($image_ids); while ($row = pwg_db_fetch_assoc($result)) { $image = array(); foreach (array('id', 'width', 'height', 'hit') as $k) { if (isset($row[$k])) { $image[$k] = (int) $row[$k]; } } foreach (array('file', 'name', 'comment', 'date_creation', 'date_available') as $k) { $image[$k] = $row[$k]; } $image = array_merge($image, ws_std_get_urls($row)); $images[$image_ids[$image['id']]] = $image; } ksort($images, SORT_NUMERIC); $images = array_values($images); } return array('paging' => new PwgNamedStruct(array('page' => $params['page'], 'per_page' => $params['per_page'], 'count' => count($images), 'total_count' => count($search_result['items']))), 'images' => new PwgNamedArray($images, 'image', ws_std_get_image_xml_attributes())); }