addType() public method

Adds a type to the current search.
public addType ( Type | string $type )
$type Type | string Type name or object
 /**
  * @return \Elastica\ResultSet
  */
 public function getSearchResult()
 {
     $index = $this->search->getIndex($this->getIndexName() . '_' . $this->language);
     $search = new Search($this->search->getClient());
     $search->addIndex($index);
     $search->addType($index->getType($this->indexType));
     $result = $search->search($this->query);
     return $result;
 }
 /**
  * Get Query Count
  *
  * @param string $index        	
  * @param string $type        	
  *
  * @return number
  */
 public function getElasticaCount($index = false, $type = false)
 {
     $elastica_query = new Query();
     $elastica_client = $this->getElasticaClient();
     // If you want to restrict your search to a particular index then get
     // that
     $elastica_index = $index ? $elastica_client->getIndex($index) : false;
     // If you want to restrict your search to a particular type then get
     // that
     $elastica_type = $elastica_index && $type ? $elastica_index->getType($type) : false;
     $elastica_search = new Search($elastica_client);
     if ($elastica_index) {
         $elastica_search->addIndex($elastica_index);
     }
     if ($elastica_type) {
         $elastica_search->addType($elastica_type);
     }
     return $elastica_search->count($elastica_query);
 }
Exemplo n.º 3
0
 public function readData($source_definition, $rest_parameters = [])
 {
     Pager::setDefaultLimit(500);
     list($limit, $offset) = Pager::calculateLimitAndOffset();
     $client = new Client(['host' => $source_definition['host'], 'port' => $source_definition['port'], 'username' => $source_definition['username'], 'password' => $source_definition['password']]);
     $index = $client->getIndex($source_definition['es_index']);
     $type = $index->getType($source_definition['es_type']);
     $search = new Search($client);
     $search->addIndex($index);
     $search->addType($type);
     $query_param = \Input::get('query');
     if (empty($query_param)) {
         $query = new MatchAll();
         $search->setQuery($query);
     } else {
         $query = new SimpleQueryString($query_param);
         $search->setQuery($query);
     }
     $search->getQuery()->setFrom($offset);
     $search->getQuery()->setSize($limit);
     $resultSet = $search->search();
     $data = new Data();
     $data_results = [];
     foreach ($resultSet->getResults() as $result) {
         $data_result = $result->getData();
         unset($data_result['__tdt_etl_timestamp__']);
         $data_results[] = $data_result;
     }
     $data->data = $data_results;
     if ($resultSet->getTotalHits() > 0) {
         $paging = Pager::calculatePagingHeaders($limit, $offset, $resultSet->getTotalHits());
         $data->paging = $paging;
     }
     $data->preferred_formats = $this->getPreferredFormats();
     return $data;
 }
Exemplo n.º 4
0
 /**
  * @group functional
  */
 public function testCount()
 {
     $index = $this->_createIndex();
     $search = new Search($index->getClient());
     $type = $index->getType('test');
     $doc = new Document(1, array('id' => 1, 'username' => 'ruflin'));
     $type->addDocument($doc);
     $index->refresh();
     $search->addIndex($index);
     $search->addType($type);
     $result1 = $search->count(new \Elastica\Query\MatchAll());
     $this->assertEquals(1, $result1);
     $result2 = $search->count(new \Elastica\Query\MatchAll(), true);
     $this->assertInstanceOf('\\Elastica\\ResultSet', $result2);
     $this->assertEquals(1, $result2->getTotalHits());
 }
Exemplo n.º 5
0
 /**
  * Create search object
  *
  * @param  string|array|\Elastica\Query $query   Array with all query data inside or a Elastica\Query object
  * @param  int|array                   $options OPTIONAL Limit or associative array of options (option=>value)
  * @return \Elastica\Search
  */
 public function createSearch($query = '', $options = null)
 {
     $search = new Search($this->getIndex()->getClient());
     $search->addIndex($this->getIndex());
     $search->addType($this);
     $search->setOptionsAndQuery($options, $query);
     return $search;
 }
Exemplo n.º 6
0
 protected function buildQuery(array $classes)
 {
     $searchQuery = new Search($this->client);
     $searchQuery->setOption(Search::OPTION_VERSION, true);
     foreach ($classes as $class) {
         if ($class->index) {
             $indexObject = $this->getIndex($class->index);
             $searchQuery->addIndex($indexObject);
             if ($class->type) {
                 $searchQuery->addType($indexObject->getType($class->type));
             }
         }
     }
     return $searchQuery;
 }
 /**
  * Build a Search that will count all pages that link to $titles.
  * @param string $titles title in prefixedDBKey form
  * @return Search that counts all pages that link to $titles
  */
 private function buildCount($titles)
 {
     $filter = new Terms('outgoing_link', $titles);
     $filter->setCached(false);
     // We're not going to be redoing this any time soon.
     $type = $this->connection->getPageType(wfWikiId());
     $search = new Search($type->getIndex()->getClient());
     $search->addIndex($type->getIndex());
     $search->addType($type);
     $search->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_COUNT);
     $matchAll = new MatchAll();
     $search->setQuery(new Filtered($matchAll, $filter));
     $search->getQuery()->addParam('stats', 'link_count');
     return $search;
 }
Exemplo n.º 8
0
 /**
  * Invoke Elasticsearch count.
  *
  * @param Query  $query
  * @param string $index
  * @param string $type
  * @param array  $options
  *
  * @return \Elastica\ResultSet
  */
 public function count($query, $type, $index = 'activehire', $options = [])
 {
     $search = new Search($this->client);
     $search->addType($type);
     $search->addIndex($index);
     $search->setOptions($options);
     $result = $search->count($query);
     return $result;
 }
 /**
  * @return ScanAndScroll
  */
 protected function getScanAndScroll()
 {
     $search = new Search($this->client);
     $search->addIndex($this->elasticaIndex);
     // type не обязателен, бэкапить можно весь индекс со всеми типами
     if ($this->typeName) {
         $search->addType($this->elasticaType);
     }
     $scanAndScroll = new ScanAndScroll($search);
     $scanAndScroll->sizePerShard = $this->sizePerShard;
     $scanAndScroll->expiryTime = $this->expiryTime;
     return $scanAndScroll;
 }
Exemplo n.º 10
0
 public function testSearchRequest()
 {
     $client = $this->_getClient();
     $search1 = new Search($client);
     $index1 = $this->_createIndex('test1');
     $index2 = $this->_createIndex('test2');
     $type1 = $index1->getType('hello1');
     $result = $search1->search(array());
     $this->assertFalse($result->getResponse()->hasError());
     $search1->addIndex($index1);
     $result = $search1->search(array());
     $this->assertFalse($result->getResponse()->hasError());
     $search1->addIndex($index2);
     $result = $search1->search(array());
     $this->assertFalse($result->getResponse()->hasError());
     $search1->addType($type1);
     $result = $search1->search(array());
     $this->assertFalse($result->getResponse()->hasError());
 }