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