Home CMS Tutorial PHPCMS How to set up phpcms unlimited model search

How to set up phpcms unlimited model search

Feb 05, 2020 am 10:18 AM
phpcms

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

<?php

defined(&#39;IN_PHPCMS&#39;) or exit(&#39;No permission resources.&#39;);

pc_base::load_sys_class(&#39;form&#39;,&#39;&#39;,0);

pc_base::load_sys_class(&#39;format&#39;,&#39;&#39;,0);

class index {

  function __construct() {

    $this->db = pc_base::load_model(&#39;search_model&#39;);

    $this->content_db = pc_base::load_model(&#39;content_model&#39;);

  }

   

  /**

   * 关键词搜索

   */

  public function init() {

    //获取siteid

    $siteid = isset($_REQUEST[&#39;siteid&#39;]) && trim($_REQUEST[&#39;siteid&#39;]) ? intval($_REQUEST[&#39;siteid&#39;]) : 1;

    $SEO = seo($siteid);

  

    //搜索配置

    $search_setting = getcache(&#39;search&#39;);

    $setting = $search_setting[$siteid];

  

    $search_model = getcache(&#39;search_model_&#39;.$siteid);

    $type_module = getcache(&#39;type_module_&#39;.$siteid);

  

    if(isset($_GET[&#39;q&#39;])) {

      if(trim($_GET[&#39;q&#39;])==&#39;&#39;) {

        header(&#39;Location: &#39;.APP_PATH.&#39;index.php?m=search&#39;);exit;

      }

      $typeid = empty($_GET[&#39;typeid&#39;]) ? 0 : intval($_GET[&#39;typeid&#39;]);

      $time = empty($_GET[&#39;time&#39;]) || !in_array($_GET[&#39;time&#39;],array(&#39;all&#39;,&#39;day&#39;,&#39;month&#39;,&#39;year&#39;,&#39;week&#39;)) ? &#39;all&#39; : trim($_GET[&#39;time&#39;]);

      $page = isset($_GET[&#39;page&#39;]) ? intval($_GET[&#39;page&#39;]) : 1;

      $pagesize = 10;

      $q = safe_replace(trim($_GET[&#39;q&#39;]));

      $q = new_html_special_chars(strip_tags($q));

      $q = str_replace(&#39;%&#39;, &#39;&#39;, $q);//过滤&#39;%&#39;,用户全文搜索

      $search_q = $q;//搜索原内容

  

      $sql_time = $sql_tid = &#39;&#39;;

      if($typeid) $sql_tid = &#39; AND typeid = &#39;.$typeid;

      //按时间搜索

      if($time == &#39;day&#39;) {

        $search_time = SYS_TIME - 86400;

        $sql_time = &#39; AND adddate > &#39;.$search_time;

      } elseif($time == &#39;week&#39;) {

        $search_time = SYS_TIME - 604800;

        $sql_time = &#39; AND adddate > &#39;.$search_time;

      } elseif($time == &#39;month&#39;) {

        $search_time = SYS_TIME - 2592000;

        $sql_time = &#39; AND adddate > &#39;.$search_time;

      } elseif($time == &#39;year&#39;) {

        $search_time = SYS_TIME - 31536000;

        $sql_time = &#39; AND adddate > &#39;.$search_time;

      } else {

        $search_time = 0;

        $sql_time = &#39;&#39;;

      }

      if($page==1 && !$setting[&#39;sphinxenable&#39;]) {

        //精确搜索

        $commend = $this->db->get_one("`siteid`= &#39;$siteid&#39; $sql_tid $sql_time AND `data` like &#39;%$q%&#39;");

      } else {

        $commend = &#39;&#39;;

      }

      //如果开启sphinx

      if($setting[&#39;sphinxenable&#39;]) {

        $sphinx = pc_base::load_app_class(&#39;search_interface&#39;, &#39;&#39;, 0);

        $sphinx = new search_interface();

         

        $offset = $pagesize*($page-1);

        $res = $sphinx->search($q, array($siteid), array($typeid), array($search_time, SYS_TIME), $offset, $pagesize, &#39;@weight desc&#39;);

        $totalnums = $res[&#39;total&#39;];

        //如果结果不为空

        if(!empty($res[&#39;matches&#39;])) {

          $result = $res[&#39;matches&#39;];

        }

      } else {

         

        $sql = "`siteid`= &#39;$siteid&#39; $sql_tid $sql_time AND `data` like &#39;%$q%&#39;";

         

  

        $result = $this->db->listinfo($sql, &#39;searchid DESC&#39;, $page, 10);

      }

       var_dump($result);

      //如果结果不为空

      if(!empty($result) || !empty($commend[&#39;id&#39;])) {

        foreach($result as $_v) {

          if($_v[&#39;typeid&#39;]) $sids[$_v[&#39;typeid&#39;]][] = $_v[&#39;id&#39;];

        }

  

        if(!empty($commend[&#39;id&#39;])) {

          if($commend[&#39;typeid&#39;]) $sids[$commend[&#39;typeid&#39;]][] = $commend[&#39;id&#39;];

        }

        $model_type_cache = getcache(&#39;type_model_&#39;.$siteid,&#39;search&#39;);

        $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, &#39;&#39;, &#39;id&#39;);

          //获取模型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(&#39;yp_content_model&#39;);

              $this->content_db->set_model($modelid);

  

            }

            $datas = $this->content_db->select($where, &#39;*&#39;);

          }

          $data = array_merge($data,$datas);

        }

        $pages = $this->db->pages;

        $totalnums = $this->db->number;

        

        //如果分词结果为空

        if(!empty($segment_q)) {

          $replace = explode(&#39; &#39;, $segment_q);

          foreach($replace as $replace_arr_v) {

            $replace_arr[] =  &#39;<font color=red>&#39;.$replace_arr_v.&#39;</font>&#39;;

          }

          foreach($data as $_k=>$_v) {

            $data[$_k][&#39;title&#39;] = str_replace($replace, $replace_arr, $_v[&#39;title&#39;]);

            $data[$_k][&#39;description&#39;] = str_replace($replace, $replace_arr, $_v[&#39;description&#39;]);

          }

        } else {

          foreach($data as $_k=>$_v) {

            $data[$_k][&#39;title&#39;] = str_replace($q, &#39;<font color=red>&#39;.$q.&#39;</font>&#39;, $_v[&#39;title&#39;]);

            $data[$_k][&#39;description&#39;] = str_replace($q, &#39;<font color=red>&#39;.$q.&#39;</font>&#39;, $_v[&#39;description&#39;]);

          }

        }

      }

      $execute_time = execute_time();

      $pages = isset($pages) ? $pages : &#39;&#39;;

      $totalnums = isset($totalnums) ? $totalnums : 0;

      $data = isset($data) ? $data : &#39;&#39;;

       

      includetemplate(&#39;search&#39;,&#39;list&#39;);

    } else {

      includetemplate(&#39;search&#39;,&#39;index&#39;);

    }

  }

  

   

  public function public_get_suggest_keyword() {

    $url = $_GET[&#39;url&#39;].&#39;&q=&#39;.$_GET[&#39;q&#39;];

    $trust_url = array(&#39;c8430fcf851e85818b546addf5bc4dd3&#39;);

    $urm_md5 = md5($url);

    if (!in_array($urm_md5, $trust_url)) exit;

     

    $res = @file_get_contents($url);

    if(CHARSET != &#39;gbk&#39;) {

      $res = iconv(&#39;gbk&#39;, CHARSET, $res);

    }

    echo $res;

  }

   

  /**

   * 提示搜索接口

   * TODO 暂时未启用,用的是google的接口

   */

  public function public_suggest_search() {

    //关键词转换为拼音

    pc_base::load_sys_func(&#39;iconv&#39;);

    $pinyin = gbk_to_pinyin($q);

    if(is_array($pinyin)) {

      $pinyin = implode(&#39;&#39;, $pinyin);

    }

    $this->keyword_db = pc_base::load_model(&#39;search_keyword_model&#39;);

    $suggest = $this->keyword_db->select("pinyin like &#39;$pinyin%&#39;", &#39;*&#39;, 10, &#39;searchnums DESC&#39;);

     

    foreach($suggest as $v) {

      echo $v[&#39;keyword&#39;]."\n";

    }

  

     

  }

}

?>

Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to jump to the details page in phpcms How to jump to the details page in phpcms Jul 27, 2023 pm 05:23 PM

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.

What framework is phpcms? What framework is phpcms? Apr 20, 2024 pm 10:51 PM

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.

WeChat Login Integration Guide: PHPCMS Practical Combat WeChat Login Integration Guide: PHPCMS Practical Combat Mar 29, 2024 am 09:18 AM

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]

What does phpcms mean? What does phpcms mean? Apr 20, 2024 pm 10:39 PM

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.

Isn't phpcms free? Isn't phpcms free? Mar 01, 2023 am 10:24 AM

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.

What database does phpcms use? What database does phpcms use? Feb 21, 2023 pm 06:57 PM

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.

What versions of phpcms are there? What versions of phpcms are there? Jun 14, 2023 pm 01:13 PM

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.

How to change the site name in phpcms How to change the site name in phpcms Feb 24, 2023 am 09:29 AM

How to modify the site name in phpcms: 1. Use the administrator to log in to the backend page; 2. Find the "Settings" option in the top menu bar and click it, then find "Site Management" in the menu on the left; 3. Find the item that needs to be modified site, click the modify link to the right of the site domain name; 4. Modify the site name in the pop-up window.

See all articles