
SolrInputDocument::clear 메서드는 SolrInputDocument 객체의 모든 필드를 삭제하는 메서드입니다.
이 메서드는 객체의 필드를 초기화할 때 사용할 수 있습니다. 예를 들어, 객체를 재사용할 때 이전에 저장된 데이터를 삭제하고 싶을 때 사용할 수 있습니다.
clear 메서드는 모든 필드를 삭제하거나, 특정 필드를 삭제할 때 차이점이 있습니다.
모든 필드를 삭제하는 경우, 메서드는 다음과 같이 구현됩니다.
#hostingforum.kr
php
public function clear() {
$this->fields = [];
}
특정 필드를 삭제하는 경우, 메서드는 다음과 같이 구현됩니다.
#hostingforum.kr
php
public function clear($fieldNames) {
foreach ($fieldNames as $fieldName) {
unset($this->fields[$fieldName]);
}
}
해당 메서드의 사용 예시는 다음과 같습니다.
#hostingforum.kr
php
$solrDoc = new SolrInputDocument();
$solrDoc->addField('name', 'John');
$solrDoc->addField('age', 30);
// 모든 필드를 삭제
$solrDoc->clear();
// 특정 필드를 삭제
$solrDoc->addField('name', 'Jane');
$solrDoc->clear(['age']);
이러한 예시는 clear 메서드의 사용 방법을 보여주고 있습니다.
2025-07-25 11:12