本文整理汇总了PHP中Railpage\AppCore::getSphinxAPI方法的典型用法代码示例。如果您正苦于以下问题:PHP AppCore::getSphinxAPI方法的具体用法?PHP AppCore::getSphinxAPI怎么用?PHP AppCore::getSphinxAPI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Railpage\AppCore
的用法示例。
在下文中一共展示了AppCore::getSphinxAPI方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPhotosFromSphinx
/**
* Get photos from the Sphinx search API within or adjacent to this place
* @since Version 3.9.1
* @param int $num
* @return array
*/
public function getPhotosFromSphinx($num = 10)
{
$Sphinx = AppCore::getSphinxAPI();
$Sphinx->SetGeoAnchor("lat", "lon", deg2rad($this->lat), deg2rad($this->lon));
$Sphinx->SetFilterRange("@geodist", 0, 5000);
// 1km radius
$Sphinx->SetSortMode(SPH_SORT_EXTENDED, '@geodist ASC');
$result = $Sphinx->query("", "idx_images");
$return = array("stat" => "ok");
if (!$result) {
$return['stat'] = "err";
$return['message'] = $Sphinx->getLastError();
return $return;
}
if (empty($result['matches'])) {
return $return;
}
foreach ($result['matches'] as $row) {
$meta = json_decode($row['attrs']['meta'], true);
$return['photos'][] = array("id" => $row['attrs']['image_id'], "provider" => $row['attrs']['provider'], "photo_id" => $row['attrs']['photo_id'], "url" => $row['attrs']['url'], "distance" => round($row['attrs']['@geodist']), "lat" => rad2deg($row['attrs']['lat']), "lon" => rad2deg($row['attrs']['lon']), "title" => empty(trim($row['attrs']['title'])) ? "Untitled" : $row['attrs']['title'], "description" => $row['attrs']['description'], "sizes" => Images::normaliseSizes($meta['sizes']));
}
$return['photos'] = array_slice($return['photos'], 0, $num);
return $return;
}
示例2: findCorrectArticle
/**
* Find articles with similar titles (good for 404 errors)
* @since Version 3.9.1
* @return array
* @param string $lookup The text to search Sphinx for
* @param int $num The maximum number of results to return
*/
public static function findCorrectArticle($lookup = false, $num = 5)
{
$Sphinx = AppCore::getSphinxAPI();
$Sphinx->setLimits(0, $num);
$results = $Sphinx->query($Sphinx->escapeString($lookup), "idx_news_article");
return isset($results['matches']) ? $results['matches'] : array();
}
示例3: getRelatedArticles
/**
* Find related news articles
* @since Version 3.9
* @return array
*
* @param int $num The maximum number of results to return
*/
public function getRelatedArticles($num = 5)
{
$SphinxQL = $this->getSphinx();
$title = preg_replace("/[^[:alnum:][:space:]]/u", '', $this->title);
$title = trim($title);
$title = str_replace(" ", "|", $title);
$query = $SphinxQL->select("*")->from("idx_news_article")->match(array("story_title", "story_paragraphs"), $title, true)->where("story_id", "!=", $this->id)->where("story_time_unix", "BETWEEN", array(strtotime("1 year ago", time()), time()))->limit($num)->option("ranker", "proximity_BM25");
$matches = $query->execute();
if (count($matches)) {
return $matches;
}
return array();
$Sphinx = AppCore::getSphinxAPI();
$Sphinx->setFilter("topic_id", array($this->Topic->id));
$Sphinx->setFilter("story_id", array($this->id), true);
$Sphinx->setFilterRange("story_time_unix", strtotime("1 year ago"), time());
$Sphinx->setLimits(0, $num);
$results = $Sphinx->query($Sphinx->escapeString($this->title), "idx_news_article");
return isset($results['matches']) ? $results['matches'] : array();
}