public function getItems() { if (!$this->items) { $this->items = array(); //Get Status of ElasticSearch Server $status = $this->elasticaClient->getStatus(); $this->status = $status->getServerStatus(); // Get all Indexes with types $indexes = $status->getIndexNames(); $index = $this->elasticaClient->getIndex(ElasticSearchConfig::getIndexName()); if ($index->exists()) { // First we get all types $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('elasticsearch'); $types = $dispatcher->trigger('onElasticSearchType', array()); // Prepare an array index by type name foreach ($types as $type) { $this->items[$type['type']] = array(); } $mapping = $index->getMapping(); // Add language by type. Example : array('article' => array('en','fr')) $lang = array(); // Array to count doc by type $counts = array(); //boost $boosts = array(); foreach ($mapping[ElasticSearchConfig::getIndexName()] as $key => $map) { $elasticType = $index->getType($key); $mapping = $elasticType->getMapping(); $pos = strrpos($key, '_'); if ($pos) { // Add the language $type_base = substr($key, 0, $pos); $type_lang = substr($key, $pos + 1); $lang[$type_base][] = $type_lang; // Count $sum = array_key_exists($type_base, $counts) ? $counts[$type_base] : 0; $counts[$type_base] = $sum + $elasticType->count(''); $boosts[$type_base] = $mapping[$key]["_boost"]["null_value"]; if (!array_key_exists($type_base, $mapping[ElasticSearchConfig::getIndexName()])) { $mapping[ElasticSearchConfig::getIndexName()][$type_base]; } } else { $boosts[$key] = $mapping[$key]["_boost"]["null_value"]; } } // Get all types of the index foreach ($this->items as $key => $map) { $elasticType = $index->getType($key); $count = $elasticType->count(''); $langs = array_key_exists($key, $lang) ? $lang[$key] : array(); $total = array_key_exists($key, $lang) ? $counts[$key] + $count : $count; $boost = array_key_exists($key, $boosts) ? $boosts[$key] : 1.0; $this->items[$key] = array('name' => $key, 'count' => $total, 'lang' => $langs, "boost" => $boost); } } } return $this->items; }
public function __construct($config = array()) { parent::__construct($config); // Create a elastica Client $this->elasticaClient = ElasticSearchConfig::getElasticSearchClient(); // Set Index $this->elasticaIndex = $this->elasticaClient->getIndex(ElasticSearchConfig::getIndexName()); }
function display($tpl = null) { $elasticaClient = ElasticSearchConfig::getElasticSearchClient(); $index = $elasticaClient->getIndex(ElasticSearchConfig::getIndexName()); $index->delete(); // Display the template parent::display($tpl); }
/** * ElasticSearch Default view display method * @return void */ function display($tpl = null) { // Load plug-in language files. JFactory::getLanguage()->load('com_finder'); if ($this->get('isConnected')) { $this->items = $this->get('Items'); $this->status = $this->get('Status'); } $this->pluginStatus = $this->get('pluginState'); $this->indexName = ElasticSearchConfig::getIndexName(); // Set the toolbar $this->addToolBar(); // Display the template parent::display($tpl); }
protected function typeExist($type) { $mapping = $this->elasticaIndex->getMapping(); foreach ($mapping[ElasticSearchConfig::getIndexName()] as $key => $map) { if ($key == $type) { return true; } } return false; }