diff --git a/modules/solr_site/js/solr_site_bestbet.js b/modules/solr_site/js/solr_site_bestbet.js
old mode 100755
new mode 100644
index 121ad31..99f177f
--- a/modules/solr_site/js/solr_site_bestbet.js
+++ b/modules/solr_site/js/solr_site_bestbet.js
@@ -1,37 +1,34 @@
-Drupal.behaviors.roblib_search_solr_site_bestbet = {
- attach: function(context, settings) {
- url = settings.roblib_search_solr_site_bestbet.search_url;
- default_site_type = settings.roblib_search_solr_site_results.default_site_type
- jQuery.getJSON(url, function(data) {
- var items = [];
- var numberOfDocs = 0;
- try {
- numberOfDocs = data.response.docs.length;
- } catch (err) {
- // do nothing leave docLength at 0
- }
- if (numberOfDocs < 1) {
- jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append('No Results');
- jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-bestbet').hide();
- } else {
+Drupal.behaviors.roblib_search_solr_bestbet_results = {
+ attach: function (context, settings) {
+ if (context == document) {
+ query = drupalSettings.path.currentPath.replace('roblib_search/', '');
+ solrUrl = settings.solr_site_search_url + query;
+ baseUrl = settings.solr_bestbet_base_url + query;
+ jQuery.getJSON(baseUrl, function (data) {
+ var items = [];
+ total_found = data.resultCount;
- jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty();
- var counter = 0;
- var divs = new Array();
- var content = new Array();
- jQuery.each(data.response.docs, function(key, val) {
- id = 'roblib_search_solr_bestbets_' + counter;
- content[counter] = val.teaser;
- divs[counter++] = id;
- items.push('
');
-
- });
- jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append(items.join(''));
- }
- });
+ if (total_found < 1) {
+ jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append('No Results');
+ jQuery('.' + 'pane-roblib-search-solr-site-roblib-search-solr-site-' . solrType).hide();
+ } else {
+ jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty();
+ var counter = 0;
+ var divs = new Array();
+ var content = new Array();
+ jQuery.each(data.results, function (key, val) {
+ id = 'roblib_search_solr_results_bestbet-' + counter;
+ content[counter] = val.teaser;
+ divs[counter++] = id;
+ items.push('');
+ });
+ jQuery('#' + 'roblib-search-content-solr-site-bestbet').empty().append(items.join(''));
+ }
+ });
+ }
}
}
-
diff --git a/modules/solr_site/roblib_search_solr_site.libraries.yml b/modules/solr_site/roblib_search_solr_site.libraries.yml
index 67ce05f..40d117d 100644
--- a/modules/solr_site/roblib_search_solr_site.libraries.yml
+++ b/modules/solr_site/roblib_search_solr_site.libraries.yml
@@ -7,3 +7,9 @@ solr-site:
js/solr_site_results.js: {}
dependencies:
- core/drupal
+solr-bestbet:
+ version: 1.x
+ js:
+ js/solr_site_bestbet.js: {}
+ dependencies:
+ - core/drupal
diff --git a/modules/solr_site/roblib_search_solr_site.module b/modules/solr_site/roblib_search_solr_site.module
index 17495d6..469797f 100755
--- a/modules/solr_site/roblib_search_solr_site.module
+++ b/modules/solr_site/roblib_search_solr_site.module
@@ -16,7 +16,10 @@ function roblib_search_solr_site_theme($existing, $type, $theme, $path) {
$spinner_path = '/' . $modulePath . "/img/spinner.gif";
return [
'roblib_search_solr_site_results' => [
- 'variables' => ['solr_type' => NULL, 'spinner_path' => $spinner_path],
+ 'variables' => ['solr_type' => 'results', 'spinner_path' => $spinner_path],
+ ],
+ 'roblib_search_solr_site_bestbet' => [
+ 'variables' => ['solr_type' => 'bestbet', 'spinner_path' => $spinner_path],
],
];
}
diff --git a/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php b/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
index abb8ab7..c25eaa7 100644
--- a/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
+++ b/modules/solr_site/src/Controller/RoblibSearchSolrsiteController.php
@@ -36,7 +36,7 @@ class RoblibSearchSolrsiteController extends ControllerBase {
* @return string
* A JSON string
*/
- function getResults($queryString = NULL, $type = 'General') {
+ function getResults($queryString = NULL, $solr_type = 'General') {
global $base_url;
$config = \Drupal::config('roblib_search_solr_site.settings');
// Url parameters.
@@ -49,7 +49,7 @@ class RoblibSearchSolrsiteController extends ControllerBase {
}
}
$queryString = urlencode($queryString);
-
+ // TODO make the index configurable.
$index = \Drupal\search_api\Entity\Index::load('default_solr_index');
$query = $index->query();
@@ -60,10 +60,14 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$query->setParseMode($parse_mode);
// Restrict the search to specific languages.
- $query->setLanguages(['en']);
+ //$query->setLanguages(['en']);
-// Set fulltext search keywords and fields.
+
$query->keys($queryString);
+ if ($solr_type == 'BestBet') {
+ $query->addCondition('type', 'bestbet');
+ }
+
// $query->setFulltextFields(['rendered_item', 'title', 'body']);
$query->range(0, 5);
$query->sort('search_api_relevance', 'DESC');
@@ -78,24 +82,23 @@ class RoblibSearchSolrsiteController extends ControllerBase {
$titles = $result->getField('title')->getValues();
$output['results'][$id]['title'] = $titles[0]->getText();
$body = $result->getField('body')->getValues();
- $bodyOutput = strip_tags($body[0]->getText());
- if (strlen($bodyOutput) > 500) {
- $bodyOutput = substr($bodyOutput, 0, 500) . '...';
+ if (!empty($body)) {
+ $bodyOutput = strip_tags($body[0]->getText());
+ if (strlen($bodyOutput) > 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();
// $output['rendered_item'] = $rendered_items[0]->getText();
$summarys = $result->getField('summary')->getValues();
- $output['results'][$id]['summary'] = reset($summarys);
+ $output['results'][$id]['summary'] = empty($summmarys) ? '' : reset($summarys);
$type = $result->getField('type')->getValues();
$output['results'][$id]['type'] = reset($type);
$urls = $result->getField('url')->getValues();
$output['results'][$id]['url'] = reset($urls);
- //list(, $path, $langcode) = explode(':', $result->getId());
- //list($entity_type, $id) = explode('/', $path);
- //$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;
+ $links = $result->getField('field_link')->getValues();
+ $output['results'][$id]['field_link'] = empty($links) ? '' : $links;
}
echo json_encode($output);
diff --git a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
index 030932a..6721d58 100644
--- a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
+++ b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteBestbet.php
@@ -18,22 +18,26 @@ class RoblibSearchSolrSiteBestbet extends BlockBase {
/**
* {@inheritdoc}
*/
- public function build() {
- //$host = \Drupal::request()->getSchemeAndHttpHost();
- $search_url = \Drupal::config('roblib_search_solr_site.settings')
+ public function build() {
+ $search_url = \Drupal::config('roblib_search_solr.settings')
->get('solr_site_url');
$settings = [
'solr_site_search_url' => $search_url,
+ 'solr_bestbet_base_url' => '/roblib_search/solr_site/bestbet/',
];
return [
- '#theme' => 'roblib_search_solr_site',
- 'query' => $query,
+ '#theme' => 'roblib_search_solr_site_bestbet',
+ //'#solr_type' => 'bestbet',
'#attached' => [
'library' => [
- 'roblib_search_solr_site/solr_site'
+ 'roblib_search_solr_site/solr-bestbet'
],
'drupalSettings' => $settings,
],
];
- }
+ }
+
+ /*public function getCacheMaxAge() {
+ return 1;
+ }*/
}
diff --git a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
index 5fda179..7e1e9a8 100644
--- a/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
+++ b/modules/solr_site/src/Plugin/Block/RoblibSearchSolrsiteGeneral.php
@@ -19,17 +19,16 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
* {@inheritdoc}
*/
public function build() {
- $host = \Drupal::request()->getSchemeAndHttpHost();
$search_url = \Drupal::config('roblib_search_solr.settings')
->get('solr_site_url');
$settings = [
'solr_site_search_url' => $search_url,
- 'solr_site_base_url' => $host . '/roblib_search/solr_site/general/',
+ 'solr_site_base_url' => '/roblib_search/solr_site/general/',
+ 'solr_type' => 'results',
];
return [
'#theme' => 'roblib_search_solr_site_results',
- //'query' => $query,
- '#solr_type' => 'results',
+ //'#solr_type' => 'results',
'#attached' => [
'library' => [
'roblib_search_solr_site/solr-site'
@@ -38,5 +37,9 @@ class RoblibSearchSolrsiteGeneral extends BlockBase {
],
];
}
+
+ /*public function getCacheMaxAge() {
+ return 1;
+ }*/
}
diff --git a/modules/solr_site/templates/roblib-search-solr-site-bestbet.html.twig b/modules/solr_site/templates/roblib-search-solr-site-bestbet.html.twig
new file mode 100644
index 0000000..879fcb4
--- /dev/null
+++ b/modules/solr_site/templates/roblib-search-solr-site-bestbet.html.twig
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php b/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php
index 3b662e3..b3f69fb 100644
--- a/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php
+++ b/src/Plugin/Block/RoblibSearchOtherSourcesBlock.php
@@ -30,5 +30,10 @@ class RoblibSearchOtherSourcesBlock extends BlockBase {
'#query' => $query,
];
}
+
+ public function getCacheMaxAge() {
+ // don't cache this block
+ return 0;
+ }
}