Revision 7576,
1.1 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 | |
---|
7 | // this is the custom result document class |
---|
8 | class myDoc extends Solarium_Document_ReadOnly{ |
---|
9 | |
---|
10 | public function getSpecialPrice() |
---|
11 | { |
---|
12 | return round(($this->price * .95), 2); |
---|
13 | } |
---|
14 | |
---|
15 | } |
---|
16 | |
---|
17 | |
---|
18 | // create a client instance |
---|
19 | $client = new Solarium_Client($config); |
---|
20 | |
---|
21 | // get a select query instance |
---|
22 | $query = $client->createSelect(); |
---|
23 | |
---|
24 | // set the custom resultclass |
---|
25 | $query->setDocumentClass('myDoc'); |
---|
26 | |
---|
27 | // this executes the query and returns the result |
---|
28 | $resultset = $client->select($query); |
---|
29 | |
---|
30 | // display the total number of documents found by solr |
---|
31 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
32 | |
---|
33 | // show documents using the resultset iterator |
---|
34 | foreach ($resultset as $document) { |
---|
35 | |
---|
36 | echo '<hr/><table>'; |
---|
37 | echo '<tr><th>id</th><td>' . $document->id . '</td></tr>'; |
---|
38 | echo '<tr><th>name</th><td>' . $document->name . '</td></tr>'; |
---|
39 | echo '<tr><th>price</th><td>' . $document->price . '</td></tr>'; |
---|
40 | |
---|
41 | // this method is added by the custom class |
---|
42 | echo '<tr><th>offer price</th><td>' . $document->getSpecialPrice() . '</td></tr>'; |
---|
43 | |
---|
44 | echo '</table>'; |
---|
45 | } |
---|
46 | |
---|
47 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.