라이브러리
[PHP] SolrQuery::getFacetDateOther - facet.date.other 매개변수에 대한 값을 반환합니다.
SolrQuery::getFacetDateOther
SolrQuery::getFacetDateOther는 Solr 쿼리에서 날짜_facet 옵션을 사용하여 facet 결과에 다른 날짜 범위가 있는지 여부를 확인하는 메서드입니다. 이 메서드는 facet 결과에서 날짜 범위가 여러 개 있는 경우에 유용합니다.
예제
아래 예제는 PHP로 작성된 Solr 쿼리 코드입니다. 이 코드는 Solr 인덱스에 날짜 필드가 있는 문서를 검색하고 facet 결과에서 다른 날짜 범위가 있는지 확인합니다.
#hostingforum.kr
php
require_once 'vendor/autoload.php';
use SolariumClient;
use SolariumCoreQueryQueryInterface;
$client = new Client([
'url' => 'http://localhost:8983/solr',
'username' => 'solr',
'password' => 'solr'
]);
$query = $client->createSelect();
$query->setQuery('title:php');
$query->addFacetDate('created_at', 'year', '2010-01-01', '2020-12-31');
$result = $client->execute($query);
$facetDate = $result->getFacetResult()->getDate('created_at');
$other = $facetDate->getOther();
if ($other) {
echo "다른 날짜 범위가 있습니다.
";
foreach ($other as $date) {
echo "다른 날짜 범위: " . $date->getValue() . "
";
}
} else {
echo "다른 날짜 범위가 없습니다.
";
}
설명
이 예제는 다음을 수행합니다.
1. Solr 클라이언트를 생성합니다.
2. 쿼리 객체를 생성하고 `title:php`라는 쿼리를 설정합니다.
3. `created_at` 필드에 대한 facet 날짜 옵션을 추가합니다. facet 날짜 옵션은 `year` 타입으로 설정되어 있으며, `2010-01-01`부터 `2020-12-31`까지의 날짜 범위를 설정합니다.
4. 쿼리를 실행하고 facet 결과를 가져옵니다.
5. facet 결과에서 `created_at` 필드에 대한 facet 날짜 결과를 가져옵니다.
6. facet 날짜 결과에서 `other` 메서드를 호출하여 다른 날짜 범위가 있는지 확인합니다.
7. 다른 날짜 범위가 있으면 `other` 메서드의 결과를 출력합니다.
결과
이 예제의 결과는 다음과 같습니다.
#hostingforum.kr
다른 날짜 범위가 있습니다.
다른 날짜 범위: 2015-01-01
다른 날짜 범위: 2018-01-01
이 예제는 Solr 쿼리에서 facet 결과에서 다른 날짜 범위가 있는지 확인하는 방법을 보여줍니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.