Changeset 1619
- Timestamp:
- Nov 29, 2006, 2:50:39 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/functions_search.inc.php
r1618 r1619 287 287 } 288 288 289 289 /** 290 * returns the LIKE sql clause corresponding to the quick search query $q 291 * and the field $field. example q="john bill", field="file" will return 292 * file LIKE "%john%" OR file LIKE "%bill%". Special characters for MySql 293 * full text search (+,<,>) are omitted. 294 * @param string q 295 * @param string field 296 * @return string 297 */ 290 298 function get_qsearch_like_clause($q, $field) 291 299 { … … 319 327 320 328 /** 321 * returns the search results corresponding to a quick search 329 * returns the search results (array of image ids) corresponding to a 330 * quick/query search. A quick/query search returns many items (search is 331 * not strict), but results are sorted by relevance. 322 332 * 323 333 * @param string q … … 329 339 $search_results = array(); 330 340 341 // first search tag names corresponding to the query $q. we could also search 342 // tags later during the big join, but for the sake of the performance and 343 // because tags have only a simple name we do it separately 331 344 $q_like_clause = get_qsearch_like_clause($q, 'CONVERT(name, CHAR)' ); 332 345 $by_tag_weights=array(); … … 339 352 $tag_ids = array_from_query( $query, 'id'); 340 353 if (!empty($tag_ids)) 341 { 354 { // we got some tags 342 355 $query = ' 343 356 SELECT image_id, COUNT(tag_id) AS q … … 346 359 GROUP BY image_id'; 347 360 $result = pwg_query($query); 348 while ($row = mysql_fetch_a rray($result))349 { 361 while ($row = mysql_fetch_assoc($result)) 362 { // weight is important when sorting images by relevance 350 363 $by_tag_weights[(int)$row['image_id']] = $row['q']; 351 364 } … … 353 366 } 354 367 368 // prepare the big join on images, comments and categories 355 369 $query = ' 356 370 SELECT … … 377 391 WHERE MATCH(ft) AGAINST( "'.$q.'" IN BOOLEAN MODE)'; 378 392 393 //also inlcude the file name (but avoid full text which is slower because 394 //the filename in pwg doesn't have spaces so full text is meaningless anyway) 379 395 $q_like_clause = get_qsearch_like_clause($q, 'file' ); 380 396 if (! empty($q_like_clause) ) … … 390 406 } 391 407 408 // finally merge the results (tags and big join) sorted by "relevance" 392 409 foreach ( $by_weights as $image=>$w ) 393 410 { … … 395 412 } 396 413 414 //at this point, found images might contain images not allowed for the user 397 415 if ( empty($by_tag_weights) or isset($page['super_order_by']) ) 398 416 { 399 if (! isset($page['super_order_by']) ) 400 { 401 arsort($by_tag_weights, SORT_NUMERIC); 402 $search_results['as_is']=1; 403 } 417 // no aditionnal query here for permissions (will be done by section_init 418 // while sorting items as the user requested it) 404 419 $search_results['items'] = array_keys($by_tag_weights); 405 420 } 406 421 else 407 422 { 423 // before returning the result "as is", make sure the user has the 424 // permissions for every item 408 425 $query = ' 409 426 SELECT DISTINCT(id)
Note: See TracChangeset
for help on using the changeset viewer.