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 the dismax component and set a boost query |
---|
13 | $dismax = $query->getDisMax(); |
---|
14 | |
---|
15 | // override the default setting of 'dismax' to enable 'edismax' |
---|
16 | $dismax->setQueryParser('edismax'); |
---|
17 | |
---|
18 | // this query is now a dismax query |
---|
19 | $query->setQuery('memory -printer'); |
---|
20 | |
---|
21 | // this executes the query and returns the result |
---|
22 | $resultset = $client->select($query); |
---|
23 | |
---|
24 | // display the total number of documents found by solr |
---|
25 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
26 | |
---|
27 | // show documents using the resultset iterator |
---|
28 | foreach ($resultset as $document) { |
---|
29 | |
---|
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 | htmlFooter(); |
---|
Note: See
TracBrowser
for help on using the repository browser.