source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/2.1.5.1.1-facet-field.php @ 7588

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
3require('init.php');
4htmlHeader();
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
22echo 'NumFound: '.$resultset->getNumFound();
23
24// display facet counts
25echo '<hr/>Facet counts for field "inStock":<br/>';
26$facet = $resultset->getFacetSet()->getFacet('stock');
27foreach($facet as $value => $count) {
28    echo $value . ' [' . $count . ']<br/>';
29}
30
31// show documents using the resultset iterator
32foreach ($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
41htmlFooter();
Note: See TracBrowser for help on using the repository browser.