当前位置: 首页>>代码示例>>PHP>>正文


PHP search::prepare_string方法代码示例

本文整理汇总了PHP中search::prepare_string方法的典型用法代码示例。如果您正苦于以下问题:PHP search::prepare_string方法的具体用法?PHP search::prepare_string怎么用?PHP search::prepare_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在search的用法示例。


在下文中一共展示了search::prepare_string方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

	function get_data() {
		global $url; global $error; global $search; global $sets;
		$return['display'] = array('search_info','search_content','navi');
		if (!in_array($url[2],$this->areas)) {
			$area = str_split($url[2]);
			foreach ($area as &$one) $one = $this->areas[$one];
			$area = array_filter($area);
			unset($one);
		} else {
			$area = array($url[2]);
		}

		$pp = $sets['pp']['search'];

		if ($url[3] != 'rel') {
			$main = 'and s.area="main"';
			$lim = (max(1,$url[6])-1)*$pp.', '.$pp;

			if ($url[3] == 'date') {
				$limit = ' order by s.sortdate desc limit '.$lim;
			} elseif ($url[3] == 'rdate') {
				$limit = ' order by s.sortdate limit '.$lim;
			}
		}

		if (empty($area)) $return['display'] = array('search_info','search_error');
		else {
			if (!$search) $search = new search();
			$request = urldecode($url[4]);
//			$request = preg_replace('/(\s|^)('.implode('|',$this->minus_words).')\s+(?=[^\s])/uis', ' -', $request);
			$request = preg_replace('/(\s|^)('.implode('|',$this->cyrillic_stoplist).')\s*/uis', ' ', $request);
			$terms = $search->parse_text($request);

			if ($search->error == true) {
				$error = true;
				return;
			}

			$pretty_query = $search->prepare_string(urldecode($url[4]),true);

			if (empty($terms)) $return['display'] = array('search_info','search_error');
			else {
				foreach ($terms as $term) {
					if (mb_strlen($term, 'UTF-8') > 3) $longterms[] = str_replace('-','_',$term);
					else $shortterms[] = $term;
				}

				if (!empty($longterms)) {
					$longquery = ' and match (s.`index`) against ("'.implode(' ',$longterms).'" in boolean mode)';
				}
				if (!empty($shortterms)) {
					$shortquery = '';
					foreach ($shortterms as $shortterm) {
						$not = $shortterm{0} == '-';
						$shortquery .= 'and s.`index` '.($not ? 'not ' : '').'like "%|'.substr($shortterm,1).'=%"';
					}
				}

				if (empty($query)) {
					$query = '(s.place="'.implode('" or s.place="',$area).'") '.$main.$shortquery.$longquery.$limit;
					$navi_query = '(s.place="'.implode('" or s.place="',$area).'") '.$main.$shortquery.$longquery;
				}
				$data = obj::db()->sql('select s.place, s.item_id, s.`index`, s.area, s.sortdate from search as s where ' . $query);

				if (empty($data)) {
					$data = $this->search_in_titles($area, $pretty_query);
				}

				if (empty($data)) {
					foreach ($area as $one) $zero[] = 0;
					obj::db()->update('search_queries',$area,$zero,$pretty_query,'query');
					$return['variants'] = $this->get_variants($pretty_query, $area);
					$return['display'] = array('search_info','search_error');
				} else {
					if (!$limit) {
						$return['navi']['last'] = ceil(count($data)/$pp);

						$this->weights = obj::db()->sql('select place, weight from search_weights','place');
						if (count($terms) > 1) $data = $this->relevance($data,$terms,$pp,max(1,$url[6]));
						else $data = $this->relevance_simple($data,$terms,$pp,max(1,$url[6]));
					} else {
						$return['navi']['last'] = ceil(obj::db()->sql('select count(*) from search as s where '. $navi_query,2)/$pp);
					}

					foreach ($data as $one) {
						$function = 'fetch_'.$one['place'];
						$return['data'][] = $this->$function($one['item_id']);
						$found[$one['place']] = true;
					}

					foreach ($area as $one) {
						$update .= ($found[$one] ? ", ".$one."=".$one."+1" : '');
						$insert .= ", ".($found[$one] ? 1 : 0);
					}
					if (!strpos($pretty_query, 'md5:'))
					{
						obj::db()->sql("insert into search_queries (`id` ,`query` ,`length` , `".implode("` ,`",$area)."`) values('','".$pretty_query."',".mb_strlen($pretty_query).$insert.") on duplicate key update ".substr($update,1).";",0);
					}

					$return['navi']['curr'] = max(1,$url[6]);
//.........这里部分代码省略.........
开发者ID:4otaku,项目名称:4otaku,代码行数:101,代码来源:search.php

示例2: search

 function search($query, $page)
 {
     global $search;
     if (!$search) {
         $search = new search();
     }
     $return = array();
     $return['display'] = array('logs_search', 'logs_results', 'navi');
     $perpage = 10;
     $start = ($page - 1) * $perpage;
     $base = substr(get_called_class(), 8);
     $query = $search->prepare_string(urldecode($query), true);
     $mark = preg_split('/\\s+/s', $query);
     $fixed_query = '+' . preg_replace('/\\s+/s', ' +', $query);
     $select_query = ' MATCH (text) AGAINST ("' . $fixed_query . '" IN BOOLEAN MODE) and cache_key = ' . static::$cache_key;
     $sql = 'SELECT id, date FROM raw_logs WHERE' . $select_query;
     $days = obj::db()->sql($sql . ' group by date order by date desc limit ' . $start . ', ' . $perpage, 'id');
     if (!empty($days)) {
         $select_days = '"' . implode('","', $days) . '"';
         $data = obj::db()->sql('SELECT `date`, `time`, `text` FROM raw_logs WHERE `date` in (' . $select_days . ') and' . $select_query);
         foreach ($days as $day) {
             foreach ($data as $key => $log) {
                 if ($log['date'] == $day) {
                     $return['days'][$day][] = array('time' => $log['time'], 'text' => $this->format_logs($log['text'], false, $mark));
                     unset($data[$key]);
                     if (count($return['days'][$day]) > 4) {
                         break;
                     }
                 }
             }
         }
         $return['navi']['meta'] = '/' . $base . '/search/' . $query . '/';
         $return['navi']['curr'] = $page;
         $return['navi']['start'] = max($return['navi']['curr'] - 5, 2);
         $return['navi']['last'] = ceil(obj::db()->sql('select count(distinct(date)) from raw_logs WHERE MATCH (text) AGAINST ("' . $fixed_query . '" IN BOOLEAN MODE) and cache_key = ' . static::$cache_key, 2) / $perpage);
     } else {
         $return['display'] = array('logs_search', 'logs_results');
     }
     $return['log_base'] = $base;
     return $return;
 }
开发者ID:4otaku,项目名称:4otaku,代码行数:41,代码来源:logs_abstract.php


注:本文中的search::prepare_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。