|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Implementation of Roblib search for searching several targets.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_theme().
|
|
|
|
*/
|
|
|
|
function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
|
|
|
|
$modulePath = \Drupal::service('module_handler')->getModule('roblib_search')
|
|
|
|
->getPath();
|
|
|
|
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
|
|
|
|
return [
|
|
|
|
'roblib_search_solr_site_results' => [
|
|
|
|
'variables' => ['solr_type' => 'results', 'spinner_path' => $spinner_path],
|
|
|
|
],
|
|
|
|
'roblib_search_solr_site_bestbet' => [
|
|
|
|
'variables' => ['solr_type' => 'bestbet', 'spinner_path' => $spinner_path],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the query to solr but limit the results so it doesn't include certain content.
|
|
|
|
*
|
|
|
|
* Print json and exit so the javascript can consume the json.
|
|
|
|
*
|
|
|
|
* @param string $query
|
|
|
|
* The solr search string.
|
|
|
|
*/
|
|
|
|
/*function roblib_search_solr_site_results($query) {
|
|
|
|
print roblib_search_solr_site_get_results($query, '-bundle:bestbet');
|
|
|
|
exit();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send the query to solr but limit the results so it only includes content of type bestbet.
|
|
|
|
*
|
|
|
|
* Print json and exit so the javascript can consume the json.
|
|
|
|
*
|
|
|
|
* @param string $query
|
|
|
|
* The solr search string.
|
|
|
|
*/
|
|
|
|
/*function roblib_search_solr_site_bestbet($query) {
|
|
|
|
$query = str_replace('"', '', $query);
|
|
|
|
$json = roblib_search_solr_site_get_results("sort_label:$query", 'bundle:bestbet');
|
|
|
|
$json = roblib_search_solr_site_add_url($json);
|
|
|
|
print $json;
|
|
|
|
exit();
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Updates the json passed in with a url directly to the target of the link field.
|
|
|
|
* This information is not in solr as it comes from a custom field.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $json
|
|
|
|
* The json string returned from the solr query.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* json we got from solr with an updated url directly to the target of the link field
|
|
|
|
*/
|
|
|
|
/*function roblib_search_solr_site_add_url($json) {
|
|
|
|
$responses = json_decode($json);
|
|
|
|
foreach ($responses->response->docs as &$doc) {
|
|
|
|
$nid = $doc->entity_id;
|
|
|
|
// The link field is a complex field and we get the text in solr but not the actual url.
|
|
|
|
// Since best best will only every return one result it's not much overhead to load the node
|
|
|
|
// and get the value of the link field. probably less overhead then installing additional
|
|
|
|
// modules to get the url in solr.
|
|
|
|
$node = node_load($nid);
|
|
|
|
$url = $node->field_link['und'][0]['url'];
|
|
|
|
$doc->url = $url;
|
|
|
|
}
|
|
|
|
return json_encode($responses);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements hook_help().
|
|
|
|
*/
|
|
|
|
function roblib_search_solr_site_help($path, $arg) {
|
|
|
|
switch ($path) {
|
|
|
|
case 'admin/help#roblib_search_solr_site':
|
|
|
|
return t(
|
|
|
|
'<p>
|
|
|
|
provides a Solr target for the Roblib search module
|
|
|
|
</p>'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|