Revision 7588,
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 | |
---|
3 | require('init.php'); |
---|
4 | htmlHeader(); |
---|
5 | |
---|
6 | // create a client instance |
---|
7 | $client = new Solarium_Client($config); |
---|
8 | |
---|
9 | // get a select query instance |
---|
10 | $query = $client->createSelect(); |
---|
11 | |
---|
12 | // get the facetset component |
---|
13 | $facetSet = $query->getFacetSet(); |
---|
14 | |
---|
15 | // create a facet field instance and set options |
---|
16 | $facetSet->createFacetField('stock')->setField('inStock'); |
---|
17 | |
---|
18 | // this executes the query and returns the result |
---|
19 | $resultset = $client->select($query); |
---|
20 | |
---|
21 | // display the total number of documents found by solr |
---|
22 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
23 | |
---|
24 | // display facet counts |
---|
25 | echo '<hr/>Facet counts for field "inStock":<br/>'; |
---|
26 | $facet = $resultset->getFacetSet()->getFacet('stock'); |
---|
27 | foreach($facet as $value => $count) { |
---|
28 | echo $value . ' [' . $count . ']<br/>'; |
---|
29 | } |
---|
30 | |
---|
31 | // show documents using the resultset iterator |
---|
32 | foreach ($resultset as $document) { |
---|
33 | |
---|
34 | echo '<hr/><table>'; |
---|
35 | echo '<tr><th>id</th><td>' . $document->id . '</td></tr>'; |
---|
36 | echo '<tr><th>name</th><td>' . $document->name . '</td></tr>'; |
---|
37 | echo '<tr><th>price</th><td>' . $document->price . '</td></tr>'; |
---|
38 | echo '</table>'; |
---|
39 | } |
---|
40 | |
---|
41 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.