函数名:SolrInputDocument::fieldExists()
适用版本:Solr 2.0.0及以上版本
函数描述:该函数用于检查SolrInputDocument对象中是否存在指定名称的字段。
用法:
bool SolrInputDocument::fieldExists( string $fieldName )
参数:
$fieldName
:要检查的字段名称,类型为字符串。
返回值:
- 如果指定的字段存在于SolrInputDocument对象中,则返回true;否则返回false。
示例:
// 创建SolrInputDocument对象
$doc = new SolrInputDocument();
// 添加字段到文档
$doc->addField('id', '12345');
$doc->addField('title', 'PHP Solr');
// 检查字段是否存在
if ($doc->fieldExists('id')) {
echo "字段 'id' 存在于文档中";
} else {
echo "字段 'id' 不存在于文档中";
}
在上述示例中,我们首先创建了一个SolrInputDocument对象,并向其添加了两个字段,分别是'id'和'title'。然后,我们使用fieldExists()函数检查'id'字段是否存在于文档中。如果存在,则输出"字段 'id' 存在于文档中",否则输出"字段 'id' 不存在于文档中"。