How to set up phpcms unlimited model search
phpcmsv9 full site search, no model restrictions!
How to set up phpcms unlimited model search
phpcmsv9 full site search, unlimited model, today I gained more knowledge. As we all know, phpcms searches based on models. After using this method, you can search the entire site
Simply modify the default search function of v9, and you can search the entire site content without modeling
The following is the index.php file in the modified search module
<?php defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_sys_class('form','',0); pc_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'); } /** * 关键词搜索 */ public function init() { //获取siteid $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1; $SEO = seo($siteid); //搜索配置 $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);//过滤'%',用户全文搜索 $search_q = $q;//搜索原内容 $sql_time = $sql_tid = ''; if($typeid) $sql_tid = ' AND typeid = '.$typeid; //按时间搜索 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']) { //精确搜索 $commend = $this->db->get_one("`siteid`= '$siteid' $sql_tid $sql_time AND `data` like '%$q%'"); } else { $commend = ''; } //如果开启sphinx if($setting['sphinxenable']) { $sphinx = pc_base::load_app_class('search_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(!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(!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']][] = $commend['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'); //获取模型id $modelid = $model_type_cache[$tid]; //是否读取其他模块接口 if($modelid) { $this->content_db->set_model($modelid); /** * 如果表名为空,则为黄页模型 */ if(empty($this->content_db->model_tablename)) { $this->content_db = pc_base::load_model('yp_content_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(!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_replace($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 : ''; includetemplate('search','list'); } else { includetemplate('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; } /** * 提示搜索接口 * TODO 暂时未启用,用的是google的接口 */ public function public_suggest_search() { //关键词转换为拼音 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%'", '*', 10, 'searchnums DESC'); foreach($suggest as $v) { echo $v['keyword']."\n"; } } } ?>
Then add an "unlimited" to the header.html template (not here, just on other search box pages) For the search conditions, set the corresponding value of typeid to 0, and do the same processing for index.html and lists.html in the search, and the effect will be there. In this way, as long as the model is not selected, the search results will be the data that meets the conditions in all models.
PHP Chinese website, a large number of free PHPCMS tutorials, welcome to learn online!
The above is the detailed content of How to set up phpcms unlimited model search. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to jump to the details page in phpcms: 1. Use the header function to generate a jump link; 2. Loop through the content list; 3. Get the title and details page link of the content; 4. Generate a jump link.

PHP CMS is a PHP-based open source content management system for managing website content. Its features include ease of use, powerful functionality, scalability, high security, and free open source. It can save time, improve website quality, enhance collaboration and reduce development costs, and is widely used in various websites such as news websites, blogs, corporate websites, e-commerce websites and community forums.

Title: WeChat Login Integration Guide: PHPCMS in Action In today’s Internet era, social login has become one of the essential functions of a website. As one of the most popular social platforms in China, WeChat’s login function is also used by more and more websites. This article will introduce how to integrate the WeChat login function in the PHPCMS website and provide specific code examples. Step 1: Register a WeChat Open Platform Account First, we need to register a developer account on the WeChat Open Platform and apply for the corresponding development permissions. Log in [WeChat open platform]

phpcms is not completely free. phpcms is an open source cms system, but open source does not mean free. It has two versions: free version and commercial version. The free version is limited to personal non-commercial use, while the commercial version requires purchasing a license; individuals can use it for research, and if it is commercial application , you need to pay a certain fee.

PHPCMS user name security setting strategy revealed In website development, user account security has always been an aspect that developers attach great importance to. The security settings of the username are also crucial, because the username is not only the user's login credentials, but may also expose the user's personal information and even cause security risks. This article will reveal the username security setting strategy in PHPCMS and give specific code examples for developers to refer to. 1. Prevent common usernames. In order to improve the security of usernames, developers should prevent users from using excessive

PHPCMS is a free and open source content management system (CMS) that features: open source, modularity, flexibility, user-friendliness and community support. It can be used to create various types of websites, including corporate websites, e-commerce websites, blogs, and community forums. Technical requirements include: PHP 5.6 or higher, MySQL, MariaDB or PostgreSQL database, and Apache or Nginx web server.

There are two well-known versions of phpcms, namely: 1. phpCMS4, which supports custom URL rules. The website management background is beautiful and easy to use, and has many front-end plug-ins, which can freely expand functions; 2. phpCMS2008R1, which supports multi-language, multi-site management, and page The manager is convenient, flexible, very lightweight, and runs fast.

phpcms uses mysql database. phpcms is a PHP open source website management system, developed using PHP+MYSQL as the technical basis. PHPCMS V9 adopts OOP method to build the basic operating framework. The supported PHP version is PHP5 and above, and the supported MYSQL version is MySql 4.1 and above.
