Ignore:
Timestamp:
Jul 23, 2008, 2:56:22 AM (16 years ago)
Author:
rvelices
Message:
  • 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)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/ws_functions.inc.php

    r2435 r2451  
    824824  $order_by = ws_std_image_sql_order($params, 'i.');
    825825
     826  $super_order_by = false;
    826827  if ( !empty($order_by) )
    827828  {
    828829    global $conf;
    829830    $conf['order_by'] = 'ORDER BY '.$order_by;
    830     $page['super_order_by']=1; // quick_search_result might be faster
     831    $super_order_by=true; // quick_search_result might be faster
    831832  }
    832833
    833834  $search_result = get_quick_search_results($params['query'],
    834     implode(',', $where_clauses) );
    835   $image_ids = $search_result['items'];
    836 
    837   $image_ids = array_slice($image_ids,
    838     $params['page']*$params['per_page'],
    839     $params['per_page'] );
     835      $super_order_by,
     836      implode(',', $where_clauses)
     837    );
     838
     839  $image_ids = array_slice(
     840      $search_result['items'],
     841      $params['page']*$params['per_page'],
     842      $params['per_page']
     843    );
    840844
    841845  if ( count($image_ids) )
     
    843847    $query = '
    844848SELECT * FROM '.IMAGES_TABLE.'
    845   WHERE id IN ('
    846         .wordwrap(implode(', ', $image_ids), 80, "\n")
    847         .')';
    848 
     849  WHERE id IN ('.implode(',', $image_ids).')';
     850
     851    $image_ids = array_flip($image_ids);
    849852    $result = pwg_query($query);
    850853    while ($row = mysql_fetch_assoc($result))
     
    863866      }
    864867      $image = array_merge( $image, ws_std_get_urls($row) );
    865       array_push($images, $image);
    866     }
    867 
    868     $image_ids = array_flip($image_ids);
    869     usort(
    870         $images,
    871         create_function('$i1,$i2', 'global $image_ids; return $image_ids[$i1["id"]]-$image_ids[$i2["id"]];')
    872       );
     868      $images[$image_ids[$image['id']]] = $image;
     869    }
     870    ksort($images, SORT_NUMERIC);
     871    $images = array_values($images);
    873872  }
    874873
Note: See TracChangeset for help on using the changeset viewer.