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 select query instance |
---|
10 | $query = $client->createSelect(); |
---|
11 | $query->setRows(0); |
---|
12 | |
---|
13 | // add spellcheck settings |
---|
14 | $spellcheck = $query->getSpellcheck(); |
---|
15 | $spellcheck->setQuery('delll ultrashar'); |
---|
16 | $spellcheck->setBuild(true); |
---|
17 | $spellcheck->setCollate(true); |
---|
18 | $spellcheck->setExtendedResults(true); |
---|
19 | $spellcheck->setCollateExtendedResults(true); |
---|
20 | |
---|
21 | // this executes the query and returns the result |
---|
22 | $resultset = $client->select($query); |
---|
23 | $spellcheckResult = $resultset->getSpellcheck(); |
---|
24 | |
---|
25 | |
---|
26 | echo '<h1>Correctly spelled?</h1>'; |
---|
27 | if ($spellcheckResult->getCorrectlySpelled()) { |
---|
28 | echo 'yes'; |
---|
29 | }else{ |
---|
30 | echo 'no'; |
---|
31 | } |
---|
32 | |
---|
33 | echo '<h1>Suggestions</h1>'; |
---|
34 | foreach($spellcheckResult as $suggestion) { |
---|
35 | echo 'NumFound: '.$suggestion->getNumFound().'<br/>'; |
---|
36 | echo 'StartOffset: '.$suggestion->getStartOffset().'<br/>'; |
---|
37 | echo 'EndOffset: '.$suggestion->getEndOffset().'<br/>'; |
---|
38 | echo 'OriginalFrequency: '.$suggestion->getOriginalFrequency().'<br/>'; |
---|
39 | echo 'Frequency: '.$suggestion->getFrequency().'<br/>'; |
---|
40 | echo 'Word: '.$suggestion->getWord().'<br/>'; |
---|
41 | echo '<hr/>'; |
---|
42 | } |
---|
43 | |
---|
44 | $collation = $spellcheckResult->getCollation(); |
---|
45 | echo '<h1>Collation</h1>'; |
---|
46 | echo 'Query: '.$collation->getQuery().'<br/>'; |
---|
47 | echo 'Hits: '.$collation->getHits().'<br/>'; |
---|
48 | echo 'Corrections:<br/>'; |
---|
49 | foreach($collation->getCorrections() as $input => $correction) { |
---|
50 | echo $input . ' => ' . $correction .'<br/>'; |
---|
51 | } |
---|
52 | |
---|
53 | htmlFooter(); |
---|