diff --git a/Lib/Formatter/Html.php b/Lib/Formatter/Html.php index 2dda42d..531a7c4 100644 --- a/Lib/Formatter/Html.php +++ b/Lib/Formatter/Html.php @@ -44,10 +44,11 @@ class Html extends Formatter { $title = $func; $content = ''; + $after = ''; if($func == 'NewSearch') { $content .= '
Count : '.$data['count'].'
'; - $content .= 'Facets : '.print_r($data['facets'], true).'
'; + $after .= 'Extra :
'.print_r($data['facets'], true).''; unset($data['count']); unset($data['facets']); @@ -85,7 +86,7 @@ class Html extends Formatter { $content .= ''; } } - $content .= ''; + $content .= ''.$after; return array( 'title' => $title, diff --git a/Lib/Search/BookSearch.php b/Lib/Search/BookSearch.php index 241b66f..082235b 100644 --- a/Lib/Search/BookSearch.php +++ b/Lib/Search/BookSearch.php @@ -28,10 +28,12 @@ class BookSearch $this->client = new \SolrClient($options); $this->query = new \SolrQuery(); - $this->query->setQuery('*:*'); - $this->query->addField('*'); + // most options like search fields, sorting, etc are already set + // as default in the Solr config and thus should be set only on a + // per request basis when needed + $this->query->addField('*'); $this->query->addParam('q.op', 'AND'); } @@ -92,9 +94,38 @@ class BookSearch } } + $highlighting = array(); + if(isset($results['highlighting'])) { + foreach($results['highlighting'] as $k => $h) { + $data = array(); + foreach($h as $f => $v) { + $data[str_replace('_fr', '', $f)] = reset($v); + } + $highlighting[$k] = $data; + } + } + + $spelling = array(); + if(isset($results['spellcheck']['suggestions'])) { + foreach($results['spellcheck']['suggestions'] as $s) { + $spelling[] = (array) $s; + } + } + + $facets = array(); + if(isset($results['facet_counts']['facet_fields'])) { + foreach($results['facet_counts']['facet_fields'] as $f => $d) { + $facets[$f] = (array) $d; + } + } + return array( 'count' => $results['response']['numFound'], - 'facets' => $results['facet_counts']['facet_fields'], + 'facets' => array( + 'facets' => $facets, + 'highlighting' => $highlighting, + 'spelling' => $spelling, + ), 'books' => $books, ); } @@ -125,8 +156,6 @@ class BookSearch $bs = new static(); $bs->addOrQuery($codes, $field); - $bs->addSortField('author', \SolrQuery::ORDER_ASC); - $bs->addSortField('title', \SolrQuery::ORDER_ASC); $results = $bs->getResults(0, $count); return $results['books']; } diff --git a/NetBiblio.php b/NetBiblio.php index 3d5bcae..46c5e54 100644 --- a/NetBiblio.php +++ b/NetBiblio.php @@ -533,7 +533,7 @@ class NetBiblio extends WebService * @param string $query Text to search * @param int $start * @param int $limit - * @return array + * @return array an array of books * @throws WebException */ public function Search($query, $start, $limit) @@ -574,6 +574,16 @@ class NetBiblio extends WebService * ° category : synonym for 'genre' (see above) * ° producer : synonym for 'producerCode' (see above) * + * Return value : + * + * The return value start with two keys : + * + * ° 'count' : which is the total number of available results + * ° 'facets' : which contains all other relevent information (facets, spellchecking, + * highlighting, etc). This name is used for compatibility reasons. + * + * Then, the books come right after. + * * @param string $values JSON encoded object * @return array * @throws WebException @@ -601,17 +611,6 @@ class NetBiblio extends WebService $bs = new BookSearch(); - if (isset($queryArray['queryType'])) { - $bs->addSortField('author', \SolrQuery::ORDER_ASC); - $bs->addSortField('title', \SolrQuery::ORDER_ASC); - $bs->addSortField('producerCode'); - $bs->addSortField('mediaType', \SolrQuery::ORDER_ASC); - } else { - $bs->addSortField('availabilityDate'); - $bs->addSortField('author', \SolrQuery::ORDER_ASC); - $bs->addSortField('title', \SolrQuery::ORDER_ASC); - } - if (isset($queryArray['queryText']) && strlen($queryArray['queryText']) > 0) { $type = isset($queryArray['queryType']) ? $queryArray['queryType'] : null; @@ -729,8 +728,13 @@ class NetBiblio extends WebService } else { $s->addQuery($genre, 'genre'); } + // this is not strictly speaking needed since we boost + // more recent books anyway, but let be on the safe side $s->addSortField('availabilityDate'); + // we only want visible books + $s->addQuery(1, 'visible'); + $results = $s->getResults(0, $number); $books = $this->AddBookData($results['books']);