
SolrDocument::hasChildDocuments 메서드는 SolrDocument 객체가 자식 문서를 가지고 있는지 여부를 확인하는 메서드입니다.
이 메서드는 다음 경우에 true를 반환합니다.
- SolrDocument 객체가 자식 문서를 가지고 있는 경우
- SolrDocument 객체가 자식 문서를 가리키는 링크 필드를 가지고 있는 경우
반면에, 이 메서드는 다음 경우에 false를 반환합니다.
- SolrDocument 객체가 자식 문서를 가지고 있지 않은 경우
- SolrDocument 객체가 자식 문서를 가리키는 링크 필드를 가지고 있지 않은 경우
이 메서드를 사용하는 예제 코드는 다음과 같습니다.
#hostingforum.kr
php
use SolariumQueryTypeSelectQueryQuery;
use SolariumCoreQueryDocumentDocument;
$query = new Query();
$query->setSearchQuery('키워드');
$result = $client->select($query);
$document = $result->getFirstDocument();
if ($document->hasChildDocuments()) {
echo "자식 문서가 있습니다.";
} else {
echo "자식 문서가 없습니다.";
}
이 예제 코드에서는 Solarium 클라이언트를 사용하여 검색 쿼리를 실행하고, 결과를 가져옵니다. 그런 다음, 첫 번째 문서를 가져와서 hasChildDocuments 메서드를 호출하여 자식 문서가 있는지 여부를 확인합니다.
2025-05-19 11:31