Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions blacklight-cornell/app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,7 @@ def authorize_email_use!
#
# :show may be set to false if you don't want the facet to be drawn in the
# facet bar
#if RAILS_ENV = 'development'
#config.add_facet_field 'availability_facet', :label => 'Availability Status', :limit => 30, :collapse => false
#end

config.add_facet_field 'online', :label => 'Access', :limit => 2, :collapse => false
config.add_facet_field 'format',
label: 'Format',
Expand All @@ -237,8 +235,6 @@ def authorize_email_use!
if: :has_search_parameters?,
advanced_search_component: AdvancedRangeLimitComponent,
advanced_search_order: 0

config.add_facet_field 'workid_facet', :label => 'Work', :show => false
config.add_facet_field 'language_facet',
label: 'Language',
limit: 5,
Expand All @@ -251,9 +247,7 @@ def authorize_email_use!
config.add_facet_field 'fast_era_facet', :label => 'Subject: Era', :limit => 5, if: :has_search_parameters?
config.add_facet_field 'fast_genre_facet', :label => 'Genre', :limit => 5, if: :has_search_parameters?
config.add_facet_field 'subject_content_facet', :label => 'Fiction/Non-Fiction', :limit => 5, if: :has_search_parameters?
config.add_facet_field 'lc_alpha_facet', :label => 'Call Number', :limit => 5, :show => false
config.add_facet_field 'hierarchy_facet', :hierarchy => true
config.add_facet_field 'authortitle_facet', :show => false, :label => "Author-Title"
# Display only top 10 call number levels server-side, render remainder via ajax
config.add_facet_field 'lc_callnum_facet',
if: :has_search_parameters?,
Expand All @@ -269,21 +263,23 @@ def authorize_email_use!
}
}

config.add_facet_field 'collection', :show => false


config.add_facet_field 'acquired_dt_query', label: 'Date Acquired', query: {
last_1_week: { label: 'Since last week', fq: "acquired_dt:[NOW-14DAY TO NOW-7DAY]"},
last_1_month: { label: 'Since last month', fq: "acquired_dt:[NOW-30DAY TO NOW-7DAY]"},
last_1_years: { label: 'Since last year', fq: "acquired_dt:[NOW-1YEAR TO NOW-7DAY]"}
}, if: :has_search_parameters?


# config.add_facet_field 'facet', :multiple => true
# config.add_facet_field 'first_facet,last_facet', :pivot => ['first_facet', 'last_facet']
# config.add_facet_field 'my_query_field', :query => { 'label' => 'value:1', 'label2' => 'value:2'}
# config.add_facet_field 'facet', :single => true
# config.add_facet_field 'facet', :tag => 'my_tag', :ex => 'my_tag'
# Facets not shown in side bar, but available for filtering
config.add_facet_field 'authortitle_facet', :show => false, :label => "Author-Title"
config.add_facet_field 'availability_facet', :show => false, :label => "Availability"
config.add_facet_field 'lc_alpha_facet', :show => false, :label => 'Call Number', :limit => 5
config.add_facet_field 'collection', :show => false, :label => "Collection"
config.add_facet_field 'subject_corp_lc_facet', :show => false, :label => "Subject: Corporate Name LC"
config.add_facet_field 'subject_pers_lc_facet', :show => false, :label => "Subject: Personal Name LC"
config.add_facet_field 'subject_sub_lc_facet', :show => false, :label => "Subject: Subdivision LC"
config.add_facet_field 'subject_topic_lc_facet', :show => false, :label => "Subject: Topic LC"
config.add_facet_field 'subject_work_lc_facet', :show => false, :label => "Subject: Work LC"
config.add_facet_field 'workid_facet', :show => false, :label => 'Work'

#config.default_solr_params[:'facet.field'] = config.facet_fields.keys
config.add_facet_fields_to_solr_request!
Expand Down
18 changes: 1 addition & 17 deletions blacklight-cornell/app/models/search_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SearchBuilder < Blacklight::SearchBuilder
include BlacklightRangeLimit::RangeLimitBuilder

self.default_processor_chain += [:sortby_title_when_browsing, :sortby_callnum,
:set_fl, :set_fq, :set_query,
:set_fl, :set_query,
:homepage_default, :reset_facet_limit, :group_bento_results]

DEFAULT_BOOLEAN = 'AND'
Expand Down Expand Up @@ -51,22 +51,6 @@ def set_fl solr_parameters
solr_parameters[:fl] = '*' if blacklight_params['controller'] == 'bookmarks' || blacklight_params['format'].present? || blacklight_params['controller'] == 'book_bags'
end

# Add any facets not already defined by blacklight to the solr fq
# Useful for backend cataloging work
def set_fq solr_parameters
if blacklight_params[:f].present?
solr_parameters[:fq] = solr_parameters[:fq] || []
blacklight_params[:f].each do |key, value|
unless blacklight_config.facet_fields.keys.include?(key)
value.each do |val|
fq_string = "{!term f=#{key.to_s}}#{val}"
solr_parameters[:fq] << fq_string
end
end
end
end
end

# Sets solr q param from search fields, booleans, and ops (simple, advanced, and bento search)
def set_query solr_parameters
# Standard blacklight_params from advanced search form:
Expand Down
2 changes: 1 addition & 1 deletion blacklight-cornell/app/views/catalog/_constraints.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%params[:y] = params[:q] %>
<% params[:q] = params[:show_query] if params[:show_query]%>
<% if params[:controller] != 'advanced_search' && query_has_constraints? %>
<% if params[:controller] != 'advanced_search' && search_state.has_constraints? %>
<div class="selected-facets">
<% if advanced_search? && params[:controller] != 'advanced_search' %>
<div class="modify-search-link">
Expand Down
2 changes: 1 addition & 1 deletion blacklight-cornell/lib/blacklight_cornell/search_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BlacklightCornell
class SearchState < Blacklight::SearchState
# Override has_constraints? to check :q_row for advanced search
def has_constraints?
!(query_param.blank? && advanced_query_param.blank? && filter_params.blank? && filters.blank? && clause_params.blank?)
!(query_param.blank? && advanced_query_param.blank? && filters.blank? && clause_params.blank?)
end

def advanced_query_param
Expand Down
38 changes: 0 additions & 38 deletions blacklight-cornell/spec/models/search_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2194,44 +2194,6 @@
end
end

describe '#set_fq' do
before do
allow(search_builder).to receive(:blacklight_params) { blacklight_params }
end

context 'empty q and search_field' do
let(:blacklight_params) { {
f: {
'author_facet' => ['Bayerische Staatsbibliothek'],
'subject_topic_lc_facet' => ['Block-books, Tibetan']
}
} }

it 'populates solr fq' do
solr_params = { fq: ['{!term f=author_facet}Bayerische Staatsbibliothek'] }
search_builder.set_fq(solr_params)
expect(solr_params[:fq]).to eq(['{!term f=author_facet}Bayerische Staatsbibliothek',
'{!term f=subject_topic_lc_facet}Block-books, Tibetan'])
end
end

context 'existing q and search_field' do
let(:blacklight_params) { {
f: {
'subject_topic_lc_facet' => ['Block-books, Tibetan']
},
q: 'tibetan',
search_field: 'all_fields'
} }

it 'populates solr fq' do
solr_params = {}
search_builder.set_fq(solr_params)
expect(solr_params[:fq]).to eq(['{!term f=subject_topic_lc_facet}Block-books, Tibetan'])
end
end
end

describe '#group_bento_results' do
let(:solr_params) { {
q: '(("cats" AND "dogs") OR phrase:"cats dogs")',
Expand Down