Changeset 2451 for trunk/include/functions_search.inc.php
- Timestamp:
- Jul 23, 2008, 2:56:22 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_search.inc.php
r2299 r2451 195 195 * @return array 196 196 */ 197 function get_regular_search_results($search )197 function get_regular_search_results($search, $images_where) 198 198 { 199 global $conf; 200 $forbidden = get_sql_condition_FandF( 201 array 202 ( 203 'forbidden_categories' => 'category_id', 204 'visible_categories' => 'category_id', 205 'visible_images' => 'id' 206 ), 207 "\n AND" 208 ); 209 199 210 $items = array(); 200 201 $search_clause = get_sql_search_clause($search); 202 203 if (!empty($search_clause)) 204 { 205 $query = ' 206 SELECT DISTINCT(id) 207 FROM '.IMAGES_TABLE.' 208 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 209 WHERE '.$search_clause.' 210 ;'; 211 $items = array_from_query($query, 'id'); 212 } 211 $tag_items = array(); 213 212 214 213 if (isset($search['fields']['tags'])) … … 218 217 $search['fields']['tags']['mode'] 219 218 ); 220 219 } 220 221 $search_clause = get_sql_search_clause($search); 222 223 if (!empty($search_clause)) 224 { 225 $query = ' 226 SELECT DISTINCT(id) 227 FROM '.IMAGES_TABLE.' i 228 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 229 WHERE '.$search_clause; 230 if (!empty($images_where)) 231 { 232 $query .= "\n AND ".$images_where; 233 } 234 if (empty($tag_items) or $search['mode']=='AND') 235 { // directly use forbidden and order by 236 $query .= $forbidden.' 237 '.$conf['order_by']; 238 } 239 $items = array_from_query($query, 'id'); 240 } 241 242 if ( !empty($tag_items) ) 243 { 244 $need_permission_check = false; 221 245 switch ($search['mode']) 222 246 { 223 247 case 'AND': 224 {225 248 if (empty($search_clause)) 226 249 { 250 $need_permission_check = true; 227 251 $items = $tag_items; 228 252 } … … 232 256 } 233 257 break; 234 }235 258 case 'OR': 236 {259 $before_count = count($items); 237 260 $items = array_unique( 238 261 array_merge( … … 241 264 ) 242 265 ); 266 if ( $before_count < count($items) ) 267 { 268 $need_permission_check = true; 269 } 243 270 break; 271 } 272 if ($need_permission_check and count($items) ) 273 { 274 $query = ' 275 SELECT DISTINCT(id) 276 FROM '.IMAGES_TABLE.' i 277 INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id 278 WHERE id IN ('.implode(',', $items).') '.$forbidden; 279 if (!empty($images_where)) 280 { 281 $query .= "\n AND ".$images_where; 244 282 } 283 $query .= ' 284 '.$conf['order_by']; 285 $items = array_from_query($query, 'id'); 245 286 } 246 287 } … … 355 396 * returns the search results corresponding to a quick/query search. 356 397 * A quick/query search returns many items (search is not strict), but results 357 * are sorted by relevance unless $ page['super_order_by'] is set. Returns:398 * are sorted by relevance unless $super_order_by is true. Returns: 358 399 * array ( 359 400 * 'items' => array(85,68,79...) 360 * 'as_is' => 1 (indicates the caller that items are ordered and permissions checked361 401 * 'qs' => array( 362 402 * 'matching_tags' => array of matching tags … … 366 406 * 367 407 * @param string q 408 * @param bool super_order_by 368 409 * @param string images_where optional aditional restriction on images table 369 410 * @return array 370 411 */ 371 function get_quick_search_results($q, $ images_where='')412 function get_quick_search_results($q, $super_order_by, $images_where='') 372 413 { 373 global $page;374 414 $search_results = 375 415 array( 376 416 'items' => array(), 377 'as_is' => 1,378 417 'qs' => array('q'=>stripslashes($q)), 379 418 ); … … 519 558 $allowed_images = array_from_query( $query, 'id'); 520 559 521 if ( isset($page['super_order_by'])or empty($by_weights) )560 if ( $super_order_by or empty($by_weights) ) 522 561 { 523 562 $search_results['items'] = $allowed_images; … … 545 584 * @return array 546 585 */ 547 function get_search_results($search_id, $ images_where='')586 function get_search_results($search_id, $super_order_by, $images_where='') 548 587 { 549 588 $search = get_search_array($search_id); 550 589 if ( !isset($search['q']) ) 551 590 { 552 $result['items'] = get_regular_search_results($search );591 $result['items'] = get_regular_search_results($search, $images_where); 553 592 return $result; 554 593 } 555 594 else 556 595 { 557 return get_quick_search_results($search['q'], $ images_where);596 return get_quick_search_results($search['q'], $super_order_by, $images_where); 558 597 } 559 598 }
Note: See TracChangeset
for help on using the changeset viewer.