【发布时间】:2011-04-11 13:53:44
【问题描述】:
我正在使用 Zend_Search_Lucene 来索引我的网站。我的网站索引并不完全相似。有的有,很少的领域,有的有很多领域。我正在尝试通过不同类型的表创建类似的索引,这就是我遇到这种错误的原因。
现在,当我显示结果时。我调用了一些字段,这些字段并不存在于生成错误的所有结果中。我试图用isset 来检查它,但它似乎完全跳过了这一行。
foreach ($hits as $hit) {
$content .= '<div class="searchResult">';
$content .= '<h2>';
$title = array();
if(isset($hit -> name)) $title[] = $hit -> name;
if(isset($hit -> title)) $title[] = $hit -> title;
// This is the part where i get fatal error.
$content .= implode(" » ",$title);
$content .= '</h2>';
$content .= '<p>'.$this->content.'</p>';
$content .= '</div>';
}
如何检查$hit中是否存在$hit -> name等内容
【问题讨论】:
-
是跳过该行还是出现 PHP 错误?你似乎优柔寡断。
-
当然错误
Fatal error: Uncaught exception 'Zend_Search_Lucene_Exception' with message 'Field name "name" not found in document -
我刚刚解决了这个问题,但请记住,如果您没有给出确切的错误消息,我将永远无法做到。今后,请在提问时发布所有相关消息。不要让人们猜测,这会让你更难获得帮助。
标签: php object zend-search-lucene