source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/2.1.5.1.2-facet-query.php @ 7588

Revision 7588, 1.0 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 query instance and set options
16$facetSet->createFacetQuery('stock')->setQuery('inStock: true');
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 query count
25$count = $resultset->getFacetSet()->getFacet('stock')->getValue();
26echo '<hr/>Facet query count : ' . $count;
27
28// show documents using the resultset iterator
29foreach ($resultset as $document) {
30
31    echo '<hr/><table>';
32    echo '<tr><th>id</th><td>' . $document->id . '</td></tr>';
33    echo '<tr><th>name</th><td>' . $document->name . '</td></tr>';
34    echo '<tr><th>price</th><td>' . $document->price . '</td></tr>';
35    echo '</table>';
36}
37
38htmlFooter();
Note: See TracBrowser for help on using the repository browser.