
SolrInputDocument::clear 메서드는 SolrInputDocument 객체의 필드와 값을 삭제합니다. 하지만, clear 메서드를 호출 후에 다시 필드를 추가하려고 할 때, 이전에 있던 필드의 값이 남아있는 것을 확인 할 수 있습니다.
이러한 현상을 해결하기 위해, clear 메서드를 사용할 때는 반드시 필드를 추가하는 메서드인 add 메서드를 호출해야 하는 것은 아닙니다.
대신, clear 메서드를 호출한 후에, 다시 add 메서드를 호출하여 새로운 필드를 추가할 수 있습니다.
또한, clear 메서드를 호출하기 전에, 필드의 값을 null로 설정하여 초기화할 수 있습니다.
예를 들어, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$solrDoc = new SolrInputDocument();
$solrDoc->addField('field1', 'value1');
$solrDoc->addField('field2', 'value2');
// 필드 삭제
$solrDoc->clear();
// 새로운 필드 추가
$solrDoc->addField('field3', 'value3');
또는, 다음과 같이 코드를 작성할 수 있습니다.
#hostingforum.kr
php
$solrDoc = new SolrInputDocument();
$solrDoc->addField('field1', 'value1');
$solrDoc->addField('field2', 'value2');
// 필드 초기화
$solrDoc->addField('field1', null);
$solrDoc->addField('field2', null);
// 새로운 필드 추가
$solrDoc->addField('field3', 'value3');
2025-03-20 09:10