/** * @param a search term as entered by "the user". **/ private function getWikiTitleFromBoss($searchTerm) { if (!$this->conf['SEARCH_API_KEY']) { array_push($this->lastErrors, "No SEARCH_API_KEY was set"); return false; } $curl = new CurlCall(); $method = "yahoo.boss"; $url = 'http://' . $this->conf['SEARCH_DOMAIN'] . $this->conf['SEARCH_API'] . urlencode($searchTerm) . '?appid=' . $this->conf['SEARCH_API_KEY'] . '&sites=' . urlencode($this->conf['WIKI_DOMAIN']); $result = $curl->getFromJsonSource($url, array('cache-ident' => $method, 'cache-time' => $this->conf['SEARCH_CACHE_TIME'], 'user-agent' => 'WikiSlurp (http://github.com/NeilCrosby/wikislurp)')); if ($aData = $this->getDataFromArray($result, array('ysearchresponse', 'resultset_web'))) { $bestDataPoint = 0; $bestCount = 0; for ($i = 0; $i < sizeof($aData); $i++) { $nTitle = preg_match_all('/<b>/', $aData[$i]['title'], $matches); $nAbstract = preg_match_all('/<b>/', $aData[$i]['abstract'], $matches); $count = 10 * $nTitle + $nAbstract; if ($count > $bestCount) { $bestDataPoint = $i; $bestCount = $count; } } $data = $aData[$bestDataPoint]; $url = $data['url']; $lastSlashPos = strrpos($url, $this->conf['WIKI_BASE_DIR']); $wikiQuery = substr($url, $lastSlashPos + strlen($this->conf['WIKI_BASE_DIR'])); $wikiUrlTitle = strrchr($wikiQuery, '_') ? urlencode($wikiQuery) : urlencode(ucwords($wikiQuery)); return $wikiUrlTitle; } return false; }
/** * @param a search term as entered by "the user". **/ private function getWikiTitleFromBoss($searchTerm) { if (!$this->conf['SEARCH_API_KEY']) { return false; } $curl = new CurlCall(); $method = "yahoo.boss"; $url = 'http://' . $this->conf['SEARCH_DOMAIN'] . $this->conf['SEARCH_API'] . urlencode('site:' . $this->conf['WIKI_DOMAIN'] . ' ' . $searchTerm) . '?appid=' . $this->conf['SEARCH_API_KEY']; $result = $curl->getFromJsonSource($url, array('cache-ident' => $method, 'cache-time' => $this->conf['SEARCH_CACHE_TIME'])); if ($data = $this->getDataFromArray($result, array('ysearchresponse', 'resultset_web', 0))) { $url = $data['url']; $lastSlashPos = strrpos($url, $this->conf['WIKI_BASE_DIR']); $wikiQuery = substr($url, $lastSlashPos + strlen($this->conf['WIKI_BASE_DIR'])); $wikiUrlTitle = strrchr($wikiQuery, '_') ? urlencode($wikiQuery) : urlencode(ucwords($wikiQuery)); return $wikiUrlTitle; } return false; }