1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<?php
namespace Elastica\Test\Filter;
use Elastica\Document;
use Elastica\Filter\BoolAnd;
use Elastica\Filter\Ids;
use Elastica\Test\Base as BaseTest;
class BoolAndTest extends BaseTest
{
/**
* @group unit
*/
public function testToArray()
{
$and = new BoolAnd();
$this->assertEquals(array('and' => array()), $and->toArray());
$idsFilter = new Ids();
$idsFilter->setIds(12);
$and->addFilter($idsFilter);
$and->addFilter($idsFilter);
$expectedArray = array(
'and' => array(
$idsFilter->toArray(),
$idsFilter->toArray(),
),
);
$this->assertEquals($expectedArray, $and->toArray());
}
/**
* @group functional
*/
public function testSetCache()
{
$client = $this->_getClient();
$index = $client->getIndex('test');
$index->create(array(), true);
$type = $index->getType('test');
$type->addDocuments(array(
new Document(1, array('name' => 'hello world')),
new Document(2, array('name' => 'nicolas ruflin')),
new Document(3, array('name' => 'ruflin')),
));
$and = new BoolAnd();
$idsFilter1 = new Ids();
$idsFilter1->setIds(1);
$idsFilter2 = new Ids();
$idsFilter2->setIds(1);
$and->addFilter($idsFilter1);
$and->addFilter($idsFilter2);
$index->refresh();
$and->setCached(true);
$resultSet = $type->search($and);
$this->assertEquals(1, $resultSet->count());
}
/**
* @group unit
*/
public function testConstruct()
{
$ids1 = new Ids('foo', array(1, 2));
$ids2 = new Ids('bar', array(3, 4));
$and1 = new BoolAnd(array($ids1, $ids2));
$and2 = new BoolAnd();
$and2->addFilter($ids1);
$and2->addFilter($ids2);
$this->assertEquals($and1->toArray(), $and2->toArray());
}
}
|