Changeset 702 for trunk/forum/includes/search/fulltext_mysql.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/search/fulltext_mysql.php
r400 r702 3 3 * 4 4 * @package search 5 * @version $Id : fulltext_mysql.php 8814 2008-09-04 12:01:47Z acydburn$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 119 119 function split_keywords(&$keywords, $terms) 120 120 { 121 global $config ;121 global $config, $user; 122 122 123 123 if ($terms == 'all') … … 166 166 preg_match_all('#(?:[^\w*"()]|^)([+\-|]?(?:[\w*"()]+\'?)*[\w*"()])(?:[^\w*"()]|$)#u', $split_keywords, $matches); 167 167 $this->split_words = $matches[1]; 168 } 169 170 // We limit the number of allowed keywords to minimize load on the database 171 if ($config['max_num_search_keywords'] && sizeof($this->split_words) > $config['max_num_search_keywords']) 172 { 173 trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], sizeof($this->split_words))); 168 174 } 169 175 … … 319 325 * 320 326 * @param string $type contains either posts or topics depending on what should be searched for 321 * @param string &$fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched) 322 * @param string &$terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words) 323 * @param array &$sort_by_sql contains SQL code for the ORDER BY part of a query 324 * @param string &$sort_key is the key of $sort_by_sql for the selected sorting 325 * @param string &$sort_dir is either a or d representing ASC and DESC 326 * @param string &$sort_days specifies the maximum amount of days a post may be old 327 * @param array &$ex_fid_ary specifies an array of forum ids which should not be searched 328 * @param array &$m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 329 * @param int &$topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched 330 * @param array &$author_ary an array of author ids if the author should be ignored during the search the array is empty 327 * @param string $fields contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched) 328 * @param string $terms is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words) 329 * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query 330 * @param string $sort_key is the key of $sort_by_sql for the selected sorting 331 * @param string $sort_dir is either a or d representing ASC and DESC 332 * @param string $sort_days specifies the maximum amount of days a post may be old 333 * @param array $ex_fid_ary specifies an array of forum ids which should not be searched 334 * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 335 * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched 336 * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty 337 * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match 331 338 * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered 332 339 * @param int $start indicates the first index of the page … … 336 343 * @access public 337 344 */ 338 function keyword_search($type, &$fields, &$terms, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page)345 function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) 339 346 { 340 347 global $config, $db; … … 435 442 $sql_from = ($join_topic) ? TOPICS_TABLE . ' t, ' : ''; 436 443 $field = ($type == 'posts') ? 'post_id' : 'topic_id'; 437 $sql_author = (sizeof($author_ary) == 1) ? ' = ' . $author_ary[0] : 'IN (' . implode(', ', $author_ary) . ')'; 444 if (sizeof($author_ary) && $author_name) 445 { 446 // first one matches post of registered users, second one guests and deleted users 447 $sql_author = ' AND (' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; 448 } 449 else if (sizeof($author_ary)) 450 { 451 $sql_author = ' AND ' . $db->sql_in_set('p.poster_id', $author_ary); 452 } 453 else 454 { 455 $sql_author = ''; 456 } 438 457 439 458 $sql_where_options = $sql_sort_join; … … 442 461 $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; 443 462 $sql_where_options .= $m_approve_fid_sql; 444 $sql_where_options .= (sizeof($author_ary)) ? ' AND p.poster_id ' . $sql_author : '';463 $sql_where_options .= $sql_author; 445 464 $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; 446 465 $sql_where_options .= $sql_match_where; … … 455 474 while ($row = $db->sql_fetchrow($result)) 456 475 { 457 $id_ary[] = $row[$field];476 $id_ary[] = (int) $row[$field]; 458 477 } 459 478 $db->sql_freeresult($result); … … 490 509 * Performs a search on an author's posts without caring about message contents. Depends on display specific params 491 510 * 492 * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered 493 * @param int $start indicates the first index of the page 494 * @param int $per_page number of ids each page is supposed to contain 495 * @return total number of results 496 */ 497 function author_search($type, $firstpost_only, &$sort_by_sql, &$sort_key, &$sort_dir, &$sort_days, &$ex_fid_ary, &$m_approve_fid_ary, &$topic_id, &$author_ary, &$id_ary, $start, $per_page) 511 * @param string $type contains either posts or topics depending on what should be searched for 512 * @param boolean $firstpost_only if true, only topic starting posts will be considered 513 * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query 514 * @param string $sort_key is the key of $sort_by_sql for the selected sorting 515 * @param string $sort_dir is either a or d representing ASC and DESC 516 * @param string $sort_days specifies the maximum amount of days a post may be old 517 * @param array $ex_fid_ary specifies an array of forum ids which should not be searched 518 * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 519 * @param int $topic_id is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched 520 * @param array $author_ary an array of author ids 521 * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match 522 * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered 523 * @param int $start indicates the first index of the page 524 * @param int $per_page number of ids each page is supposed to contain 525 * @return boolean|int total number of results 526 * 527 * @access public 528 */ 529 function author_search($type, $firstpost_only, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $m_approve_fid_ary, $topic_id, $author_ary, $author_name, &$id_ary, $start, $per_page) 498 530 { 499 531 global $config, $db; … … 517 549 implode(',', $ex_fid_ary), 518 550 implode(',', $m_approve_fid_ary), 519 implode(',', $author_ary) 551 implode(',', $author_ary), 552 $author_name, 520 553 ))); 521 554 … … 530 563 531 564 // Create some display specific sql strings 532 $sql_author = $db->sql_in_set('p.poster_id', $author_ary); 565 if ($author_name) 566 { 567 // first one matches post of registered users, second one guests and deleted users 568 $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; 569 } 570 else 571 { 572 $sql_author = $db->sql_in_set('p.poster_id', $author_ary); 573 } 533 574 $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; 534 575 $sql_topic_id = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : ''; … … 610 651 while ($row = $db->sql_fetchrow($result)) 611 652 { 612 $id_ary[] = $row[$field];653 $id_ary[] = (int) $row[$field]; 613 654 } 614 655 $db->sql_freeresult($result);
Note:
See TracChangeset
for help on using the changeset viewer.