/** * @internal **/ public static function _query($args, $pageIndex, $size, $sortByDate = false) { $query = new \Elastica\Query($args); $query->setFrom($pageIndex * $size); $query->setSize($size); $query->setFields(array('id')); Config::apply_filters('searcher_query', $query); try { $index = Indexer::_index(false); $search = new \Elastica\Search($index->getClient()); $search->addIndex($index); if (!$query->hasParam('sort')) { if ($sortByDate) { $query->addSort(array('post_date' => 'desc')); } else { $query->addSort('_score'); } } Config::apply_filters('searcher_search', $search, $query); $results = $search->search($query); return self::_parseResults($results); } catch (\Exception $ex) { error_log($ex); return null; } }
protected function setUp() { parent::setUp(); update_option('server_url', 'http://127.0.0.1:9200/'); update_option('server_index', 'travisci'); $this->index = Indexer::_index(true); $this->index->create(array(), true); // make sure index is available before continuing Indexer::_client(true)->request('_cluster/health/travisci?wait_for_status=yellow', \Elastica\Request::GET); $this->assertEquals(0, $this->index->count()); }
public function testIndexDefined() { update_option('server_index', 'index_name'); $index = Indexer::_index(false); $this->assertEquals('index_name', $index->getName()); }