source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/4.1-api-usage.php @ 7576

Revision 7576, 1.4 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// apply settings using the API
13$query->setQuery('*:*');
14$query->setStart(2)->setRows(20);
15$query->setFields(array('id','name','price'));
16$query->addSort('price', Solarium_Query_Select::SORT_ASC);
17
18// create a filterquery using the API
19$fq = $query->createFilterQuery('maxprice')->setQuery('price:[1 TO 300]');
20
21// create a facet field instance and set options using the API
22$facetSet = $query->getFacetSet();
23$facet = $facetSet->createFacetField('stock')->setField('inStock');
24
25// this executes the query and returns the result
26$resultset = $client->select($query);
27
28// display the total number of documents found by solr
29echo 'NumFound: '.$resultset->getNumFound();
30
31// display facet counts
32echo '<hr/>Facet counts for field "inStock":<br/>';
33$facet = $resultset->getFacetSet()->getFacet('stock');
34foreach($facet as $value => $count) {
35    echo $value . ' [' . $count . ']<br/>';
36}
37
38// show documents using the resultset iterator
39foreach ($resultset as $document) {
40
41    echo '<hr/><table>';
42    echo '<tr><th>id</th><td>' . $document->id . '</td></tr>';
43    echo '<tr><th>name</th><td>' . $document->name . '</td></tr>';
44    echo '<tr><th>price</th><td>' . $document->price . '</td></tr>';
45    echo '</table>';
46}
47
48htmlFooter();
Note: See TracBrowser for help on using the repository browser.