source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/6.2-escaping.php @ 7576

Revision 7576, 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
10$query = $client->createSelect();
11
12// search input string, this value fails without escaping because of the double-quote
13$input = 'ATA "133';
14
15// in this case phrase escaping is used (most common) but you can also do term escaping, see the manual
16// also note that the same can be done using the placeholder syntax, see example 6.3
17$helper = $query->getHelper();
18$query->setQuery('features:' . $helper->escapePhrase($input));
19
20// this executes the query and returns the result
21$resultset = $client->select($query);
22
23// display the total number of documents found by solr
24echo 'NumFound: '.$resultset->getNumFound();
25
26// show documents using the resultset iterator
27foreach ($resultset as $document) {
28
29    echo '<hr/><table>';
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        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
38    }
39
40    echo '</table>';
41}
42
43htmlFooter();
Note: See TracBrowser for help on using the repository browser.