1 | <!----> |
---|
2 | <!--<html><head><title>Basic select</title></head><body>--> |
---|
3 | <?php |
---|
4 | require('init.php'); |
---|
5 | //require('../library/Solarium/Autoloader.php'); |
---|
6 | //Solarium_Autoloader::register(); |
---|
7 | |
---|
8 | // create a client instance |
---|
9 | $client = new Solarium_Client($config); |
---|
10 | |
---|
11 | // get a select query instance |
---|
12 | $query = $client->createSelect(); |
---|
13 | |
---|
14 | $query->setQuery("gato"); |
---|
15 | |
---|
16 | // override the default row limit of 10 by setting rows to 30 |
---|
17 | $query->setRows(30); |
---|
18 | |
---|
19 | // this executes the query with default settings and returns the result |
---|
20 | $resultset = $client->select($query); |
---|
21 | |
---|
22 | // display the total number of documents found by solr |
---|
23 | echo 'NumFound: '.$resultset->getNumFound(); |
---|
24 | |
---|
25 | // show documents using the resultset iterator |
---|
26 | foreach ($resultset as $document) { |
---|
27 | |
---|
28 | echo "-----------------------------------------"; |
---|
29 | echo '</br>'; |
---|
30 | |
---|
31 | // the documents are also iterable, to get all fields |
---|
32 | foreach($document AS $field => $value) |
---|
33 | { |
---|
34 | // this converts multivalue fields to a comma-separated string |
---|
35 | if(is_array($value)) $value = implode(', ', $value); |
---|
36 | |
---|
37 | if($field == "id" ) |
---|
38 | { |
---|
39 | echo "UID: ".substr($value, 1, strlen($value)-2)."</br>"; |
---|
40 | } |
---|
41 | |
---|
42 | if($field == "user" ) |
---|
43 | { |
---|
44 | echo "Usuário: ".$value."</br>"; |
---|
45 | } |
---|
46 | |
---|
47 | if($field == "subject" ) |
---|
48 | { |
---|
49 | echo "Assunto: ".$value."</br>"; |
---|
50 | } |
---|
51 | |
---|
52 | // echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>'; |
---|
53 | } |
---|
54 | |
---|
55 | } |
---|
56 | ?> |
---|
57 | <!--</body></html>--> |
---|
58 | |
---|