mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-07-05 09:22:21 +02:00
- merge r2451 from trunk: normalize behaviour of query search versus std search (now both return items already sorted and permission checked); also more optimized sql queries (in some cases)
git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2452 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -759,68 +759,35 @@ function ws_images_search($params, &$service)
|
||||
include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
|
||||
include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
|
||||
|
||||
$where_clauses = ws_std_image_sql_filter( $params );
|
||||
$order_by = ws_std_image_sql_order($params);
|
||||
$where_clauses = ws_std_image_sql_filter( $params, 'i.' );
|
||||
$order_by = ws_std_image_sql_order($params, 'i.');
|
||||
|
||||
if ( !empty($where_clauses) and !empty($order_by) )
|
||||
$super_order_by = false;
|
||||
if ( !empty($order_by) )
|
||||
{
|
||||
$page['super_order_by']=1; // quick_search_result might be faster
|
||||
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']);
|
||||
|
||||
global $image_ids; //needed for sorting by rank (usort)
|
||||
if ( ( !isset($search_result['as_is'])
|
||||
or !empty($where_clauses)
|
||||
or !empty($order_by) )
|
||||
and !empty($search_result['items']) )
|
||||
{
|
||||
$where_clauses[] = 'id IN ('
|
||||
.wordwrap(implode(', ', $search_result['items']), 80, "\n")
|
||||
.')';
|
||||
$where_clauses[] = get_sql_condition_FandF(
|
||||
array
|
||||
(
|
||||
'forbidden_categories' => 'category_id',
|
||||
'visible_categories' => 'category_id',
|
||||
'visible_images' => 'id'
|
||||
),
|
||||
'', true
|
||||
);
|
||||
$query = '
|
||||
SELECT DISTINCT id FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id=image_id
|
||||
WHERE '.implode('
|
||||
AND ', $where_clauses);
|
||||
if (!empty($order_by))
|
||||
{
|
||||
$query .= '
|
||||
ORDER BY '.$order_by;
|
||||
}
|
||||
$image_ids = array_from_query($query, 'id');
|
||||
global $ranks;
|
||||
$ranks = array_flip( $search_result['items'] );
|
||||
usort(
|
||||
$image_ids,
|
||||
create_function('$i1,$i2', 'global $ranks; return $ranks[$i1]-$ranks[$i2];')
|
||||
$search_result = get_quick_search_results($params['query'],
|
||||
$super_order_by,
|
||||
implode(',', $where_clauses)
|
||||
);
|
||||
unset ($ranks);
|
||||
}
|
||||
else
|
||||
{
|
||||
$image_ids = $search_result['items'];
|
||||
}
|
||||
|
||||
$image_ids = array_slice($image_ids,
|
||||
$params['page']*$params['per_page'],
|
||||
$params['per_page'] );
|
||||
$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 ('
|
||||
.wordwrap(implode(', ', $image_ids), 80, "\n")
|
||||
.')';
|
||||
WHERE id IN ('.implode(',', $image_ids).')';
|
||||
|
||||
$image_ids = array_flip($image_ids);
|
||||
$result = pwg_query($query);
|
||||
while ($row = mysql_fetch_assoc($result))
|
||||
{
|
||||
@@ -837,14 +804,10 @@ SELECT * FROM '.IMAGES_TABLE.'
|
||||
$image[$k] = $row[$k];
|
||||
}
|
||||
$image = array_merge( $image, ws_std_get_urls($row) );
|
||||
array_push($images, $image);
|
||||
$images[$image_ids[$image['id']]] = $image;
|
||||
}
|
||||
|
||||
$image_ids = array_flip($image_ids);
|
||||
usort(
|
||||
$images,
|
||||
create_function('$i1,$i2', 'global $image_ids; return $image_ids[$i1["id"]]-$image_ids[$i2["id"]];')
|
||||
);
|
||||
ksort($images, SORT_NUMERIC);
|
||||
$images = array_values($images);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user