@ -48,9 +48,9 @@ class RoblibSearchSolrsiteController extends ControllerBase {
return '';
}
}
// $queryString = urlencode($queryString);
$queryString = urlencode($queryString);
// TODO make the index configurable.
$index = \Drupal\search_api\Entity\Index::load('library ');
$index = \Drupal\search_api\Entity\Index::load('default_solr_index ');
$query = $index->query();
// Change the parse mode for the search.
@ -65,13 +65,7 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$query->keys($queryString);
if ($solr_type == 'BestBet') {
$query->addCondition('type', 'bestbet', '=');
$query->setFulltextFields(['title_1']);
if(str_starts_with($queryString, '"')) {
$query->keys($queryString);
} else {
$query->keys('"'.$queryString.'"');
}
$query->addCondition('type', 'bestbet');
} else {
$query->addCondition('type', 'bestbet', '< >');
}
@ -87,17 +81,13 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'] = [];
foreach ($results as $result) {
$id = $result->getId();
$title = $result->getField('title');
if(empty($title)){
break;
}
$titles = $title->getValues();
$output['results'][$id]['title'] = reset($titles);
$titles = $result->getField('title')->getValues();
$output['results'][$id]['title'] = $titles[0]->getText();
$body = $result->getField('body')->getValues();
if (!empty($body)) {
$bodyOutput = strip_tags($body[0]->getText());
if (strlen($bodyOutput) > 500) {
$bodyOutput = substr($bodyOutput, 0, 499 ) . '...';
$bodyOutput = substr($bodyOutput, 0, 500 ) . '...';
}
}
$output['results'][$id]['body'] = empty($bodyOutput) ? '' : $bodyOutput;
@ -109,10 +99,6 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'][$id]['type'] = reset($type);
$urls = $result->getField('url')->getValues();
$output['results'][$id]['url'] = reset($urls);
if ($solr_type == 'BestBet') {
$entity = $result->getOriginalObject()->getValue();
$output['results'][$id]['title'] = $entity->field_link->first()->title;
}
$links = $result->getField('field_link')->getValues();
$output['results'][$id]['field_link'] = empty($links) ? '' : $links;
}