/** * @desc Слэширует символы поиска */ function makeSearchString($str) { return to_search_string($str); }
/** * Метод осуществляет поиск по карте сайте * @param string $szKeyword строка поисковая ключа * @return array */ public static function search($szKeyword, $nStart, $nLimit, $filter = array()) { $szKeyword = to_search_string($szKeyword); $nStart = intval($nStart); $nLimit = intval($nLimit); // if (strlen($szKeyword) < 2) { throw new Exception('Can`t start search. Search keyword too small'); } if (!empty($filter)) { foreach ($filter as $key => $row) { $filter[$key] = '"' . DB::escape($row) . '"'; } $sqlFilter = sprintf(' and `document_name` in (%s)', implode(',', $filter)); } else { $sqlFilter = ''; } $sql = 'SELECT SQL_CALC_FOUND_ROWS *,UNIX_TIMESTAMP(`date_updated`) as `unixtimestamp` FROM `%s` WHERE ( `name` LIKE "%%%s%%" or `full_url` LIKE "%%%s%%" ) and (`document_id` != 0 or LENGTH(`script_admin_url`) > 0) %s ORDER by `name` LIMIT %d,%d'; $sql = sprintf($sql, SITEMAP_TABLE, $szKeyword, $szKeyword, $sqlFilter, $nStart, $nLimit); $aResult = DB::query($sql); $sql = 'SELECT FOUND_ROWS() as `totalcount`'; $aFound = DB::Get($sql); self::$nItemCount = $aFound['totalcount']; return $aResult; }
protected static function buildSQLSelectCondition() { $parts = array(); if (!empty(self::$lastSearchRequest->search_phrase)) { $parts[] = sprintf('( `short` like "%%%s%%" or `full` like "%%%s%%" )', to_search_string(self::$lastSearchRequest->search_phrase), to_search_string(self::$lastSearchRequest->search_phrase)); } $emptyDate = '0000-00-00 00:00:00'; $validateDateFrom = !empty(self::$lastSearchRequest->date_from) && $emptyDate != self::$lastSearchRequest->date_from; if ($validateDateFrom) { $parts[] = sprintf('a.date >= "%s"', DB::escape(selF::$lastSearchRequest->date_from)); } $validateDateTo = !empty(self::$lastSearchRequest->date_to) && $emptyDate != self::$lastSearchRequest->date_to; if ($validateDateTo) { $parts[] = sprintf('a.date <= "%s"', DB::escape(selF::$lastSearchRequest->date_to)); } if (!empty(self::$lastSearchRequest->user)) { $parts[] = sprintf(' a.user_login = "******"', DB::escape(self::$lastSearchRequest->user)); } if (!empty($parts)) { return implode(' and ', $parts); } else { return ' 1 '; } }
/** * Отыскивает пользователя по части его логина * @return */ public static function searchByLogin($szKey) { $szKey = trim($szKey); if (strlen($szKey) < 2) { throw new Exception('Search key too small'); } $sql = 'SELECT id,login,email FROM `%s` WHERE `login` LIKE "%%%s%%" order by `login` ASC'; $sql = sprintf($sql, USERS_TABLE, to_search_string($szKey)); return DB::query($sql); }