public function saveAction() { $values = Zend_Json::decode($this->getParam("data")); // convert all special characters to their entities so the xml writer can put it into the file $values = array_htmlspecialchars($values); try { $sphinx_config = new SphinxSearch_Config(); $sphinx_config->writeSphinxConfig(); $plugin_config = new SphinxSearch_Config_Plugin(); $config_data = $plugin_config->getData(); $config_data["path"]["pid"] = $values["sphinxsearch.path_pid"]; $config_data["path"]["querylog"] = $values["sphinxsearch.path_querylog"]; $config_data["path"]["log"] = $values["sphinxsearch.path_logfile"]; $config_data["path"]["indexer"] = $values["sphinxsearch.path_indexer"]; $config_data["path"]["phpcli"] = $values["sphinxsearch.path_phpcli"]; $config_data["path"]["searchd"] = $values["sphinxsearch.path_searchd"]; $config_data["indexer"]["period"] = $values["sphinxsearch.indexer_period"]; $config_data["indexer"]["runwithmaintenance"] = $values["sphinxsearch.indexer_maintenance"] == "true" ? "true" : "false"; $config_data["indexer"]["onchange"] = $values["sphinxsearch.indexer_onchange"]; $config_data["documents"]["use_i18n"] = $values["sphinxsearch.documents_i18n"] == "true" ? "true" : "false"; $config_data["searchd"]["port"] = $values["sphinxsearch.searchd_port"]; $plugin_config->setData($config_data); $plugin_config->save(); $this->_helper->json(array("success" => true)); } catch (Exception $e) { $this->_helper->json(false); } }
/** * SphinxSearch_Backend Constructor * * @param SphinxSearch_Config $config * @return SphinxSearch_Backend */ function SphinxSearch_Backend($config) { $this->config = $config; $this->view = $config->get_view(); if (!empty($_GET['menu']) && !empty($_REQUEST['action'])) { if ('terms_editor' == $_GET['menu'] && $_REQUEST['action'] == 'export') { $terms_editor = new TermsEditorController($this->config); $terms_editor->_export_keywords(); } } }
private function getDocumentIds() { if ($this->search_result_ids === null) { $sphinx_config = SphinxSearch_Config::getInstance(); $documents_config = $sphinx_config->getDocumentsAsArray(); $query = $this->query; if (!$this->getUnpublished()) { $query = $query . " @o_published 1"; } $language = "all"; if ($this->plugin_config->documents->use_i18n == "true") { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); } foreach ($documents_config as $document_name => $document_properties) { $indexes[] = "idx_document_" . $document_name . "_" . $language; } $search_result = $this->SphinxClient->Query($query, implode(", ", $indexes)); if ($search_result === false) { throw new Exception($this->SphinxClient->GetLastError()); } if ($search_result["total_found"] > 0) { $this->search_result_ids = array_keys($search_result["matches"]); } else { $this->search_result_ids = array(); } } return $this->search_result_ids; }
/** * Returns an instance of SphinxSearch_Config * * Singleton pattern implementation * * @return SphinxSearch_Config */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; }
public function __construct($query, $class_name) { parent::__construct($query); $class_name = strtolower($class_name); $this->class_name = $class_name; $sphinx_config = SphinxSearch_Config::getInstance(); $class_config = $sphinx_config->getClassesAsArray(); // The configuration $field_weights = array(); foreach ($class_config[$this->class_name] as $field_name => $field_config) { if (array_key_exists("weight", $field_config)) { $field_weights[$field_name] = $field_config["weight"]; } } if (sizeof($field_weights) > 0) { $this->SphinxClient->setFieldWeights($field_weights); } }
function _get_stat_keywords($page, $period_param) { $start = ($page - 1) * $this->_keywords_per_page; if ($period_param > 0) { $this->_sphinx->SetFilterRange("date_added", strtotime("-{$period_param} days"), time()); } $sort_order = 'desc'; if (!empty($_REQUEST['sort_order']) && strtolower($_REQUEST['sort_order']) == 'asc') { $sort_order = 'asc'; } $sort_by_param = !empty($_REQUEST['sort_by']) ? $_REQUEST['sort_by'] : 'date'; switch (strtolower($sort_by_param)) { case 'cnt': $sort_by = '@count'; break; case 'date': default: $sort_by = 'date_added'; break; } $this->_sphinx->SetGroupBy("keywords_crc", SPH_GROUPBY_ATTR, "{$sort_by} {$sort_order}"); if ('asc' == $sort_order) { $this->_sphinx->SetSortMode(SPH_SORT_ATTR_ASC, "date_added"); } else { $this->_sphinx->SetSortMode(SPH_SORT_ATTR_DESC, "date_added"); } $this->_sphinx->SetLimits($start, $this->_keywords_per_page); $res = $this->_sphinx->Query("", $this->_config->get_option('sphinx_index') . 'stats'); if (empty($res['matches'])) { return array(); } $this->_results = $res; $ids = array_keys($res['matches']); $sql = 'select id, keywords, date_added from ' . $this->_table_prefix . 'sph_stats where id in (' . implode(',', $ids) . ') order by FIELD(id, ' . implode(',', $ids) . ')'; $keywords = $this->_wpdb->get_results($sql, OBJECT_K); foreach ($res['matches'] as $index => $match) { $keywords[$index]->cnt = $match['attrs']['@count']; } return $keywords; }
function _get_new_keywords($page, $status) { $sterm_value = !empty($_REQUEST['sterm']) ? $_REQUEST['sterm'] : ''; switch ($status) { case 'approved': $status_filter = array(1); $sort_order = "@count desc"; break; case 'ban': $status_filter = array(2); $sort_order = "@count desc"; break; case 'new': default: $status_filter = array(0); $sort_order = "date_added desc"; break; } $start = ($page - 1) * $this->_keywords_per_page; $this->_sphinx->SetFilter('status', $status_filter); $this->_sphinx->SetGroupBy("keywords_crc", SPH_GROUPBY_ATTR, $sort_order); $this->_sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'date_added'); $this->_sphinx->SetLimits($start, $this->_keywords_per_page); $res = $this->_sphinx->Query($sterm_value, $this->_config->get_option('sphinx_index') . 'stats'); if (empty($res['matches'])) { return array(); } $this->_results = $res; $ids = array_keys($res['matches']); $sql = 'select id, keywords, date_added from ' . $this->_table_prefix . 'sph_stats where id in (' . implode(',', $ids) . ') order by FIELD(id, ' . implode(',', $ids) . ')'; $keywords = $this->_wpdb->get_results($sql, OBJECT_K); foreach ($res['matches'] as $index => $match) { $keywords[$index]->cnt = $match['attrs']['@count']; } return $keywords; }
/** * @access private * @return void */ function _set_sphinx_detected($searchd, $indexer) { $options['sphinx_searchd'] = $searchd; $options['sphinx_indexer'] = $indexer; $this->_config->update_admin_options($options); }
ini_set('memory_limit', '2048M'); set_time_limit(-1); date_default_timezone_set("Europe/Berlin"); include_once dirname(__FILE__) . "/../../../pimcore/config/startup.php"; Pimcore::initAutoloader(); Pimcore::initConfiguration(); Pimcore::initLogger(); Pimcore::initPlugins(); $opts = new Zend_Console_Getopt(array('language|l=s' => "language", 'document|d=s' => "document")); try { $opts->parse(); } catch (Exception $e) { Logger::critical($e->getMessage()); die("Error: " . $e->getMessage()); } $sphinx_config = SphinxSearch_Config::getInstance(); $documents = $sphinx_config->getDocumentsAsArray(); if (!array_key_exists($opts->document, $documents)) { SphinxSearch_Logger::err("Unknown document: " . $opts->document . "\n"); print "Unknown document: " . $opts->document . "\n"; print "Possible documents are:\n"; foreach ($documents as $document_name => $document_config) { print $document_name . "\n"; } die; } $document_config = $documents[$opts->document]; $controller = $document_config["controller"]; $action = $document_config["action"]; $template = $document_config["template"]; $db = Pimcore_Resource::get();
public static function queryDocument($query, $params = array()) { if (trim($query) == "") { return array(); } $sphinx_config = SphinxSearch_Config::getInstance(); $documents_config = $sphinx_config->getDocumentsAsArray(); $SphinxClient = new SphinxClient(); $entries = array(); $language = "all"; if (SphinxSearch_Config_Plugin::getValue("documents", "use_i18n") == "true") { if (array_key_exists("language", $params)) { $language = $params["language"]; } else { $locale = Zend_Registry::get("Zend_Locale"); $language = $locale->getLanguage(); } } $field_weights = array(); $indexes = array(); foreach ($documents_config as $document_name => $document_properties) { $indexes[] = "idx_document_" . $document_name . "_" . $language; foreach ($document_properties["elements"] as $field_name => $field_config) { if (array_key_exists("weight", $field_config) && intval($field_config["weight"]) > 0) { $field_weights[$field_name] = intval($field_config["weight"]); } } } if (sizeof($field_weights) > 0) { $SphinxClient->setFieldWeights($field_weights); } $search_result = $SphinxClient->Query($query, implode(", ", $indexes)); if ($search_result === false) { throw new Exception($SphinxClient->GetLastError()); } if ($search_result["total_found"] > 0) { foreach ($search_result["matches"] as $id => $meta) { $entries[] = array("result" => Document::getById($id), "id" => $id, "meta" => $meta, "type" => "document"); } } return $entries; }
public static function isSearchdRunning() { $config = SphinxSearch_Config::getInstance(); $pid_file = PIMCORE_DOCUMENT_ROOT . DIRECTORY_SEPARATOR . SphinxSearch_Config_Plugin::getValue("path", "pid"); if (!file_exists($pid_file)) { //die("PIDFILE ".$pid_file." nicht gefunden"); return false; } $pid = trim(file_get_contents($pid_file)); exec("ps {$pid}", $output, $result); return count($output) >= 2; }