source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/4.2-configuration-usage.php @ 7588

Revision 7588, 1.8 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
7// In this case an array is used for configuration to keep the example simple.
8// For an easier to use config file you are probably better of with another format, like Zend_Config_Ini
9// See the documentation for more info about this.
10$select = array(
11    'query'         => '*:*',
12    'start'         => 2,
13    'rows'          => 20,
14    'fields'        => array('id','name','price'),
15    'sort'          => array('price' => 'asc'),
16    'filterquery' => array(
17        'maxprice' => array(
18            'query' => 'price:[1 TO 300]'
19        ),
20    ),
21    'component' => array(
22        'facetset' => array(
23            'facet' => array(
24                // notice this config uses an inline key value, instead of array key like the filterquery
25                array('type' => 'field', 'key' => 'stock', 'field' => 'inStock'),
26            )
27        ),
28    ),
29);
30
31// create a client instance
32$client = new Solarium_Client($config);
33
34// get a select query instance based on the config
35$query = $client->createSelect($select);
36
37// this executes the query and returns the result
38$resultset = $client->select($query);
39
40// display the total number of documents found by solr
41echo 'NumFound: '.$resultset->getNumFound();
42
43// display facet counts
44echo '<hr/>Facet counts for field "inStock":<br/>';
45$facet = $resultset->getFacetSet()->getFacet('stock');
46foreach($facet as $value => $count) {
47    echo $value . ' [' . $count . ']<br/>';
48}
49
50// show documents using the resultset iterator
51foreach ($resultset as $document) {
52
53    echo '<hr/><table>';
54    echo '<tr><th>id</th><td>' . $document->id . '</td></tr>';
55    echo '<tr><th>name</th><td>' . $document->name . '</td></tr>';
56    echo '<tr><th>price</th><td>' . $document->price . '</td></tr>';
57    echo '</table>';
58}
59
60htmlFooter();
Note: See TracBrowser for help on using the repository browser.