|
|
@ -36,7 +36,7 @@ class RoblibSearchSolrsiteController extends ControllerBase { |
|
|
|
* @return string |
|
|
|
* @return string |
|
|
|
* A JSON string |
|
|
|
* A JSON string |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function getResults($queryString = NULL, $type = 'General') { |
|
|
|
function getResults($queryString = NULL, $solr_type = 'General') { |
|
|
|
global $base_url; |
|
|
|
global $base_url; |
|
|
|
$config = \Drupal::config('roblib_search_solr_site.settings'); |
|
|
|
$config = \Drupal::config('roblib_search_solr_site.settings'); |
|
|
|
// Url parameters. |
|
|
|
// Url parameters. |
|
|
@ -49,7 +49,7 @@ class RoblibSearchSolrsiteController extends ControllerBase { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
$queryString = urlencode($queryString); |
|
|
|
$queryString = urlencode($queryString); |
|
|
|
|
|
|
|
// TODO make the index configurable. |
|
|
|
$index = \Drupal\search_api\Entity\Index::load('default_solr_index'); |
|
|
|
$index = \Drupal\search_api\Entity\Index::load('default_solr_index'); |
|
|
|
$query = $index->query(); |
|
|
|
$query = $index->query(); |
|
|
|
|
|
|
|
|
|
|
@ -60,10 +60,14 @@ class RoblibSearchSolrsiteController extends ControllerBase { |
|
|
|
$query->setParseMode($parse_mode); |
|
|
|
$query->setParseMode($parse_mode); |
|
|
|
|
|
|
|
|
|
|
|
// Restrict the search to specific languages. |
|
|
|
// Restrict the search to specific languages. |
|
|
|
$query->setLanguages(['en']); |
|
|
|
//$query->setLanguages(['en']); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set fulltext search keywords and fields. |
|
|
|
|
|
|
|
$query->keys($queryString); |
|
|
|
$query->keys($queryString); |
|
|
|
|
|
|
|
if ($solr_type == 'BestBet') { |
|
|
|
|
|
|
|
$query->addCondition('type', 'bestbet'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// $query->setFulltextFields(['rendered_item', 'title', 'body']); |
|
|
|
// $query->setFulltextFields(['rendered_item', 'title', 'body']); |
|
|
|
$query->range(0, 5); |
|
|
|
$query->range(0, 5); |
|
|
|
$query->sort('search_api_relevance', 'DESC'); |
|
|
|
$query->sort('search_api_relevance', 'DESC'); |
|
|
@ -78,24 +82,23 @@ class RoblibSearchSolrsiteController extends ControllerBase { |
|
|
|
$titles = $result->getField('title')->getValues(); |
|
|
|
$titles = $result->getField('title')->getValues(); |
|
|
|
$output['results'][$id]['title'] = $titles[0]->getText(); |
|
|
|
$output['results'][$id]['title'] = $titles[0]->getText(); |
|
|
|
$body = $result->getField('body')->getValues(); |
|
|
|
$body = $result->getField('body')->getValues(); |
|
|
|
|
|
|
|
if (!empty($body)) { |
|
|
|
$bodyOutput = strip_tags($body[0]->getText()); |
|
|
|
$bodyOutput = strip_tags($body[0]->getText()); |
|
|
|
if (strlen($bodyOutput) > 500) { |
|
|
|
if (strlen($bodyOutput) > 500) { |
|
|
|
$bodyOutput = substr($bodyOutput, 0, 500) . '...'; |
|
|
|
$bodyOutput = substr($bodyOutput, 0, 500) . '...'; |
|
|
|
} |
|
|
|
} |
|
|
|
$output['results'][$id]['body'] = $bodyOutput; |
|
|
|
} |
|
|
|
|
|
|
|
$output['results'][$id]['body'] = empty($bodyOutput) ? '' : $bodyOutput; |
|
|
|
//$rendered_items = $result->getField('rendered_item')->getValues(); |
|
|
|
//$rendered_items = $result->getField('rendered_item')->getValues(); |
|
|
|
// $output['rendered_item'] = $rendered_items[0]->getText(); |
|
|
|
// $output['rendered_item'] = $rendered_items[0]->getText(); |
|
|
|
$summarys = $result->getField('summary')->getValues(); |
|
|
|
$summarys = $result->getField('summary')->getValues(); |
|
|
|
$output['results'][$id]['summary'] = reset($summarys); |
|
|
|
$output['results'][$id]['summary'] = empty($summmarys) ? '' : reset($summarys); |
|
|
|
$type = $result->getField('type')->getValues(); |
|
|
|
$type = $result->getField('type')->getValues(); |
|
|
|
$output['results'][$id]['type'] = reset($type); |
|
|
|
$output['results'][$id]['type'] = reset($type); |
|
|
|
$urls = $result->getField('url')->getValues(); |
|
|
|
$urls = $result->getField('url')->getValues(); |
|
|
|
$output['results'][$id]['url'] = reset($urls); |
|
|
|
$output['results'][$id]['url'] = reset($urls); |
|
|
|
//list(, $path, $langcode) = explode(':', $result->getId()); |
|
|
|
$links = $result->getField('field_link')->getValues(); |
|
|
|
//list($entity_type, $id) = explode('/', $path); |
|
|
|
$output['results'][$id]['field_link'] = empty($links) ? '' : $links; |
|
|
|
//$entity = \Drupal::service('entity_type.manager')->getStorage($entity_type)->load($id); |
|
|
|
|
|
|
|
//teaserOutput = \Drupal::service('entity_type.manager')->getViewBuilder($entity_type)->view($entity, 'teaser'); |
|
|
|
|
|
|
|
//$output['teaser'] = $teaserOutput; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
echo json_encode($output); |
|
|
|
echo json_encode($output); |
|
|
|