Revision 7576,
1.1 KB
checked in by adir, 12 years ago
(diff) |
Ticket #000 - Adicionando a integracao de buscas com Solr na base a ser isnerida na comunidade
|
Line | |
---|
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 | // get grouping component and create two query groups |
---|
13 | $groupComponent = $query->getGrouping(); |
---|
14 | $groupComponent->addQuery('price:[0 TO 99.99]'); |
---|
15 | $groupComponent->addQuery('price:[100 TO *]'); |
---|
16 | // sorting inside groups |
---|
17 | $groupComponent->setSort('price desc'); |
---|
18 | // maximum number of items per group |
---|
19 | $groupComponent->setLimit(5); |
---|
20 | |
---|
21 | // this executes the query and returns the result |
---|
22 | $resultset = $client->select($query); |
---|
23 | |
---|
24 | $groups = $resultset->getGrouping(); |
---|
25 | foreach($groups AS $groupKey => $group) { |
---|
26 | |
---|
27 | echo '<h1>'.$groupKey.'</h1>'; |
---|
28 | |
---|
29 | foreach($group AS $document) { |
---|
30 | echo '<hr/><table>'; |
---|
31 | |
---|
32 | // the documents are also iterable, to get all fields |
---|
33 | foreach($document AS $field => $value) |
---|
34 | { |
---|
35 | // this converts multivalue fields to a comma-separated string |
---|
36 | if(is_array($value)) $value = implode(', ', $value); |
---|
37 | |
---|
38 | echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; |
---|
39 | } |
---|
40 | |
---|
41 | echo '</table>'; |
---|
42 | } |
---|
43 | } |
---|
44 | |
---|
45 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.