source: sandbox/expresso-solr/expressoMail1_2/solrclient/examples/2.1.6-helper-functions.php @ 7588

Revision 7588, 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 and a query helper instance
10$query = $client->createSelect();
11$helper = $query->getHelper();
12
13// add a filterquery on a price range, using the helper to generate the range
14$query->createFilterQuery('price')->setQuery($helper->rangeQuery('price', 10, 300));
15
16// add a filterquery to find products in a range of 5km, using the helper to generate the 'geofilt' filter
17$query->createFilterQuery('region')->setQuery($helper->geofilt(45.15, -93.85, 'store', 5));
18
19// this executes the query and returns the result
20$resultset = $client->select($query);
21
22// display the total number of documents found by solr
23echo 'NumFound: '.$resultset->getNumFound();
24
25// show documents using the resultset iterator
26foreach ($resultset as $document) {
27
28    echo '<hr/><table>';
29
30    // the documents are also iterable, to get all fields
31    foreach($document AS $field => $value)
32    {
33        // this converts multivalue fields to a comma-separated string
34        if(is_array($value)) $value = implode(', ', $value);
35
36        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
37    }
38
39    echo '</table>';
40}
41
42htmlFooter();
Note: See TracBrowser for help on using the repository browser.