Adapt code to new Solr config

This commit is contained in:
Gilles Crettenand
2015-06-09 14:38:18 +02:00
parent 320e2aead4
commit 1894212a5c
3 changed files with 53 additions and 19 deletions

View File

@@ -44,10 +44,11 @@ class Html extends Formatter {
$title = $func;
$content = '';
$after = '';
if($func == 'NewSearch') {
$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['facets']);
@@ -85,7 +86,7 @@ class Html extends Formatter {
$content .= '</tr>';
}
}
$content .= '</tbody></table>';
$content .= '</tbody></table>'.$after;
return array(
'title' => $title,

View File

@@ -28,10 +28,12 @@ class BookSearch
$this->client = new \SolrClient($options);
$this->query = new \SolrQuery();
$this->query->setQuery('*:*');
// 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'];
}