Revision 7588,
1.2 KB
checked in by adir, 12 years ago
(diff) |
Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade
|
Line | |
---|
1 | <?php |
---|
2 | |
---|
3 | require('init.php'); |
---|
4 | htmlHeader(); |
---|
5 | |
---|
6 | if ($_POST) { |
---|
7 | // if data is posted add it to solr |
---|
8 | |
---|
9 | // create a client instance |
---|
10 | $client = new Solarium_Client($config); |
---|
11 | |
---|
12 | // get an update query instance |
---|
13 | $update = $client->createUpdate(); |
---|
14 | |
---|
15 | // create a new document for the data |
---|
16 | // please note that any type of validation is missing in this example to keep it simple! |
---|
17 | $doc = $update->createDocument(); |
---|
18 | $doc->id = $_POST['id']; |
---|
19 | $doc->name = $_POST['name']; |
---|
20 | $doc->price = $_POST['price']; |
---|
21 | |
---|
22 | // add the document and a commit command to the update query |
---|
23 | $update->addDocument($doc); |
---|
24 | $update->addCommit(); |
---|
25 | |
---|
26 | // this executes the query and returns the result |
---|
27 | $result = $client->update($update); |
---|
28 | |
---|
29 | echo '<b>Update query executed</b><br/>'; |
---|
30 | echo 'Query status: ' . $result->getStatus(). '<br/>'; |
---|
31 | echo 'Query time: ' . $result->getQueryTime(); |
---|
32 | |
---|
33 | } else { |
---|
34 | // if no data is posted show a form |
---|
35 | ?> |
---|
36 | |
---|
37 | <form method="POST"> |
---|
38 | Id: <input type="text" name="id"/> <br/> |
---|
39 | Name: <input type="text" name="name"/> <br/> |
---|
40 | Price: <input type="text" name="price"/> <br/> |
---|
41 | <input type="submit" value="Add"/> |
---|
42 | </form> |
---|
43 | |
---|
44 | <?php |
---|
45 | } |
---|
46 | |
---|
47 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.