source: sandbox/expresso-solr/expressoMail1_2/inc/solrclient/examples/2.3.2-mlt-stream.php @ 7576

Revision 7576, 1.5 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 morelikethis query instance
10$query = $client->createMoreLikeThis();
11
12$query->setQuery('electronics memory');
13$query->setQueryStream(true);
14$query->setMltFields('manu,cat');
15$query->setMinimumDocumentFrequency(1);
16$query->setMinimumTermFrequency(1);
17$query->createFilterQuery('stock')->setQuery('inStock:true');
18$query->setInterestingTerms('details');
19$query->setMatchInclude(true);
20
21// this executes the query and returns the result
22$resultset = $client->select($query);
23
24echo 'Document used for matching:<br/><table>';
25foreach($resultset->getMatch() AS $field => $value)
26{
27    // this converts multivalue fields to a comma-separated string
28    if(is_array($value)) $value = implode(', ', $value);
29
30    echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
31}
32echo '</table><hr/>';
33
34// display the total number of MLT documents found by solr
35echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>';
36echo '<b>Listing of matched docs:</b>';
37
38// show MLT documents using the resultset iterator
39foreach ($resultset as $document) {
40
41    echo '<hr/><table>';
42
43    // the documents are also iterable, to get all fields
44    foreach($document AS $field => $value)
45    {
46        // this converts multivalue fields to a comma-separated string
47        if(is_array($value)) $value = implode(', ', $value);
48       
49        echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
50    }
51
52    echo '</table>';
53}
54
55htmlFooter();
Note: See TracBrowser for help on using the repository browser.