From c872c7b9bc3b805080df7ea3a81959b87ba8bd83 Mon Sep 17 00:00:00 2001 From: Gilles Crettenand Date: Wed, 17 Jun 2015 13:09:09 +0200 Subject: [PATCH] ListOfDurations --- Lib/Search/BookSearch.php | 48 +++++++++++++++++++++++++++++++++++++++ NetBiblio.php | 12 +++++++++- 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/Lib/Search/BookSearch.php b/Lib/Search/BookSearch.php index 44addec..f19049a 100644 --- a/Lib/Search/BookSearch.php +++ b/Lib/Search/BookSearch.php @@ -82,6 +82,11 @@ class BookSearch $this->query->addFacetField($field); } + public function setFacetRangeField($field) + { + $this->query->setParam('facet.range', $field); + } + public function setFacetLimits($limit = null, $count = null) { if(! is_null($limit)) { @@ -93,6 +98,13 @@ class BookSearch } } + public function setFacetRange($start, $end, $gap) + { + $this->query->setParam('facet.range.start', $start); + $this->query->setParam('facet.range.end', $end); + $this->query->setParam('facet.range.gap', $gap); + } + /** * @param int $start * @param int $count @@ -147,6 +159,19 @@ class BookSearch $facets[$f] = $d; } } + if(isset($results['facet_counts']['facet_ranges'])) { + $integer = strpos($this->query->getParam('facet.range.gap'), '.') === false; + foreach($results['facet_counts']['facet_ranges'] as $f => $d) { + if($integer) { + $facets[$f] = array(); + foreach($d['counts'] as $k => $v) { + $facets[$f][intval($k)] = $v; + } + } else { + $facets[$f] = $d['counts']; + } + } + } return array( 'count' => $results['response']['numFound'], @@ -233,4 +258,27 @@ class BookSearch $results = $bs->getResults(0, $count); return $results['books']; } + + public static function GetTerms($field) { + $s = new BookSearch(); + $s->addQuery(1, 'visible'); + $s->addFacetField($field); + $s->setFacetLimits(2000, 10); + $results = $s->getResults(0, 0); + + return $results['facets']['facets'][$field]; + } + + + public static function GetTermsRange($field) { + $s = new BookSearch(); + $s->addQuery(1, 'visible'); + $s->setFacetRangeField($field); + $s->setFacetRange(0, 250, 1); + // to avoid useless calculation, only set this 'normal' facet + $s->addFacetField('visible'); + $results = $s->getResults(0, 0); + + return $results['facets']['facets'][$field]; + } } diff --git a/NetBiblio.php b/NetBiblio.php index 8e8dc93..f86f63b 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -13,7 +13,7 @@ use BSR\Lib\WebService; class NetBiblio extends WebService { /** @var string $version version number */ - public static $version = '1.0.4'; + public static $version = '1.0.5'; private $login = ''; private $client = 'website'; @@ -721,6 +721,16 @@ class NetBiblio extends WebService return $bs->suggest($text); } + /** + * This method returns the list of all volunteer readers that read book + * in the database. + * @return array + */ + public function ListOfDurations() + { + return BookSearch::GetTermsRange('duration'); + } + /** * This method returns the list of all volunteer readers that read book * in the database.