search_mysql_ftext.php
来自「sabreipb 2.1.6 utf-8中文版本!」· PHP 代码 · 共 879 行 · 第 1/2 页
PHP
879 行
<?php/*+--------------------------------------------------------------------------| Invision Power Board v2.1.5| =============================================| by Matthew Mecham| (c) 2001 - 2005 Invision Power Services, Inc.| | =============================================| Web: | Time: Wed, 01 Mar 2006 19:11:29 GMT| Release: | Licence Info: +---------------------------------------------------------------------------| > $Date: 2006-02-02 17:23:13 +0000 (Thu, 02 Feb 2006) $| > $Revision: 133 $| > $Author: bfarber $+---------------------------------------------------------------------------|| > MySQL FULL TEXT Search Library| > Module written by Matt Mecham| > Date started: 31st March 2003|| > Module Version Number: 1.0.0+--------------------------------------------------------------------------*/class search_lib extends Search{ var $parser = ""; var $is = ""; var $resultlimit = ""; //----------------------------------------- // Constructor //----------------------------------------- function search_lib(&$that) { $this->is = &$that; // hahaha! $this->resultlimit = $this->is->resultlimit; } //----------------------------------------- // Simple search //----------------------------------------- function do_simple_search() { if ( ! $this->ipsclass->input['sid'] ) { $boolean = ""; $topics_name = ""; //----------------------------------------- // NEW SEARCH.. Check Keywords.. //----------------------------------------- if ( $this->is->mysql_version >= 40010 ) { $boolean = 'IN BOOLEAN MODE'; $keywords = $this->is->filter_ftext_keywords($this->ipsclass->input['keywords']); } else { $keywords = $this->is->filter_keywords($this->ipsclass->input['keywords']); } $check_keywords = trim($keywords); if ( (! $check_keywords) or ($check_keywords == "") or (! isset($check_keywords) ) ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_words') ); } if (strlen(trim($keywords)) < $this->ipsclass->vars['min_search_word']) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => 4) ); } //----------------------------------------- // Check for filter abuse.. //----------------------------------------- $tmp = explode( ' ', $keywords ); foreach( $tmp as $t ) { if ( ! $t ) { continue; } $t = preg_replace( "#[\+\-\*\.]#", "", $t ); //----------------------------------------- // Allow abc* but not a*** //----------------------------------------- if ( strlen( $t ) < $this->ipsclass->vars['min_search_word'] ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'search_word_short', 'EXTRA' => $this->ipsclass->vars['min_search_word']) ); } } //print $check_keywords; exit(); //----------------------------------------- // Get forums... //----------------------------------------- $myforums = $this->is->get_searchable_forums(); if ($myforums == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_forum') ); } //----------------------------------------- // Only allowed to see their own topics? //----------------------------------------- if ( ! $this->ipsclass->member['g_other_topics'] ) { $topics_name = " AND t.starter_id=".$this->ipsclass->member['id']; } //----------------------------------------- // Allowed to see queueueueueuueueueued? //----------------------------------------- if ( ! $this->ipsclass->member['g_is_supmod'] ) { $approved = 'and p.queued=0 and t.approved=1'; } else { $approved = 'and p.queued IN (0,1)'; } //----------------------------------------- // How many results? //----------------------------------------- $this->ipsclass->DB->query("SELECT COUNT(*) as dracula FROM ".SQL_PREFIX."posts p LEFT JOIN ".SQL_PREFIX."topics t ON (t.tid=p.topic_id) WHERE t.forum_id IN ($myforums) {$topics_name} {$approved} AND MATCH(p.post) AGAINST ('$check_keywords' $boolean)"); $count = $this->ipsclass->DB->fetch_row(); if ( $count['dracula'] < 1 ) // Tee-hee! { $this->output .= $this->ipsclass->compiled_templates['skin_search']->search_error_page($this->ipsclass->input['keywords']); $this->ipsclass->print->add_output( $this->output ); $this->ipsclass->print->do_output( array( 'TITLE' => $this->ipsclass->lang['g_simple_title'], 'JS' => 0, NAV => array( $this->ipsclass->lang['g_simple_title'] ) ) ); } //----------------------------------------- // Store it daddy-o! //----------------------------------------- $cache = "SELECT MATCH(post) AGAINST ('$check_keywords' $boolean) as score, t.tid, t.posts as topic_posts, t.title as topic_title, t.views, t.forum_id, p.post, p.author_id, p.author_name, p.post_date, p.pid, p.post_htmlstate,m.*, me.* FROM ".SQL_PREFIX."posts p LEFT JOIN ".SQL_PREFIX."topics t on (p.topic_id=t.tid) LEFT JOIN ".SQL_PREFIX."members m on (m.id=p.author_id) LEFT JOIN ".SQL_PREFIX."member_extra me on (me.id=p.author_id) WHERE t.forum_id IN ($myforums) AND t.title IS NOT NULL {$topics_name} {$approved} AND MATCH(post) AGAINST ('$check_keywords' $boolean)"; if ( $this->ipsclass->input['sortby'] != "relevant" ) { $cache .= " ORDER BY p.post_date DESC"; } $unique_id = md5(uniqid(microtime(),1)); $str = $this->ipsclass->DB->compile_db_insert_string( array ( 'id' => $unique_id, 'search_date'=> time(), 'topic_id' => '00', 'topic_max' => $count['dracula'], 'member_id' => $this->ipsclass->member['id'], 'ip_address' => $this->ipsclass->input['IP_ADDRESS'], 'post_id' => '00', 'query_cache'=> $cache, ) ); $this->ipsclass->DB->query("INSERT INTO ibf_search_results ({$str['FIELD_NAMES']}) VALUES ({$str['FIELD_VALUES']})"); $hilight = str_replace( '"', '', $this->ipsclass->input['keywords'] ); $hilight = urlencode(trim(str_replace( '&', '&', $hilight))); $this->ipsclass->print->redirect_screen( $this->ipsclass->lang['search_redirect'] , "act=Search&CODE=simpleresults&sid=$unique_id&highlite=".$hilight ); } else { //----------------------------------------- // Load up the topic stuff //----------------------------------------- require_once( ROOT_PATH.'sources/action_public/topics.php' ); $this->topics = new topics(); $this->topics->ipsclass =& $this->ipsclass; $this->topics->topic_init(); //----------------------------------------- // Get SQL schtuff //----------------------------------------- $this->unique_id = $this->ipsclass->input['sid']; if ($this->unique_id == "") { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } $this->ipsclass->DB->query("SELECT * FROM ibf_search_results WHERE id='{$this->unique_id}'"); if ( ! $sr = $this->ipsclass->DB->fetch_row() ) { $this->ipsclass->Error( array( 'LEVEL' => 1, 'MSG' => 'no_search_results' ) ); } $query = stripslashes($sr['query_cache']); $check_keywords = preg_replace( '/&(lt|gt|quot);/', "&\\1;", trim(urldecode($this->ipsclass->input['highlite'])) ); //----------------------------------------- // Display //----------------------------------------- $this->links = $this->ipsclass->build_pagelinks( array( 'TOTAL_POSS' => $sr['topic_max'], 'leave_out' => 10, 'PER_PAGE' => 25, 'CUR_ST_VAL' => $this->is->first, 'L_SINGLE' => $this->ipsclass->lang['sp_single'], 'L_MULTI' => "", 'BASE_URL' => $this->ipsclass->base_url."&act=Search&CODE=simpleresults&sid=".$this->unique_id."&highlite=".urlencode(str_replace('"', '', $check_keywords)), ) ); //----------------------------------------- // oh look, a query! //----------------------------------------- $last_tid = 0; $SQLtime = new Debug(); $SQLtime->startTimer(); $outer = $this->ipsclass->DB->query($query." LIMIT {$this->is->first},25"); $ex_time = sprintf( "%.4f",$SQLtime->endTimer() ); $show_end = 25; if ( $sr['topic_max'] < 25 ) { $show_end = $sr['topic_max']; } $this->output .= $this->ipsclass->compiled_templates['skin_search']->result_simple_header(array( 'links' => $this->links, 'start' => $this->is->first, 'end' => $show_end + $this->is->first, 'matches' => $sr['topic_max'], 'ex_time' => $ex_time, 'keyword' => $check_keywords, ) ); $attach_pids = array(); while ( $row = $this->ipsclass->DB->fetch_row($outer) ) { //----------------------------------------- // Listen up, this is relevant. // MySQL's relevance is a bit of a mystery. It's // based on many hazy variables such as placing, occurance // and such. The result is a floating point number, like 1.239848556 // No one can really disect what this means in human terms, so I'm // going to simply assume that anything over 1.0 is 100%, and *100 any // other relevance result. //----------------------------------------- $member = $this->topics->parse_member( $row ); $row['relevance'] = sprintf( "%3d", ( $row['score'] > 1.0 ) ? 100 : $row['score'] * 100 ); $row['post_date'] = $this->ipsclass->get_date( $row['post_date'], 'LONG' ); // Link member's name if ($row['author_id']) { $row['author_name'] = "<a href='{$this->ipsclass->base_url}act=Profile&MID={$row['author_id']}'>{$row['author_name']}</a>"; } //----------------------------------------- // Attachments? //----------------------------------------- if ( strstr( $row['post'], '[attachmentid=' ) ) { $attach_pids[] = $row['pid']; } //----------------------------------------- // Fix up quotes.. //----------------------------------------- $this->topics->parser->parse_html = ( $this->ipsclass->forums->forum_by_id[$row['forum_id']]['use_html'] and $this->ipsclass->cache['group_cache'][ $row['mgroup'] ]['g_dohtml'] and $row['post_htmlstate'] ) ? 1 : 0; $this->topics->parser->parse_wordwrap = $this->ipsclass->vars['post_wordwrap']; $this->topics->parser->parse_nl2br = $row['post_htmlstate'] == 2 ? 1 : 0; $row['post'] = $this->topics->parser->pre_db_parse( $this->topics->parser->pre_edit_parse( $row['post'] ) ); $row['post'] = $this->topics->parser->pre_display_parse( $row['post'] ); $keywords_array = explode( " ", str_replace( "+", " ", $this->ipsclass->input['highlite'] ) ); if ( count($keywords_array) ) { foreach( $keywords_array as $keys ) { if ( $keys == "" ) { continue; } while( preg_match( "/(^|\s|'|\"|>)(".preg_quote($keys, '/').")(\s|'|\"|,|\.|!|<br|$)/is", $row['post'] ) ) { $row['post'] = preg_replace( "/(^|\s|'|\"|>)(".preg_quote($keys, '/').")(\s|'|\"|,|\.|!|<br|$)/is", "\\1<span class='searchlite'>\\2</span>\\3", $row['post'] ); } } } $row['forum_name'] = $this->ipsclass->forums->forum_by_id[ $row['forum_id'] ]['name']; $this->output .= $this->ipsclass->compiled_templates['skin_search']->RenderPostRow($row, $member); } //----------------------------------------- // Add in attachments? //----------------------------------------- if ( count( $attach_pids ) ) { $this->output = $this->topics->parse_attachments( $this->output, $attach_pids ); } $this->output .= $this->ipsclass->compiled_templates['skin_search']->end_results_table(array( 'SHOW_PAGES' => $this->links ) , 1 ); $this->ipsclass->print->add_output("$this->output"); $this->ipsclass->print->do_output( array( 'TITLE' => $this->ipsclass->lang['g_simple_title'], 'JS' => 0, NAV => array( $this->ipsclass->lang['g_simple_title'] ) ) ); } } //----------------------------------------- // Main Board Search-e-me-doo-daa //----------------------------------------- function do_main_search() { //----------------------------------------- // Invisible topic-approval permissions? //----------------------------------------- $my_invisible_forums_t = array(); $my_invisible_forums_p = array(); if( is_array($this->ipsclass->cache['moderators']) AND count($this->ipsclass->cache['moderators']) ) { foreach( $this->ipsclass->cache['moderators'] as $k => $v ) { if( $v['member_id'] == $this->ipsclass->member['id'] AND $v['post_q'] ) { $my_invisible_forums_p[] = $v['forum_id']; } if( $v['member_id'] == $this->ipsclass->member['id'] AND $v['topic_q'] ) { $my_invisible_forums_t[] = $v['forum_id']; } if( $v['is_group'] && ( $v['group_id'] == $this->ipsclass->member['mgroup'] OR in_array( $v['group_id'], explode( ",", $this->ipsclass->clean_perm_string( $this->ipsclass->member['mgroup_others'] ) ) ) ) && $v['post_q'] ) { $my_invisible_forums_p[] = $v['forum_id']; } if( $v['is_group'] && ( $v['group_id'] == $this->ipsclass->member['mgroup'] OR in_array( $v['group_id'], explode( ",", $this->ipsclass->clean_perm_string( $this->ipsclass->member['mgroup_others'] ) ) ) ) && $v['topic_q'] ) { $my_invisible_forums_t[] = $v['forum_id']; } } } //----------------------------------------- // Do we have any input? //----------------------------------------- //----------------------------------------- // USING FULL TEXT - Wooohoo!! //----------------------------------------- if ($this->ipsclass->input['namesearch'] != "") { $name_filter = $this->is->filter_keywords($this->ipsclass->input['namesearch'], 1); } if ($this->ipsclass->input['useridsearch'] != "") { $keywords = $this->is->filter_keywords($this->ipsclass->input['useridsearch']); $this->is->search_type = 'userid'; } else { $keywords = $this->is->filter_keywords($this->ipsclass->input['keywords']); $this->is->search_type = 'posts'; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?