protected function _execute(array $params) { $index = ElasticSearch::instance()->get_index('mg'); $index->create(array('number_of_shards' => 4, 'number_of_replicas' => 1, 'analysis' => array('analyzer' => array('indexAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('lowercase', 'mySnowball')), 'searchAnalyzer' => array('type' => 'custom', 'tokenizer' => 'standard', 'filter' => array('standard', 'lowercase', 'mySnowball'))), 'filter' => array('mySnowball' => array('type' => 'snowball', 'language' => 'English')))), true); Minion_CLI::write('Search index setup complete!'); }
public function action_index() { $this->view = new View_Search(); if ($this->request->query('query') !== NULL) { $query = $this->request->query('query'); $queryString = new \Elastica\Query\QueryString(); $queryString->setDefaultOperator('AND'); $queryString->setQuery($query); $elasticaQuery = new \Elastica\Query(); $elasticaQuery->setQuery($queryString); $resultSet = ElasticSearch::instance()->search($elasticaQuery); $results = $resultSet->getResults(); /** @var Kostache $renderer */ $renderer = Kostache::factory(); $out = array(); foreach ($results as $result) { // Attempt to create the avatar instance. try { $refl = new ReflectionClass('View_Search_' . ucfirst($result->getType())); $view = $refl->newInstance(); $view->data = $result->getData(); $out[] = $renderer->render($view); } catch (ReflectionException $ex) { Kohana::$log->add(LOG::ERROR, 'No search view class found for search type ":type".', array(':type' => $result->getType())); } } $this->view->query = $query; $this->view->results = $out; } }
/** * Deletes a single record while ignoring relationships. * * @chainable * @throws Kohana_Exception * @return ORM */ public function delete() { if ($this->_search_enabled) { // Delete the document from the search server. ElasticSearch::instance()->delete_document($this->_search_type(), $this->id); } return parent::delete(); }
/** * @return \Elastica\Type\Mapping */ public function send_search_mapping() { $type = ElasticSearch::instance()->get_type($this->_search_type()); $mapping = new \Elastica\Type\Mapping(); $mapping->setType($type); // Set mapping $mapping->setProperties(array('id' => array('type' => 'integer', 'include_in_all' => FALSE), 'content' => array('type' => 'string', 'include_in_all' => TRUE))); // Send mapping to type $mapping->send(); }
protected function _execute(array $params) { $model = $params['model']; $limit = $params['limit']; $times = $params['times']; $offset = $params['offset']; $elasticsearch = ElasticSearch::instance(); $orm = ORM::factory($model); $type = $orm->_search_type(); $total = $orm->count_all(); // Write the header Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##'); Minion_CLI::write('# Bulk updating search indexes in model: ' . Minion_CLI::color($model, 'blue') . ' #'); Minion_CLI::write('#########################################' . str_repeat('#', strlen($model)) . '##'); Minion_CLI::write(); Minion_CLI::write('Importing ' . $limit . ' items at a time, beginning at offset ' . $offset . ', ' . $times . ' times'); Minion_CLI::write(); while ($times !== 0) { $results = ORM::factory($model)->limit($limit)->offset($offset)->find_all(); // Break the loop if there are no more results in the database. if ($results->count() <= 0) { break; } $documents = array(); foreach ($results as $result) { $documents[] = $result->get_search_document(); } $elasticsearch->add_documents($type, $documents); $current = $offset + $results->count(); Minion_CLI::write('Imported: ' . $current . '/' . $total); $offset += $limit; $times -= 1; } // Write the footer Minion_CLI::write(); Minion_CLI::write('##########################'); Minion_CLI::write('# Bulk update completed! #'); Minion_CLI::write('##########################'); }