[7576] | 1 | <?php |
---|
| 2 | |
---|
| 3 | require('init.php'); |
---|
| 4 | htmlHeader(); |
---|
| 5 | |
---|
| 6 | // create a client instance |
---|
| 7 | $client = new Solarium_Client($config); |
---|
| 8 | |
---|
| 9 | // get an analysis document query |
---|
| 10 | $query = $client->createAnalysisDocument(); |
---|
| 11 | |
---|
| 12 | $query->setShowMatch(true); |
---|
| 13 | $query->setQuery('ipod'); |
---|
| 14 | |
---|
| 15 | $doc = new Solarium_Document_ReadWrite( |
---|
| 16 | array( |
---|
| 17 | 'id' => 'MA147LL', |
---|
| 18 | 'name' => 'Apple 60 GB iPod with Video Playback Black', |
---|
| 19 | 'manu' => 'Apple Computer Inc.', |
---|
| 20 | 'cat' => 'electronics', |
---|
| 21 | 'cat' => 'music', |
---|
| 22 | 'features' => 'iTunes, Podcasts, Audiobooks', |
---|
| 23 | 'features' => 'Stores up to 15,000 songs, 25,000 photos, or 150 hours of video', |
---|
| 24 | 'features' => '2.5-inch, 320x240 color TFT LCD display with LED backlight', |
---|
| 25 | 'features' => 'Up to 20 hours of battery life', |
---|
| 26 | 'features' => 'Plays AAC, MP3, WAV, AIFF, Audible, Apple Lossless, H.264 video', |
---|
| 27 | 'features' => 'Notes, Calendar, Phone book, Hold button, Date display, Photo wallet, Built-in games, JPEG photo playback, Upgradeable firmware, USB 2.0 compatibility, Playback speed control, Rechargeable capability, Battery level indication', |
---|
| 28 | 'includes' => 'earbud headphones, USB cable', |
---|
| 29 | 'weight' => 5.5, |
---|
| 30 | 'price' => 399.00, |
---|
| 31 | 'popularity' => 10, |
---|
| 32 | 'inStock' => true, |
---|
| 33 | ) |
---|
| 34 | ); |
---|
| 35 | |
---|
| 36 | $query->addDocument($doc); |
---|
| 37 | |
---|
| 38 | // this executes the query and returns the result |
---|
| 39 | $result = $client->analyze($query); |
---|
| 40 | |
---|
| 41 | // show the results |
---|
| 42 | foreach ($result as $document) { |
---|
| 43 | |
---|
| 44 | echo '<hr><h2>Document: ' . $document->getName() . '</h2>'; |
---|
| 45 | |
---|
| 46 | foreach ($document as $field) { |
---|
| 47 | |
---|
| 48 | echo '<h3>Field: ' . $field->getName() . '</h3>'; |
---|
| 49 | |
---|
| 50 | $indexAnalysis = $field->getIndexAnalysis(); |
---|
| 51 | if (!empty($indexAnalysis)) { |
---|
| 52 | echo '<h4>Index Analysis</h4>'; |
---|
| 53 | foreach ($indexAnalysis as $classes) { |
---|
| 54 | |
---|
| 55 | echo '<h5>'.$classes->getName().'</h5>'; |
---|
| 56 | |
---|
| 57 | foreach($classes as $result) { |
---|
| 58 | echo 'Text: ' . $result->getText() . '<br/>'; |
---|
| 59 | echo 'Raw text: ' . $result->getRawText() . '<br/>'; |
---|
| 60 | echo 'Start: ' . $result->getStart() . '<br/>'; |
---|
| 61 | echo 'End: ' . $result->getEnd() . '<br/>'; |
---|
| 62 | echo 'Position: ' . $result->getPosition() . '<br/>'; |
---|
| 63 | echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>'; |
---|
| 64 | echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>'; |
---|
| 65 | echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>'; |
---|
| 66 | echo '-----------<br/>'; |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | $queryAnalysis = $field->getQueryAnalysis(); |
---|
| 72 | if (!empty($queryAnalysis)) { |
---|
| 73 | echo '<h4>Query Analysis</h4>'; |
---|
| 74 | foreach ($queryAnalysis as $classes) { |
---|
| 75 | |
---|
| 76 | echo '<h5>'.$classes->getName().'</h5>'; |
---|
| 77 | |
---|
| 78 | foreach($classes as $result) { |
---|
| 79 | echo 'Text: ' . $result->getText() . '<br/>'; |
---|
| 80 | echo 'Raw text: ' . $result->getRawText() . '<br/>'; |
---|
| 81 | echo 'Start: ' . $result->getStart() . '<br/>'; |
---|
| 82 | echo 'End: ' . $result->getEnd() . '<br/>'; |
---|
| 83 | echo 'Position: ' . $result->getPosition() . '<br/>'; |
---|
| 84 | echo 'Position history: ' . implode(', ',$result->getPositionHistory()) . '<br/>'; |
---|
| 85 | echo 'Type: ' . htmlspecialchars($result->getType()) . '<br/>'; |
---|
| 86 | echo 'Match: ' . var_export($result->getMatch(),true) . '<br/>'; |
---|
| 87 | echo '-----------<br/>'; |
---|
| 88 | } |
---|
| 89 | } |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | htmlFooter(); |
---|