Adapt code to new Solr config

master
Gilles Crettenand 11 years ago
parent 320e2aead4
commit 1894212a5c

@ -44,10 +44,11 @@ class Html extends Formatter {
$title = $func; $title = $func;
$content = ''; $content = '';
$after = '';
if($func == 'NewSearch') { if($func == 'NewSearch') {
$content .= '<p>Count : '.$data['count'].'</p>'; $content .= '<p>Count : '.$data['count'].'</p>';
$content .= '<p>Facets : '.print_r($data['facets'], true).'</p>'; $after .= '<p>Extra : <pre>'.print_r($data['facets'], true).'</pre></p>';
unset($data['count']); unset($data['count']);
unset($data['facets']); unset($data['facets']);
@ -85,7 +86,7 @@ class Html extends Formatter {
$content .= '</tr>'; $content .= '</tr>';
} }
} }
$content .= '</tbody></table>'; $content .= '</tbody></table>'.$after;
return array( return array(
'title' => $title, 'title' => $title,

@ -28,10 +28,12 @@ class BookSearch
$this->client = new \SolrClient($options); $this->client = new \SolrClient($options);
$this->query = new \SolrQuery(); $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'); $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( return array(
'count' => $results['response']['numFound'], 'count' => $results['response']['numFound'],
'facets' => $results['facet_counts']['facet_fields'], 'facets' => array(
'facets' => $facets,
'highlighting' => $highlighting,
'spelling' => $spelling,
),
'books' => $books, 'books' => $books,
); );
} }
@ -125,8 +156,6 @@ class BookSearch
$bs = new static(); $bs = new static();
$bs->addOrQuery($codes, $field); $bs->addOrQuery($codes, $field);
$bs->addSortField('author', \SolrQuery::ORDER_ASC);
$bs->addSortField('title', \SolrQuery::ORDER_ASC);
$results = $bs->getResults(0, $count); $results = $bs->getResults(0, $count);
return $results['books']; return $results['books'];
} }

@ -533,7 +533,7 @@ class NetBiblio extends WebService
* @param string $query Text to search * @param string $query Text to search
* @param int $start * @param int $start
* @param int $limit * @param int $limit
* @return array * @return array an array of books
* @throws WebException * @throws WebException
*/ */
public function Search($query, $start, $limit) public function Search($query, $start, $limit)
@ -574,6 +574,16 @@ class NetBiblio extends WebService
* ° category : synonym for 'genre' (see above) * ° category : synonym for 'genre' (see above)
* ° producer : synonym for 'producerCode' (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 * @param string $values JSON encoded object
* @return array * @return array
* @throws WebException * @throws WebException
@ -601,17 +611,6 @@ class NetBiblio extends WebService
$bs = new BookSearch(); $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) { if (isset($queryArray['queryText']) && strlen($queryArray['queryText']) > 0) {
$type = isset($queryArray['queryType']) ? $queryArray['queryType'] : null; $type = isset($queryArray['queryType']) ? $queryArray['queryType'] : null;
@ -729,8 +728,13 @@ class NetBiblio extends WebService
} else { } else {
$s->addQuery($genre, 'genre'); $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'); $s->addSortField('availabilityDate');
// we only want visible books
$s->addQuery(1, 'visible');
$results = $s->getResults(0, $number); $results = $s->getResults(0, $number);
$books = $this->AddBookData($results['books']); $books = $this->AddBookData($results['books']);

Loading…
Cancel
Save