1 | <?php |
---|
2 | |
---|
3 | require('init.php'); |
---|
4 | htmlHeader(); |
---|
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 | |
---|
23 | echo 'Document used for matching:<br/><table>'; |
---|
24 | foreach($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 | } |
---|
31 | echo '</table><hr/>'; |
---|
32 | |
---|
33 | // display the total number of MLT documents found by solr |
---|
34 | echo 'Number of MLT matches found: '.$resultset->getNumFound().'<br/><br/>'; |
---|
35 | echo '<b>Listing of matched docs:</b>'; |
---|
36 | |
---|
37 | // show MLT documents using the resultset iterator |
---|
38 | foreach ($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 | |
---|
54 | htmlFooter(); |
---|