php - 如何在日光浴室使用拼写检查
问题描述
我想在日光浴室使用拼写检查,但我无法使用它
<?php
require(__DIR__.'/init.php');
htmlHeader();
// create a client instance
$client = new Solarium\Client($config);
// get a select query instance
$query = $client->createSelect();
$query->setRows(0);
// add spellcheck settings
$spellcheck = $query->getSpellcheck();
$spellcheck->setQuery('tes');
$spellcheck->setCount(10);
$spellcheck->setBuild(true);
$spellcheck->setCollate(true);
$spellcheck->setExtendedResults(true);
$spellcheck->setCollateExtendedResults(true);
// this executes the query and returns the result
$resultset = $client->select($query);
$spellcheckResult = $resultset->getSpellcheck();
echo '<h1>Correctly spelled?</h1>';
if ($spellcheckResult->getCorrectlySpelled()) {
echo 'yes';
} else {
echo 'no';
}
echo '<h1>Suggestions</h1>';
foreach ($spellcheckResult as $suggestion) {
echo 'NumFound: '.$suggestion->getNumFound().'<br/>';
echo 'StartOffset: '.$suggestion->getStartOffset().'<br/>';
echo 'EndOffset: '.$suggestion->getEndOffset().'<br/>';
echo 'OriginalFrequency: '.$suggestion->getOriginalFrequency().'<br/>';
foreach ($suggestion->getWords() as $word) {
echo '-----<br/>';
echo 'Frequency: '.$word['freq'].'<br/>';
echo 'Word: '.$word['word'].'<br/>';
}
echo '<hr/>';
}
$collations = $spellcheckResult->getCollations();
echo '<h1>Collations</h1>';
foreach ($collations as $collation) {
echo 'Query: '.$collation->getQuery().'<br/>';
echo 'Hits: '.$collation->getHits().'<br/>';
echo 'Corrections:<br/>';
foreach ($collation->getCorrections() as $input => $correction) {
echo $input . ' => ' . $correction .'<br/>';
}
echo '<hr/>';
}
htmlFooter();
但它不起作用,我看到下面的错误
致命错误:未捕获的错误:在 null 上调用成员函数 getCorrectlySpelled()
我使用solr 4.4.0
和solarium 3.3.0
你的解决方案是什么?
解决方案
推荐阅读
- javascript - 我可以从 double v-for 获取对象中的数据吗
- python-3.x - 如何使用 python-telegram-bot 获取最新的 message_id?
- graphql - 如何过滤graphQL一对多关系中的查询?
- python - 如何识别段落中的一系列数字
- ios - 单个 WatchOS App 和 iOS App 之间的通信
- r - 查找带有日期的每年的最小值和最大值
- r - 如何使用 R 考试在 Rnw 文件中进行评论
- r - 使用 gganimate 动画块
- ansible - 如何在使用 Ansible 进行部署之前验证发布
- java - Room + RxJava 2 如何检查表中某列等于特定值的记录