source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/2.1.2-custom-result-document.php @ 7576

Revision 7576, 1.1 KB checked in by adir, 11 years ago (diff)

Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade

Line 
1<?php
2
3require('init.php');
4htmlHeader();
5
6
7// this is the custom result document class
8class 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
31echo 'NumFound: '.$resultset->getNumFound();
32
33// show documents using the resultset iterator
34foreach ($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
47htmlFooter();
Note: See TracBrowser for help on using the repository browser.