MoreLikeThis API

master
Gilles Crettenand 11 years ago
parent 5ebe300c28
commit 240ed85dbc

@ -15,7 +15,7 @@ class BookSearch
private $query;
private $queryParts = array();
public function __construct()
public function __construct($edismax = true)
{
$options = array
(
@ -27,10 +27,13 @@ class BookSearch
);
$this->client = new \SolrClient($options);
$this->query = new \SolrDisMaxQuery();
// use the Extended DisMax Query parser
if($edismax) {
$this->query = new \SolrDisMaxQuery();
$this->query->useEDisMaxQueryParser();
} else {
$this->query = new \SolrQuery();
}
// most options like search fields, sorting, etc are already set
// as default in the Solr config and thus should be set only on a
@ -45,6 +48,11 @@ class BookSearch
*/
}
public function setHandler($handler)
{
$this->client->setServlet(\SolrClient::SEARCH_SERVLET_TYPE, $handler);
}
public function addCompoundQuery(array $texts, $field, $operator)
{
if(count($texts) > 0) {

@ -711,6 +711,39 @@ class NetBiblio extends WebService
return array_merge($data, $this->AddBookData($results['books']));
}
/**
* This method return books similar to the one given.
*
* @param int|array $ids One or multiple book ids
* @return array
*/
public function MoreLikeThis($ids)
{
$bs = new BookSearch(false);
$bs->addOrQuery(is_array($ids) ? $ids : array($ids), 'id');
$bs->setHandler('more');
$results = $bs->getResults(0, 5);
return $results['books'];
}
/**
* This method returns books similar to the books already
* loaned by the current user.
*
* @return array
* @throws AuthenticationException
*/
public function MoreLikeLoans()
{
$_SESSION["user"]["login"] = 35;
$loans = $this->getUser()->GetOldLoans();
$ids = array_map(function($l) {
return $l['id'];
}, $loans);
return $this->MoreLikeThis($ids);
}
/**
* This method return a list of suggested titles for the given search terms
* @param string $text

Loading…
Cancel
Save