From d67c3aba6bb35ab8b7184589d99b114b0d9d96b8 Mon Sep 17 00:00:00 2001 From: Chris Beer Date: Fri, 13 Nov 2015 16:11:40 -0800 Subject: [PATCH] Add collapsable hit highlighting --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/full_text_collapse.js | 21 ++++++++++++ app/assets/stylesheets/blacklight.scss | 35 ++++++++++++++++++++ app/assets/stylesheets/variables.scss | 5 +-- app/controllers/catalog_controller.rb | 9 ++++- 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/full_text_collapse.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 491b73721..4b6691ca5 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -19,4 +19,5 @@ // // Required by Blacklight //= require blacklight/blacklight +//= require spotlight //= require_tree . diff --git a/app/assets/javascripts/full_text_collapse.js b/app/assets/javascripts/full_text_collapse.js new file mode 100644 index 000000000..3097142e5 --- /dev/null +++ b/app/assets/javascripts/full_text_collapse.js @@ -0,0 +1,21 @@ +Spotlight.onLoad(function(){ + var uniqueId = (function() { + var uuid = 0; + + return function(el) { + el.id = 'ui-id-' + ( ++uuid ); + }; + } )(); + + $('dd.blacklight-full_text_tesimv').addClass('collapse').each(function() { + $(this).attr('id', uniqueId(this)); + }); + + $('dt.blacklight-full_text_tesimv').each(function() { + $(this).text($(this).text().replace(/:$/, '')); + $(this).attr('data-toggle', 'collapse'); + $(this).attr('data-target', '#' + $(this).next('dd').attr('id')); + }); + + $('dd.blacklight-full_text_tesimv').collapse({ toggle: false }); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/blacklight.scss b/app/assets/stylesheets/blacklight.scss index 8eb8d0982..5ce13a3bc 100644 --- a/app/assets/stylesheets/blacklight.scss +++ b/app/assets/stylesheets/blacklight.scss @@ -66,3 +66,38 @@ } } } + +dt.blacklight-full_text_tesimv { + @extend .h4; + display: inline-block; + float: none; + text-align: initial; + width: auto; + + // collapse carets shamelessly stolen from blacklight facets + &[data-toggle="collapse"]:after { + color: $gray90; + // symbol for "opening" panels + content: "\e114"; + float: right; + font-family: "Glyphicons Halflings"; + font-size: 0.8em; + line-height: normal; + padding-left: 2ch; + } + + &.collapsed:after { + // symbol for "collapsed" panels + content: "\e080"; + } +} + +dd.blacklight-full_text_tesimv { + float: none; + margin-left: 0; + + em { + background-color: $highlight-bg; + font-weight: bold; + } +} diff --git a/app/assets/stylesheets/variables.scss b/app/assets/stylesheets/variables.scss index d10d63cdc..498901efa 100644 --- a/app/assets/stylesheets/variables.scss +++ b/app/assets/stylesheets/variables.scss @@ -30,6 +30,7 @@ $navbar-default-link-active-bg: #ebebeb; $link-color: $black; - @import 'bootstrap/variables'; -@import 'spotlight/variables_bootstrap'; \ No newline at end of file +@import 'spotlight/variables_bootstrap'; + +$highlight-bg: saturate($state-warning-bg, 30%); diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 50b5c3664..6ff827b9d 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -13,7 +13,13 @@ class CatalogController < ApplicationController ## Default parameters to send to solr for all search-like requests. See also SolrHelper#solr_search_params config.default_solr_params = { qt: 'search', - fl: '*' + fl: '*', + hl: true, + 'hl.fl' => 'full_text_tesimv', + 'hl.snippets' => 5, + 'hl.fragsize' => 240, + 'hl.mergeContiguous' => true, + 'hl.useFastVectorHighlighter' => true } config.default_autocomplete_solr_params = { @@ -136,6 +142,7 @@ class CatalogController < ApplicationController config.add_index_field 'folder_name_ssi', label: 'Folder Name' config.add_index_field 'location_ssi', label: 'Location' config.add_index_field 'donor_tags_ssim', label: 'Donor tags' + config.add_index_field 'full_text_tesimv', label: 'Preview matches in document text', highlight: true # "fielded" search configuration. Used by pulldown among other places. # For supported keys in hash, see rdoc for Blacklight::SearchFields