Ignore:
Timestamp:
Mar 31, 2010, 6:32:40 PM (15 years ago)
Author:
george
Message:
  • Upraveno: Aktualizace fóra.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/forum/includes/search/fulltext_mysql.php

    r400 r702  
    33*
    44* @package search
    5 * @version $Id: fulltext_mysql.php 8814 2008-09-04 12:01:47Z acydburn $
     5* @version $Id$
    66* @copyright (c) 2005 phpBB Group
    77* @license http://opensource.org/licenses/gpl-license.php GNU Public License
     
    119119        function split_keywords(&$keywords, $terms)
    120120        {
    121                 global $config;
     121                global $config, $user;
    122122
    123123                if ($terms == 'all')
     
    166166                        preg_match_all('#(?:[^\w*"()]|^)([+\-|]?(?:[\w*"()]+\'?)*[\w*"()])(?:[^\w*"()]|$)#u', $split_keywords, $matches);
    167167                        $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)));
    168174                }
    169175
     
    319325        *
    320326        * @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
    331338        * @param        array           &$id_ary                        passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
    332339        * @param        int                     $start                          indicates the first index of the page
     
    336343        * @access       public
    337344        */
    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)
    339346        {
    340347                global $config, $db;
     
    435442                $sql_from                       = ($join_topic) ? TOPICS_TABLE . ' t, ' : '';
    436443                $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                }
    438457
    439458                $sql_where_options = $sql_sort_join;
     
    442461                $sql_where_options .= (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
    443462                $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;
    445464                $sql_where_options .= ($sort_days) ? ' AND p.post_time >= ' . (time() - ($sort_days * 86400)) : '';
    446465                $sql_where_options .= $sql_match_where;
     
    455474                while ($row = $db->sql_fetchrow($result))
    456475                {
    457                         $id_ary[] = $row[$field];
     476                        $id_ary[] = (int) $row[$field];
    458477                }
    459478                $db->sql_freeresult($result);
     
    490509        * Performs a search on an author's posts without caring about message contents. Depends on display specific params
    491510        *
    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)
    498530        {
    499531                global $config, $db;
     
    517549                        implode(',', $ex_fid_ary),
    518550                        implode(',', $m_approve_fid_ary),
    519                         implode(',', $author_ary)
     551                        implode(',', $author_ary),
     552                        $author_name,
    520553                )));
    521554
     
    530563
    531564                // 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                }
    533574                $sql_fora               = (sizeof($ex_fid_ary)) ? ' AND ' . $db->sql_in_set('p.forum_id', $ex_fid_ary, true) : '';
    534575                $sql_topic_id   = ($topic_id) ? ' AND p.topic_id = ' . (int) $topic_id : '';
     
    610651                while ($row = $db->sql_fetchrow($result))
    611652                {
    612                         $id_ary[] = $row[$field];
     653                        $id_ary[] = (int) $row[$field];
    613654                }
    614655                $db->sql_freeresult($result);
Note: See TracChangeset for help on using the changeset viewer.