forked from solariumphp/solarium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.3-basic-update.php
47 lines (35 loc) · 1.2 KB
/
1.3-basic-update.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
<?php
require(__DIR__.'/init.php');
htmlHeader();
if ($_POST) {
// if data is posted add it to solr
// create a client instance
$client = new Solarium\Client($config);
// get an update query instance
$update = $client->createUpdate();
// create a new document for the data
// please note that any type of validation is missing in this example to keep it simple!
$doc = $update->createDocument();
$doc->id = $_POST['id'];
$doc->name = $_POST['name'];
$doc->price = $_POST['price'];
// add the document and a commit command to the update query
$update->addDocument($doc);
$update->addCommit();
// this executes the query and returns the result
$result = $client->update($update);
echo '<b>Update query executed</b><br/>';
echo 'Query status: ' . $result->getStatus(). '<br/>';
echo 'Query time: ' . $result->getQueryTime();
} else {
// if no data is posted show a form
?>
<form method="POST">
Id: <input type="text" name="id"/> <br/>
Name: <input type="text" name="name"/> <br/>
Price: <input type="text" name="price"/> <br/>
<input type="submit" value="Add"/>
</form>
<?php
}
htmlFooter();