本文整理汇总了PHP中Search类的典型用法代码示例。如果您正苦于以下问题:PHP Search类的具体用法?PHP Search怎么用?PHP Search使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Search类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: search_query
public static function search_query($keyword = '', $category = '')
{
if (isset($_GET)) {
$keyword_clean = mysqli_real_escape_string(db_connect(), $keyword);
$category_clean = mysqli_real_escape_string(db_connect(), $category);
if ($category_clean === 'post') {
$search_results = db_select("SELECT * FROM post WHERE title LIKE '%" . $keyword_clean . "%' OR body LIKE '%" . $keyword_clean . "%'");
} elseif ($category_clean === 'category') {
$search_results = db_select("SELECT * FROM category WHERE title LIKE '%" . $keyword_clean . "%' OR description LIKE '%" . $keyword_clean . "%'");
} elseif ($category_clean === 'page') {
$search_results = db_select("SELECT * FROM page WHERE title LIKE '%" . $keyword_clean . "%' OR body LIKE '%" . $keyword_clean . "%'");
} elseif ($category_clean === 'upload') {
$search_results = db_select("SELECT * FROM upload WHERE filename LIKE '%" . $keyword_clean . "%' OR filetype LIKE '%" . $keyword_clean . "%' OR filepath LIKE '%" . $keyword_clean . "%'");
} elseif ($category_clean === 'user') {
$search_results = db_select("SELECT * FROM user WHERE username LIKE '%" . $keyword_clean . "%'");
} else {
// ALL
$search = new Search();
$search_results = $search->searchAllDB($keyword_clean);
//print_r($search_results);
}
} else {
$search_results = '';
$flash = new Flash();
$flash->flash('flash_message', 'No keyword entered!', 'danger');
}
return $search_results;
}
示例2: index
function index()
{
$q = trim(Input::get('q'));
if (empty($q) || !Input::has('q')) {
return Redirect::home();
}
if (!Input::has('guess') || Input::get('guess') != 'no') {
$regex = array('pilot' => '[0-9]+', 'airport' => '[A-Z0-9]{4}', 'airline' => '[A-Z0-9]{3}', 'airportIata' => '[A-Z0-9]{3}', 'citypair' => '([A-Z0-9]{3,4})(?:(?:\\s*?[-|>]\\s*?)|\\s+to\\s+|\\s+)([A-Z0-9]{3,4})', 'callsign' => '.*');
$search = new Search($q);
foreach ($regex as $type => $pattern) {
if (preg_match('/^' . $pattern . '$/i', $q, $matches) && ($match = $search->quick($type, $matches))) {
Messages::info('You were redirected here by a best guess of the search system. <a href="' . URL::route('search', array('q' => $q, 'guess' => 'no')) . '" class="alert-link">Return to search results.</a>');
return $match;
}
}
}
$pilots = Pilot::where(function ($search) use($q) {
$search->where('vatsim_id', '=', $q);
$search->orWhere(function ($name) use($q) {
$name->where('name', 'LIKE', '%' . $q . '%');
$name->where('anonymous', '=', false);
});
})->where('vatsim_id', '!=', 0)->get();
$flights = Flight::where('callsign', '=', $q)->orderBy('departure_time', 'desc')->get();
$airlines = Airline::where('icao', '=', $q)->orWhere('name', 'LIKE', '%' . $q . '%')->get();
$airports = Airport::where('icao', '=', $q)->orWhere('iata', '=', $q)->orWhere('name', 'LIKE', '%' . $q . '%')->orWhere('city', 'LIKE', '%' . $q . '%')->get();
$this->autoRender(compact('q', 'flights', 'pilots', 'airlines', 'airports'), 'Search');
}
示例3: view
public function view()
{
$dao = DAO::getDAO('SearchDAO');
if (isset($this->params[0]) && trim($this->params[0]) == 'remove') {
// ex: requesting: /search/delete/2
$id = trim(sanitizeString($this->params[1]));
$dao->removeById($id);
} else {
if (isset($this->params[0]) && trim($this->params[0]) == 'add') {
$randNum = mt_rand(0, 99999);
$newSearch = new Search(array('username' => "test{$randNum}", 'email' => "test{$randNum}@example.com", 'created' => dbDateTime()));
// #TODO: implement UserDao.create($newUser) instead.
if ($dao->countAll() > 30) {
// Demo mode: clean up if too many searchs
$dao->execute("DELETE FROM searchs");
$dao->execute("vacuum");
}
$dao->insertInto("username, email, created", $newSearch->getFields());
}
}
$search = $dao->getAll();
$v = $this->smarty;
$v->assign('title', 'Search List');
$v->assign('inc_content', v('search.html'));
$v->assign('search', $search);
$v->assign('totalSearch', $dao->countAll());
$this->display($v, v('index.html'));
}
示例4: testShouldGenerateSearchStringArray
public function testShouldGenerateSearchStringArray()
{
$params = array('CISOROOT' => 'all', 'CISOOP1' => 'any', 'CISOFIELD1' => 'creato', 'CISOBOX1' => 'michigan lake', 'CISOOP2' => 'all', 'CISOFIELD2' => 'title', 'CISOBOX2' => 'general grant', 'media-types' => array('image', 'audio', 'map', 'docs'), 'search-button.x' => '61', 'search-button.y' => '19', 'search-button' => '');
$search = new Search();
$search->set_search_string($params);
$this->assertEquals('creato', $search->search_string[0]['field']);
}
示例5: indexAction
public function indexAction()
{
$key = $this->getRequest()->get('kw');
$orderby = $this->getRequest()->get('od');
$page = $this->getRequest()->get('page', 1);
// $router = \Yaf\Dispatcher::getInstance()->getRouter();
// $config = \Yaf\Application::app()->getConfig();
$search = new Search();
$search->setQ($key);
$search->setPage($page);
if (!empty($orderby)) {
$search->setSortby($orderby);
}
$res = $search->query();
$pages = 1;
$films = null;
if ($res) {
$pages = empty($res['pages']) ? 1 : $res['pages'];
if (isset($res['matches'])) {
foreach ($res['matches'] as $match) {
$ids[] = $match['id'];
}
$conn = new MyPDO();
$films = $conn->table('film')->select('*')->where('id in (' . implode(',', $ids) . ')')->orderBy('order by find_in_set (id, \'' . implode(',', $ids) . '\')')->execute();
}
}
$this->_view->assign('films', $films);
$this->_view->assign('kw', $key);
$this->_view->assign('orderby', $orderby);
$this->_view->assign('page', $page);
$this->_view->assign('pages', $pages);
}
示例6: show
private function show($q)
{
include 'lib/search.php';
$search = new Search();
$items = $search->do_search($q);
foreach ($items as $item) {
$item->content = process_content($item->content);
foreach ($item->comments as $comment) {
$comment->content = process_content($comment->content);
}
foreach ($item->likes as $like) {
if (isset($_SESSION['user_id']) && $like->user_id == $_SESSION['user_id']) {
$item->i_like = true;
} else {
$item->i_like = false;
}
}
}
if (isset($this->plugins->log)) {
$result_count = count($items);
$this->plugins->log->add($_SESSION['user_id'], 'search', NULL, 'new', "Term = {$q}\nResult_count = {$result_count}");
}
if ($this->json) {
$this->render_json($items);
} else {
$this->loadView('search/index', array('items' => $items));
}
}
示例7: getBookSearchResults
public function getBookSearchResults()
{
$search = new Search();
$books = $search->searchBook($_POST['searchstring']);
include 'view/libro/search_menu.php';
include 'view/libro/libros.php';
}
示例8: get_top_recommendations
public function get_top_recommendations($query_name, $number)
{
$auth = Clarifai::get_auth($this->client_id, $this->client_secret);
$matches = $this->get_initial_recommendations($query_name, $number);
// Get initial recommended movies
$number = count($matches);
if ($number <= 0) {
return NULL;
}
$query = new Search($query_name);
$query_links = $query->get_links();
// Get links to query stills using Google Images API
$links = array();
$links[$query_name] = $query_links;
// Array containing links
foreach ($matches as $match) {
// Get stills to each of the initial recommended movies
$match_search = new Search($match);
$links[$match] = $match_search->get_links();
// Add links to array
}
$tags_array = Clarifai::get_unique_tags($links, $auth);
// Get tags using Clarifai API
$results = array();
foreach (array_slice($tags_array, 1, $number) as $key => $tags) {
$results[$key] = count(array_intersect($tags, $tags_array[$query_name]));
}
arsort($results);
return array_keys($results);
}
示例9: testAnnotations
public function testAnnotations()
{
$s = new Search('reddress');
$s->setUid('b1cb66795dfb0ff41fff56c841c0dea8');
$s->setTqid('D9XmaeqdjAxrkDPX');
$this->assertEquals('q=reddress&tqid=D9XmaeqdjAxrkDPX&uid=b1cb66795dfb0ff41fff56c841c0dea8', $s->getUrlString());
}
示例10: getUserLabels
/**
* getUserLabels Helper
*
* @param array $data
* @param function $callback
* @return mixed
*/
static function getUserLabels(array $data, $callback = false)
{
// validate data parameters
if (!isset($data['website'])) {
throw new \InvalidArgumentException('website is required.');
}
// validate data parameters
if (!isset($data['search'])) {
throw new \InvalidArgumentException('search is required.');
}
$woopra_labels = Woopra::getAllLabels($data);
$search = new Search($data);
$rsp = $search->search(array('website' => $data['website'], 'search' => $data['search']));
$labels = array();
foreach ($rsp->visitors as $visitor) {
foreach ($visitor->labels as $label) {
if (array_key_exists($label, $woopra_labels)) {
$labels[$label] = $woopra_labels[$label];
}
}
}
// run callback or return the label data
if (is_callable($callback)) {
$callback($labels);
} else {
return $labels;
}
}
示例11: searchPostAction
public function searchPostAction($search)
{
$admin = new Search();
$searchResult = $admin->setSearchItem($_GET['search'], 'posts');
require_once ROOT_PATH . DIRECTORY_SEPARATOR . 'templates/front/header.php';
require_once ROOT_PATH . DIRECTORY_SEPARATOR . 'templates/front/search.php';
require_once ROOT_PATH . DIRECTORY_SEPARATOR . 'templates/front/footer.php';
}
示例12: testFiter
public function testFiter()
{
$s = new Search('');
$s->addFilter((new Filter('tags', '=', 'Women'))->addOr('tags', '=', 'dress pants'));
$r = $this->engine->search($s);
$this->assertEquals($r->results->hits[0]->id, 'f346904e7dcd43c521bff2e6dcfae21a');
$this->assertEquals($r->results->hits[1]->id, 'c05ef333b5dbd9f31123a65221762395');
}
示例13: solrSearch
/**
* Search with solr & prepare data for output
*
* @param $p options
* @param $prepare bool
*/
private function solrSearch($p, $prepare = false)
{
// skip grid params
unset($p->grid);
$p->fl = 'id, pid, path, name, template_type, system, ' . 'size, date, date_end, oid, cid, cdate, uid, udate, case_id, acl_count, ' . 'case, template_id, task_u_assignee, status, task_d_closed, versions, ' . 'case_violation_resolved, case_violation_unresolved, cfg, type, nid, ' . 'search_hash, case_hash';
$s = new Search();
return $s->query($p);
}
示例14: Search
public function Search($param)
{
//echo "hello";
import('SC.Search.Search');
$searchInfo = new Search($param);
$result = $searchInfo->run();
echo $result;
}
示例15: before_render
public function before_render(&$template, &$content)
{
parent::before_render($template, $content);
/*
* Create the browser title.
*/
if (strlen($content->get('browser_title')) === 0) {
if (strlen($content->get('page_title')) > 0) {
$content->set('browser_title', $content->get('page_title'));
$content->append('browser_title', ' - ' . SITE_TITLE);
} else {
$content->set('browser_title', SITE_TITLE);
}
} else {
$content->append('browser_title', ' - ' . SITE_TITLE);
}
/*
* Include the place name (e.g., "Washington," "Texas," "United States").
*/
$content->set('place_name', PLACE_NAME);
/*
* Get the edition data
*/
$search = new Search();
// Since we don't have any conditions in our template, we have to build
// html here.
if (!$content->is_set('current_edition') && defined('EDITION_ID')) {
$content->set('current_edition', EDITION_ID);
}
$content->set('edition_select', $search->build_edition($content->get('current_edition')));
/*
* Set our search terms.
*/
$query = '';
if (isset($_GET['q'])) {
$query = $_GET['q'];
}
$content->set('search_terms', $query);
/*
* If a Google Analytics Web Property ID has been provided, insert the tracking code.
*/
if (defined('GOOGLE_ANALYTICS_ID')) {
$content->prepend('javascript', "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n\t\t\t\t(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n\t\t\t\tm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n\t\t\t\t})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\n\t\t\t\tga('create', '" . GOOGLE_ANALYTICS_ID . "', 'auto');\n\t\t\t\tga('send', 'pageview');");
}
/*
* If a Typekit ID has been provided, insert the JavaScript.
*/
if (defined('TYPEKIT_ID')) {
$this->add_asset('typekit_js', array('path' => '//use.typekit.net/' . TYPEKIT_ID . '.js', 'type' => 'javascript'));
$content->append('javascript', 'try{Typekit.load();}catch(e){};');
}
$content->append('javascript', 'var zclip_swf_file = "' . THEME_WEB_PATH . 'static/js/vendor/ZeroClipboard.swf";');
/*
* Setup assets
*/
$this->render_assets($template, $content);
}