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 | // 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 |
---|
29 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
30 | |
---|
31 | // display facet counts |
---|
32 | echo '<hr/>Facet counts for field "inStock":<br/>'; |
---|
33 | $facet = $resultset->getFacetSet()->getFacet('stock'); |
---|
34 | foreach($facet as $value => $count) { |
---|
35 | echo $value . ' [' . $count . ']<br/>'; |
---|
36 | } |
---|
37 | |
---|
38 | // show documents using the resultset iterator |
---|
39 | foreach ($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 | |
---|
48 | htmlFooter(); |
---|