Skip to content

Commit

Permalink
Add collapsable hit highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Nov 23, 2015
1 parent 72774cb commit d67c3ab
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
//
// Required by Blacklight
//= require blacklight/blacklight
//= require spotlight
//= require_tree .
21 changes: 21 additions & 0 deletions app/assets/javascripts/full_text_collapse.js
Original file line number Diff line number Diff line change
@@ -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 });
});
35 changes: 35 additions & 0 deletions app/assets/stylesheets/blacklight.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
5 changes: 3 additions & 2 deletions app/assets/stylesheets/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ $navbar-default-link-active-bg: #ebebeb;

$link-color: $black;


@import 'bootstrap/variables';
@import 'spotlight/variables_bootstrap';
@import 'spotlight/variables_bootstrap';

$highlight-bg: saturate($state-warning-bg, 30%);
9 changes: 8 additions & 1 deletion app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d67c3ab

Please sign in to comment.