Revision 7588,
1.3 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 | require('init.php'); |
---|
3 | |
---|
4 | htmlHeader(); |
---|
5 | |
---|
6 | // create a client instance and autoload the postbigrequest plugin |
---|
7 | $client = new Solarium_Client($config); |
---|
8 | $client->getPlugin('postbigrequest'); |
---|
9 | |
---|
10 | // create a basic query to execute |
---|
11 | $query = $client->createSelect(); |
---|
12 | |
---|
13 | // add a huge filterquery to create a very long query string |
---|
14 | // note: normally you would use a range for this, it's just an easy way to create a very big querystring as a test |
---|
15 | $fq = ''; |
---|
16 | for($i=1; $i<=1000; $i++) { |
---|
17 | $fq .= ' OR price:'.$i; |
---|
18 | } |
---|
19 | $fq = substr($fq, 4); |
---|
20 | $query->createFilterQuery('fq')->setQuery($fq); |
---|
21 | |
---|
22 | // without the plugin this query would fail as it is bigger than the default servlet container header buffer |
---|
23 | $resultset = $client->select($query); |
---|
24 | |
---|
25 | // display the total number of documents found by solr |
---|
26 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
27 | |
---|
28 | // show documents using the resultset iterator |
---|
29 | foreach ($resultset as $document) { |
---|
30 | |
---|
31 | echo '<hr/><table>'; |
---|
32 | |
---|
33 | // the documents are also iterable, to get all fields |
---|
34 | foreach($document AS $field => $value) |
---|
35 | { |
---|
36 | // this converts multivalue fields to a comma-separated string |
---|
37 | if(is_array($value)) $value = implode(', ', $value); |
---|
38 | |
---|
39 | echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; |
---|
40 | } |
---|
41 | |
---|
42 | echo '</table>'; |
---|
43 | } |
---|
44 | |
---|
45 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.