Browse Source

updates to solr results for drupal10

2.x
ppound 2 years ago
parent
commit
f702f1bed2
  1. 10
      modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
  2. 1
      modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

10
modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php

@ -50,7 +50,7 @@ class RoblibSearchSolrsiteController extends ControllerBase {
} }
$queryString = urlencode($queryString); $queryString = urlencode($queryString);
// TODO make the index configurable. // TODO make the index configurable.
$index = \Drupal\search_api\Entity\Index::load('default_solr_index'); $index = \Drupal\search_api\Entity\Index::load('library');
$query = $index->query(); $query = $index->query();
// Change the parse mode for the search. // Change the parse mode for the search.
@ -81,8 +81,12 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$output['results'] = []; $output['results'] = [];
foreach ($results as $result) { foreach ($results as $result) {
$id = $result->getId(); $id = $result->getId();
$titles = $result->getField('title')->getValues(); $title = $result->getField('title');
$output['results'][$id]['title'] = $titles[0]->getText(); if(empty($title)){
break;
}
$titles = $title->getValues();
$output['results'][$id]['title'] = reset($titles);
$body = $result->getField('body')->getValues(); $body = $result->getField('body')->getValues();
if (!empty($body)) { if (!empty($body)) {
$bodyOutput = strip_tags($body[0]->getText()); $bodyOutput = strip_tags($body[0]->getText());

1
modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php

@ -25,6 +25,7 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
'solr_site_search_url' => $search_url, 'solr_site_search_url' => $search_url,
'solr_site_base_url' => '/roblib_search/solr_site/general/', 'solr_site_base_url' => '/roblib_search/solr_site/general/',
'solr_type' => 'results', 'solr_type' => 'results',
'solr_site_search_url' => $search_url,
]; ];
return [ return [
'#theme' => 'roblib_search_solr_site_results', '#theme' => 'roblib_search_solr_site_results',

Loading…
Cancel
Save