Create search object.
public createSearch ( string | array | |
||
$query | string | array | |
Array with all query data inside or a Elastica\Query object |
$options | integer | array | OPTIONAL Limit or associative array of options (option=>value) |
$builder | Elastica\ResultSet\BuilderInterface | |
return |
/** * @inheritDoc */ public function findAllIds() { $generator = function (ScanAndScroll $scanAndScroll) { foreach ($scanAndScroll as $scrollId => $resultSet) { foreach ($resultSet as $result) { (yield $result->getId()); } } }; $query = new Query(new Query\MatchAll()); $query->setFields([]); $search = $this->type->createSearch($query); $scanAndScroll = new ScanAndScroll($search); return $generator($scanAndScroll); }
/** * @group functional */ public function testCreateSearchWithArray() { $client = $this->_getClient(); $index = new Index($client, 'test_index'); $type = new Type($index, 'test_type'); $query = array('query' => array('query_string' => array('query' => 'test'))); $options = array('limit' => 5, 'explain' => true); $search = $type->createSearch($query, $options); $expected = array('query' => array('query_string' => array('query' => 'test')), 'size' => 5, 'explain' => true); $this->assertEquals($expected, $search->getQuery()->toArray()); $this->assertEquals(array('test_index'), $search->getIndices()); $this->assertTrue($search->hasIndices()); $this->assertTrue($search->hasIndex($index)); $this->assertTrue($search->hasIndex('test_index')); $this->assertFalse($search->hasIndex('test')); $this->assertEquals(array('test_type'), $search->getTypes()); $this->assertTrue($search->hasTypes()); $this->assertTrue($search->hasType($type)); $this->assertTrue($search->hasType('test_type')); $this->assertFalse($search->hasType('test_type2')); }