本文整理汇总了PHP中Elastica\Search::addType方法的典型用法代码示例。如果您正苦于以下问题:PHP Search::addType方法的具体用法?PHP Search::addType怎么用?PHP Search::addType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Elastica\Search
的用法示例。
在下文中一共展示了Search::addType方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSearchResult
/**
* @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;
}
示例2: getElasticaCount
/**
* 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);
}
示例3: readData
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;
}
示例4: testCount
/**
* @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());
}
示例5: createSearch
/**
* 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;
}
示例6: buildQuery
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;
}
示例7: buildCount
/**
* 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;
}
示例8: count
/**
* 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;
}
示例9: getScanAndScroll
/**
* @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;
}
示例10: testSearchRequest
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());
}