source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/2.1.1-query-params.php @ 7576

Revision 7576, 1.2 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// set a query (all prices starting from 12)
13$query->setQuery('price:[12 TO *]');
14
15// set start and rows param (comparable to SQL limit) using fluent interface
16$query->setStart(2)->setRows(20);
17
18// set fields to fetch (this overrides the default setting 'all fields')
19$query->setFields(array('id','name','price'));
20
21// sort the results by price ascending
22$query->addSort('price', Solarium_Query_Select::SORT_ASC);
23
24// this executes the query and returns the result
25$resultset = $client->select($query);
26
27// display the total number of documents found by solr
28echo 'NumFound: '.$resultset->getNumFound();
29
30// show documents using the resultset iterator
31foreach ($resultset as $document) {
32
33    echo '<hr/><table>';
34
35    // the documents are also iterable, to get all fields
36    foreach($document AS $field => $value)
37    {
38        // this converts multivalue fields to a comma-separated string
39        if(is_array($value)) $value = implode(', ', $value);
40       
41        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
42    }
43
44    echo '</table>';
45}
46
47htmlFooter();
Note: See TracBrowser for help on using the repository browser.