|
|
|
|
@ -146,6 +146,43 @@ class BookSearch
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return a list of suggested titles for the given text
|
|
|
|
|
* @param string $text
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function suggest($text) {
|
|
|
|
|
$this->query->setQuery($text);
|
|
|
|
|
$this->query->setStart(0);
|
|
|
|
|
$this->query->setRows(0);
|
|
|
|
|
$this->query->setParam('suggest', 'true');
|
|
|
|
|
|
|
|
|
|
$results = $this->client->query($this->query)->getResponse();
|
|
|
|
|
|
|
|
|
|
$text = mb_strtolower ($text, 'UTF-8');
|
|
|
|
|
|
|
|
|
|
$suggestions = array();
|
|
|
|
|
if(isset($results['suggest'])) {
|
|
|
|
|
foreach($results['suggest'] as $suggester) {
|
|
|
|
|
foreach($suggester[$text]['suggestions'] as $s) {
|
|
|
|
|
$s->term = strip_tags($s->term);
|
|
|
|
|
|
|
|
|
|
$pos = strpos(mb_strtolower($s->term, 'UTF-8'), $text);
|
|
|
|
|
if($pos !== false) {
|
|
|
|
|
// increase weight of proposition that have the words at the beginning
|
|
|
|
|
$s->weight += (int) ((1 - $pos / strlen($s->term)) * 100);
|
|
|
|
|
}
|
|
|
|
|
$suggestions[$s->term] = (array) $s;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
usort($suggestions, function($a, $b) {
|
|
|
|
|
return $b['weight'] - $a['weight'];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $suggestions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieve books from Solr based on their code (NoticeNr).
|
|
|
|
|
|