svn checkout yandex.googlecode.com/svn/trunk yandex-read-only
require_once 'Yandex.php';
// "query", "page" "host" request'
$query = isset($_REQUEST['query'])?$_REQUEST['query']:'';
$page = isset($_REQUEST['page']) ?$_REQUEST['page']:0;
$host = isset($_REQUEST['host']) ?$_REQUEST['host']:null;
if ($ query) { // create an instance of the Yandex class $ Yandex = new Yandex (); $ Yandex -> query ($ query) // set the search query -> host ($ host) // limit to site search -> page ($ page) // current page -> limit (10) // results per page -> set ('max-title-length', 160) // fine tuning of the search results (see http://code.google.com/p/yandex/source/browse/trunk/Yandex.php#48) -> set ('max-passage-length', 200) -> request () // send request ; }
// check if everything is smooth if (isset ($ Yandex) && empty ($ Yandex-> ​​error)): // this is how we knock on the results foreach ($ Yandex-> ​​result-> response-> results-> grouping-> group as $ group): // display URL echo $ group-> doc-> url; // header output - Yandex :: highlight method selects the search phrase Yandex :: highlight ($ group-> doc-> title); // display passages foreach ($ group-> doc-> passages-> passage as $ passage): Yandex :: highlight ($ passage); endforeach; endforeach; // next we display page navigation, it is a bit cumbersome foreach ($ Yandex-> ​​pageBar () as $ page => $ value): // switch statement for $ value ['type'] switch ($ value ['type']) { // link to the page case 'link': echo '<a href="'. $url .'&page=' $ $ .'" title="Page'. ($page+1) .'">'. sprintf ($ value ['text'], $ page + 1). '</a> | '; break; // current page case 'current': echo sprintf ($ value ['text'], $ page + 1). ' | '; break; // delimiter text - ".." case 'text': echo $ value ['text']. ' | '; break; default: break; } endforeach; // if something is wrong - we display an error elseif (isset ($ Yandex) && isset ($ Yandex-> ​​error)): echo $ Yandex-> ​​error; endif;
// - :
$Smarty->assign("Yandex", $Yandex);
Source: https://habr.com/ru/post/37402/
All Articles