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
|
<?php
namespace Elastica\Test;
use Elastica\Document;
use Elastica\Test\Base as BaseTest;
/**
* Tests the example code.
*/
class ExampleTest extends BaseTest
{
/**
* @group functional
*/
public function testBasicGettingStarted()
{
$client = $this->_getClient();
$index = $client->getIndex('ruflin');
$type = $index->getType('users');
$id = 2;
$data = array('firstname' => 'Nicolas', 'lastname' => 'Ruflin');
$doc = new Document($id, $data);
$type->addDocument($doc);
}
/**
* @group functional
*/
public function testExample()
{
// Creates a new index 'xodoa' and a type 'user' inside this index
$client = $this->_getClient();
$index = $client->getIndex('elastica_test');
$index->create(array(), true);
$type = $index->getType('user');
// Adds 1 document to the index
$doc1 = new 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 Document(2,
array('username' => 'john', 'test' => array('1', '3', '6'))
);
$docs[] = new Document(3,
array('username' => 'rolf', 'test' => array('2', '3', '7'))
);
$type->addDocuments($docs);
// Refresh index
$index->refresh();
$resultSet = $type->search('rolf');
}
}
|