/
TypeTest.php
executable file
·97 lines (75 loc) · 2.67 KB
/
TypeTest.php
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
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once dirname(__FILE__) . '/../../bootstrap.php';
class Elastica_TypeTest extends PHPUnit_Framework_TestCase
{
public function setUp() {
}
public function tearDown() {
}
public function testTest() {
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = new Elastica_Client();
$index = new Elastica_Index($client, 'xodoa');
$index->create(array(), true);
$type = new Elastica_Type($index, 'user');
// Adds 1 document to the index
$doc1 = new Elastica_Document(1,
array('username' => 'hans', 'test' => array('2', '3', '5'))
);
$type->addDocument($doc1);
// Adds a list of documents with _bulk upload to the index
$docs = array();
$docs[] = new Elastica_Document(2,
array('username' => 'john', 'test' => array('1', '3', '6'))
);
$docs[] = new Elastica_Document(3,
array('username' => 'rolf', 'test' => array('2', '3', '7'))
);
$type->addDocuments($docs);
$index->refresh();
$resultSet = $type->search('rolf');
$this->assertEquals(1, $resultSet->count());
// Test if source is returned
$result = $resultSet->current();
$this->assertEquals(3, $result->getId());
$data = $result->getData();
$this->assertEquals('rolf', $data['user']['username']);
}
public function testNoSource() {
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = new Elastica_Client();
$index = new Elastica_Index($client, 'xodoa');
$index->create(array(), true);
$type = new Elastica_Type($index, 'user');
$type->setMapping(
array(
'id' => array('type' => 'integer', 'store' => 'yes'),
'username' => array('type' => 'string', 'store' => 'no'),
), false
);
// Adds 1 document to the index
$doc1 = new Elastica_Document(1,
array('username' => 'hans', 'test' => array('2', '3', '5'))
);
$type->addDocument($doc1);
// Adds a list of documents with _bulk upload to the index
$docs = array();
$docs[] = new Elastica_Document(2,
array('username' => 'john', 'test' => array('1', '3', '6'))
);
$docs[] = new Elastica_Document(3,
array('username' => 'rolf', 'test' => array('2', '3', '7'))
);
$type->addDocuments($docs);
// To update index
$index->refresh();
$resultSet = $type->search('rolf');
$this->assertEquals(1, $resultSet->count());
// Tests if no source is in response except id
$result = $resultSet->current();
$this->assertEquals(3, $result->getId());
$this->assertEmpty($result->getData());
}
public function testSearchDefault() {
}
}