/** * Get an array of all tags related to the specified tag, with relativity ranking * * The relativity ranking designates how many posts include both tags * * @param string $tag * @return array */ public static function getRelatedTags($tag) { $return = array(); $params = array('group' => true, 'startkey' => array($tag), 'endkey' => array($tag, array())); $tags = Geves_Model_Object::getDb()->view('tag', 'related', $params); foreach ($tags as $value) { $key = $tags->currentKey(); $return[$key[1]] = $value; } return $return; }
protected function _initDb() { $dbConfig = $this->_options['couchdb']; Geves_Model_Object::setDbConfig($dbConfig); if ($dbConfig['validate']) { // Make sure the DB exists try { $db = Sopha_Db::createDb($dbConfig['dbname'], $dbConfig['hostname'], $dbConfig['port']); } catch (Sopha_Db_Exception $ex) { if ($ex->getCode() != 412) { throw $ex; } $db = Geves_Model_Object::getDb(); } // Load design documents and create them $views = (require APPLICATION_PATH . '/configs/couchdb-views.php'); if (!is_array($views)) { throw new ErrorException("Unable to configure database views: \$views is not properly defined"); } foreach ($views as $view => $viewData) { try { $db->create($viewData, array('_design', $view)); } catch (Sopha_Db_Exception $ex) { if ($ex->getCode() == 409) { // document already exists if ($dbConfig['replaceViews']) { $view = $db->retrieve(array('_design', $view)); $view->fromArray($viewData); $db->update($view); } } else { throw $ex; } } } } }