Get the list of readers from Solr

master
Gilles Crettenand 11 years ago
parent 1894212a5c
commit 0143374ae1

@ -64,6 +64,22 @@ class BookSearch
$this->query->addSortField($field, $order);
}
public function addFacetField($field)
{
$this->query->addFacetField($field);
}
public function setFacetLimits($limit = null, $count = null)
{
if(! is_null($limit)) {
$this->query->setFacetLimit($limit);
}
if(! is_null($count)) {
$this->query->setFacetMinCount($count);
}
}
/**
* @param int $start
* @param int $count

@ -4,33 +4,6 @@ namespace BSR\Lib\db;
class DbHelper
{
/**
* Retrieve the list of all readers (volunteers) having read at least 4 books (2 notices per book).
* Returns an associative array containing $lastname and $firstname
*/
public static function ListOfReaders()
{
$sql = "SELECT
count(*),
ContentShortPart AS name
FROM NoticeFields
WHERE Tag=901
GROUP BY ContentShortPart
HAVING count(*) > 6
ORDER BY SUBSTRING(ContentShortPart, CHARINDEX(' ', ContentShortPart)+1, 15);";
$results = Connection::execute($sql);
return array_map(function($row) {
$fullname = str_replace("*", "", $row['name']);
$parts = explode(" ", $fullname);
$firstname = array_shift($parts);
$lastname = implode(" ", $parts);
return array(
'lastname' => $lastname,
'firstname' => $firstname);
}, $results->to_array());
}
/**
* Retrieve the list of all type available in the database.
* @param boolean $withJeunesse add 'Jeunesse' to the list

@ -662,7 +662,30 @@ class NetBiblio extends WebService
*/
public function ListOfReaders()
{
return DBHelper::ListOfReaders();
$s = new BookSearch();
$s->addQuery(1, 'visible');
$s->addFacetField('reader');
$s->setFacetLimits(2000, 10);
$results = $s->getResults(0, 0);
$readers = array();
foreach($results['facets']['facets']['reader'] as $name => $count) {
$parts = explode(" ", $name);
$firstname = array_shift($parts);
$lastname = implode(" ", $parts);
$fullname = trim($lastname.' '.$firstname);
$readers[$fullname] = array(
'lastname' => $lastname,
'firstname' => $firstname,
'count' => $count,
);
}
// sort readers by lastname
ksort($readers);
return array_values($readers);
}
/**

Loading…
Cancel
Save