source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/6.3-placeholder-syntax.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// the placeholder syntax applies phrase escaping to the first term
16// see the manual for all supported formats
17$query->setQuery('features: %p1% AND inStock:%2%',array($input,1));
18
19// show the result after replacing the placeholders with values
20echo $query->getQuery() . '<br/>';
21
22// this executes the query and returns the result
23$resultset = $client->select($query);
24
25// display the total number of documents found by solr
26echo 'NumFound: '.$resultset->getNumFound();
27
28// show documents using the resultset iterator
29foreach ($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
45htmlFooter();
Note: See TracBrowser for help on using the repository browser.