PHPCMS V9 Unlimited model full Site search

Source: Internet
Author: User

Simply modify the V9 default search function, you can not search by model for the entire site content
The following is the index.php file in the modified search module

<?phpdefined (' in_phpcms ') or exit (' No permission resources. ');        Pc_base::load_sys_class (' form ', ' ', 0 ');p c_base::load_sys_class (' format ', ' ', 0 '); class Index {function __construct () {        $this->db = Pc_base::load_model (' Search_model ');    $this->content_db = Pc_base::load_model (' Content_model '); }/** * Keyword search */public function init () {//get SiteID $siteid = isset ($_request[' SiteID ']) &amp ;& Trim ($_request[' SiteID ')?        Intval ($_request[' SiteID '): 1;        $SEO = SEO ($siteid);        Search configuration $search _setting = GetCache (' search ');        $setting = $search _setting[$siteid];        $search _model = GetCache (' search_model_ '. $siteid);        $type _module = GetCache (' Type_module_ '. $siteid); if (isset ($_get[' Q '))) {if (Trim ($_get[' q ')) = = = ") {Header (' Location: '). App_path. '            Index.php?m=search '); exit; } $typeid = Empty ($_get[' typeid ')?            0:intval ($_get[' typeid '); $time = EmptY ($_get[' time ') | | !in_array ($_get[' time '],array (' All ', ' Day ', ' Month ', ' Year ', ' Week '))?            ' All ': trim ($_get[' time '); $page = isset ($_get[' page ')?            Intval ($_get[' page '): 1;            $pagesize = 10;            $q = Safe_replace (Trim ($_get[' q '));            $q = New_html_special_chars (Strip_tags ($q));   $q = str_replace ('% ', ' ', $q);    Filter '% ', user full-text search $search _q = $q;            Search the original content $sql _time = $sql _tid = ";            if ($typeid) $sql _tid = ' and typeID = '. $typeid;                Search by Time if ($time = = ' Day ') {$search _time = sys_time-86400;            $sql _time = ' and Adddate > '. $search _time;                } elseif ($time = = ' Week ') {$search _time = sys_time-604800;            $sql _time = ' and Adddate > '. $search _time;                } elseif ($time = = ' month ') {$search _time = sys_time-2592000;            $sql _time = ' and Adddate > '. $search _time; } elseif ($time = = ' Year ') {$search _time = sys_time-31536000;            $sql _time = ' and Adddate > '. $search _time;                } else {$search _time = 0;            $sql _time = "; if ($page ==1 &&! $setting [' sphinxenable ']) {//exact search $commend = $this-&gt            ;d b->get_one ("' SiteID ' = ' $siteid ' $sql _tid $sql _time and ' data ' like '% $q% '");            } else {$commend = '; }//If Open Sphinx if ($setting [' sphinxenable ']) {$sphinx = Pc_base::load_app_class (' Sear                Ch_interface ', ', 0);                $sphinx = new Search_interface ();                $offset = $pagesize * ($page-1); $res = $sphinx->search ($q, Array ($siteid), Array ($typeid), Array ($search _time, Sys_time), $offset, $pagesize, ' @                Weight desc ');                $totalnums = $res [' Total '];                If the result is not NULL if (!empty ($res [' matches '])) {    $result = $res [' matches '];                }} else {$sql = "' SiteID ' = ' $siteid ' $sql _tid $sql _time and ' data ' like '% $q% '";            $result = $this->db->listinfo ($sql, ' Searchid DESC ', $page, 10);            } var_dump ($result);                    If the result is not NULL if (!empty ($result) | |!empty ($commend [' ID '])) {foreach ($result as $_v) {                if ($_v[' typeid ') $sids [$_v[' typeid ']][] = $_v[' id ']; if (!empty ($commend [' ID '])) {if ($commend [' typeid ']) $sids [$commend [' typeid ']][] = $com                mend[' id '];                } $model _type_cache = GetCache (' Type_model_ '. $siteid, ' search ');                $model _type_cache = Array_flip ($model _type_cache);                $data = Array ();                    foreach ($sids as $_k=>$_val) {$tid = $_k;                    $ids = Array_unique ($_val);   $where = To_sqls ($ids, ' ', ' id ');                 Get model ID $modelid = $model _type_cache[$tid];                        Whether to read other module interfaces if ($modelid) {$this->content_db->set_model ($modelid); /** * If the table name is empty, the Yellow page model */if (Empty ($th Is->content_db->model_tablename) {$this->content_db = Pc_base::load_model (' Yp_conten                            T_model ');                        $this->content_db->set_model ($modelid);                    } $datas = $this->content_db->select ($where, ' * ');                } $data = Array_merge ($data, $datas);                } $pages = $this->db->pages;                $totalnums = $this->db->number;                    If the word breaker result is empty if (!empty ($segment _q)) {$replace = Explode (", $segment _q); foreach ($replaCe as $replace _arr_v) {$replace _arr[] = ' <font color=red> '. $replace _arr_v. ' </font> '; } foreach ($data as $_k=>$_v) {$data [$_k][' title '] = Str_r                        Eplace ($replace, $replace _arr, $_v[' title ']);                    $data [$_k][' description '] = Str_replace ($replace, $replace _arr, $_v[' description ']); }} else {foreach ($data as $_k=>$_v) {$data [$_k][' title '] =                        Str_replace ($q, ' <font color=red> ' $q. ' </font> ', $_v[' title ']);                    $data [$_k][' description '] = Str_replace ($q, ' <font color=red> '. $q. ' </font> ', $_v[' description ']);            }}} $execute _time = Execute_time (); $pages = Isset ($pages)?            $pages: "; $totalnums = Isset ($totalnums)?            $totalnums: 0; $data = Isset ($data)?    $data: ";        Include template (' Search ', ' list ');        } else {include template (' Search ', ' index '); }} Public Function Public_get_suggest_keyword () {$url = $_get[' url ']. '        &q= '. $_get[' Q '];        $trust _url = Array (' C8430FCF851E85818B546ADDF5BC4DD3 ');        $urm _MD5 = MD5 ($url);        if (!in_array ($urm _md5, $trust _url)) exit;        $res = @file_get_contents ($url);        if (CHARSET! = ' GBK ') {$res = Iconv (' GBK ', CHARSET, $res);    } Echo $res;        }/** * Prompt Search interface * TODO is temporarily not enabled, with Google's interface */Public function Public_suggest_search () {//keyword converted to pinyin        Pc_base::load_sys_func (' Iconv ');        $pinyin = Gbk_to_pinyin ($q);        if (Is_array ($pinyin)) {$pinyin = Implode (", $pinyin);        } $this->keyword_db = Pc_base::load_model (' Search_keyword_model ');        $suggest = $this->keyword_db->select ("Pinyin like ' $pinyin% '", ' * ', ', ' searchnums DESC '); foreach ($suggest as $v){echo $v [' keyword ']. "        \ n "; }}}?>

  

Then add an "unlimited" search condition on the header.html template, the value of typeid corresponds to 0, Search in the index.html and lists.html also do the same, the effect such as this site, so long as the model is not selected so that the results are all the data in the model matching criteria

Because copying code can cause code errors, use the files in the following compressed package
Link: Http://pan.baidu.com/s/1kUAmRWF Password: 76YP

Transferred from: http://blog.csdn.net/w18842629521/article/details/72674072

PHPCMS V9 Unlimited model full Site search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.