Changeset 702 for trunk/forum/includes/search/fulltext_native.php
- Timestamp:
- Mar 31, 2010, 6:32:40 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/forum/includes/search/fulltext_native.php
r400 r702 3 3 * 4 4 * @package search 5 * @version $Id : fulltext_native.php 9173 2008-12-04 17:01:39Z naderman$5 * @version $Id$ 6 6 * @copyright (c) 2005 phpBB Group 7 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License … … 82 82 function split_keywords($keywords, $terms) 83 83 { 84 global $db, $user ;84 global $db, $user, $config; 85 85 86 86 $keywords = trim($this->cleanup($keywords, '+-|()*')); … … 168 168 169 169 $keywords = preg_replace($match, $replace, $keywords); 170 $num_keywords = sizeof(explode(' ', $keywords)); 171 172 // We limit the number of allowed keywords to minimize load on the database 173 if ($config['max_num_search_keywords'] && $num_keywords > $config['max_num_search_keywords']) 174 { 175 trigger_error($user->lang('MAX_NUM_SEARCH_KEYWORDS_REFINE', $config['max_num_search_keywords'], $num_keywords)); 176 } 170 177 171 178 // $keywords input format: each word separated by a space, words in a bracket are not separated … … 196 203 $sql = 'SELECT word_id, word_text, word_common 197 204 FROM ' . SEARCH_WORDLIST_TABLE . ' 198 WHERE ' . $db->sql_in_set('word_text', $exact_words); 205 WHERE ' . $db->sql_in_set('word_text', $exact_words) . ' 206 ORDER BY word_count ASC'; 199 207 $result = $db->sql_query($sql); 200 208 … … 371 379 } 372 380 373 sort($this->must_contain_ids);374 sort($this->must_not_contain_ids);375 sort($this->must_exclude_one_ids);376 377 381 if (!empty($this->search_query)) 378 382 { … … 386 390 * 387 391 * @param string $type contains either posts or topics depending on what should be searched for 388 * @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) 389 * @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) 390 * @param array &$sort_by_sql contains SQL code for the ORDER BY part of a query 391 * @param string &$sort_key is the key of $sort_by_sql for the selected sorting 392 * @param string &$sort_dir is either a or d representing ASC and DESC 393 * @param string &$sort_days specifies the maximum amount of days a post may be old 394 * @param array &$ex_fid_ary specifies an array of forum ids which should not be searched 395 * @param array &$m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 396 * @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 397 * @param array &$author_ary an array of author ids if the author should be ignored during the search the array is empty 392 * @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) 393 * @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) 394 * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query 395 * @param string $sort_key is the key of $sort_by_sql for the selected sorting 396 * @param string $sort_dir is either a or d representing ASC and DESC 397 * @param string $sort_days specifies the maximum amount of days a post may be old 398 * @param array $ex_fid_ary specifies an array of forum ids which should not be searched 399 * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 400 * @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 401 * @param array $author_ary an array of author ids if the author should be ignored during the search the array is empty 402 * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match 398 403 * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered 399 404 * @param int $start indicates the first index of the page … … 403 408 * @access public 404 409 */ 405 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)410 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) 406 411 { 407 412 global $config, $db; … … 413 418 } 414 419 420 $must_contain_ids = $this->must_contain_ids; 421 $must_not_contain_ids = $this->must_not_contain_ids; 422 $must_exclude_one_ids = $this->must_exclude_one_ids; 423 424 sort($must_contain_ids); 425 sort($must_not_contain_ids); 426 sort($must_exclude_one_ids); 427 415 428 // generate a search_key from all the options to identify the results 416 429 $search_key = md5(implode('#', array( 417 serialize($ this->must_contain_ids),418 serialize($ this->must_not_contain_ids),419 serialize($ this->must_exclude_one_ids),430 serialize($must_contain_ids), 431 serialize($must_not_contain_ids), 432 serialize($must_exclude_one_ids), 420 433 $type, 421 434 $fields, … … 426 439 implode(',', $ex_fid_ary), 427 440 implode(',', $m_approve_fid_ary), 428 implode(',', $author_ary) 441 implode(',', $author_ary), 442 $author_name, 429 443 ))); 430 444 … … 617 631 if (sizeof($author_ary)) 618 632 { 619 $sql_where[] = $db->sql_in_set('p.poster_id', $author_ary); 633 if ($author_name) 634 { 635 // first one matches post of registered users, second one guests and deleted users 636 $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; 637 } 638 else 639 { 640 $sql_author = $db->sql_in_set('p.poster_id', $author_ary); 641 } 642 $sql_where[] = $sql_author; 620 643 } 621 644 … … 639 662 $sql_array_count = $sql_array; 640 663 664 if ($left_join_topics) 665 { 666 $sql_array_count['LEFT_JOIN'][] = array( 667 'FROM' => array(TOPICS_TABLE => 't'), 668 'ON' => 'p.topic_id = t.topic_id' 669 ); 670 } 671 641 672 switch ($db->sql_layer) 642 673 { … … 645 676 646 677 // 3.x does not support SQL_CALC_FOUND_ROWS 647 $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT'];678 // $sql_array['SELECT'] = 'SQL_CALC_FOUND_ROWS ' . $sql_array['SELECT']; 648 679 $is_mysql = true; 649 680 … … 694 725 break; 695 726 } 696 727 697 728 if ($left_join_topics) 698 729 { 699 $sql_array['LEFT_JOIN'][ $left_join_topics] = array(730 $sql_array['LEFT_JOIN'][] = array( 700 731 'FROM' => array(TOPICS_TABLE => 't'), 701 732 'ON' => 'p.topic_id = t.topic_id' … … 714 745 while ($row = $db->sql_fetchrow($result)) 715 746 { 716 $id_ary[] = $row[(($type == 'posts') ? 'post_id' : 'topic_id')];747 $id_ary[] = (int) $row[(($type == 'posts') ? 'post_id' : 'topic_id')]; 717 748 } 718 749 $db->sql_freeresult($result); … … 726 757 if (!$total_results && $is_mysql) 727 758 { 759 // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. 760 $sql_array_copy = $sql_array; 761 $sql_array_copy['SELECT'] = 'SQL_CALC_FOUND_ROWS p.post_id '; 762 763 $sql = $db->sql_build_query('SELECT', $sql_array_copy); 764 unset($sql_array_copy); 765 766 $db->sql_query($sql); 767 $db->sql_freeresult($result); 768 728 769 $sql = 'SELECT FOUND_ROWS() as total_results'; 729 770 $result = $db->sql_query($sql); … … 749 790 * @param string $type contains either posts or topics depending on what should be searched for 750 791 * @param boolean $firstpost_only if true, only topic starting posts will be considered 751 * @param array &$sort_by_sql contains SQL code for the ORDER BY part of a query 752 * @param string &$sort_key is the key of $sort_by_sql for the selected sorting 753 * @param string &$sort_dir is either a or d representing ASC and DESC 754 * @param string &$sort_days specifies the maximum amount of days a post may be old 755 * @param array &$ex_fid_ary specifies an array of forum ids which should not be searched 756 * @param array &$m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 757 * @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 758 * @param array &$author_ary an array of author ids 792 * @param array $sort_by_sql contains SQL code for the ORDER BY part of a query 793 * @param string $sort_key is the key of $sort_by_sql for the selected sorting 794 * @param string $sort_dir is either a or d representing ASC and DESC 795 * @param string $sort_days specifies the maximum amount of days a post may be old 796 * @param array $ex_fid_ary specifies an array of forum ids which should not be searched 797 * @param array $m_approve_fid_ary specifies an array of forum ids in which the searcher is allowed to view unapproved posts 798 * @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 799 * @param array $author_ary an array of author ids 800 * @param string $author_name specifies the author match, when ANONYMOUS is also a search-match 759 801 * @param array &$id_ary passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered 760 802 * @param int $start indicates the first index of the page … … 764 806 * @access public 765 807 */ 766 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)808 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) 767 809 { 768 810 global $config, $db; … … 786 828 implode(',', $ex_fid_ary), 787 829 implode(',', $m_approve_fid_ary), 788 implode(',', $author_ary) 830 implode(',', $author_ary), 831 $author_name, 789 832 ))); 790 833 … … 799 842 800 843 // Create some display specific sql strings 801 $sql_author = $db->sql_in_set('p.poster_id', $author_ary); 844 if ($author_name) 845 { 846 // first one matches post of registered users, second one guests and deleted users 847 $sql_author = '(' . $db->sql_in_set('p.poster_id', array_diff($author_ary, array(ANONYMOUS)), false, true) . ' OR p.post_username ' . $author_name . ')'; 848 } 849 else 850 { 851 $sql_author = $db->sql_in_set('p.poster_id', $author_ary); 852 } 802 853 $sql_fora = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : ''; 803 854 $sql_time = ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : ''; … … 849 900 case 'mysql4': 850 901 case 'mysqli': 851 $select = 'SQL_CALC_FOUND_ROWS ' . $select;902 // $select = 'SQL_CALC_FOUND_ROWS ' . $select; 852 903 $is_mysql = true; 853 904 break; … … 936 987 while ($row = $db->sql_fetchrow($result)) 937 988 { 938 $id_ary[] = $row[$field];989 $id_ary[] = (int) $row[$field]; 939 990 } 940 991 $db->sql_freeresult($result); … … 942 993 if (!$total_results && $is_mysql) 943 994 { 995 // Count rows for the executed queries. Replace $select within $sql with SQL_CALC_FOUND_ROWS, and run it. 996 $sql = str_replace('SELECT ' . $select, 'SELECT DISTINCT SQL_CALC_FOUND_ROWS p.post_id', $sql); 997 998 $db->sql_query($sql); 999 $db->sql_freeresult($result); 1000 944 1001 $sql = 'SELECT FOUND_ROWS() as total_results'; 945 1002 $result = $db->sql_query($sql); … … 1111 1168 // Get unique words from the above arrays 1112 1169 $unique_add_words = array_unique(array_merge($words['add']['post'], $words['add']['title'])); 1113 1170 1114 1171 // We now have unique arrays of all words to be added and removed and 1115 1172 // individual arrays of added and removed words for text and title. What
Note:
See TracChangeset
for help on using the changeset viewer.