-
-
Save ebenenglish/d20ae258f9ff9f25c638 to your computer and use it in GitHub Desktop.
blacklight_advanced_search modifications
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%# /app/views/blacklight_advanced_search/_advanced_search_date.html.erb %> | |
<div id="date_range_limit" class="advanced_search_field"> | |
<div class="control-group"> | |
<label class="control-label">Year</label> | |
<div class="controls"> | |
<div class="input-append"> | |
<label id="date_range_start_label" class="control-label" for="date_start">Start</label> | |
<%= text_field_tag 'date_start', | |
nil, | |
:id => 'date_range_start', | |
:class => 'input-mini', | |
:maxlength => 4 %> | |
</div> | |
<div class="input-prepend"> | |
<label id="date_range_end_label" class="control-label" for="date_end">End</label> | |
<%= text_field_tag 'date_end', | |
nil, | |
:id => 'date_range_end', | |
:class => 'input-mini', | |
:maxlength => 4 %> | |
</div> | |
</div> | |
</div> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%# /app/views/blacklight_advanced_search/_advanced_search_fields.html.erb %> | |
<% search_fields_for_advanced_search.take(3).each_with_index do |(key, field_def), index| %> | |
<div class="advanced_search_field"> | |
<%= select_tag('search_index[]', | |
options_for_select(search_fields, | |
search_fields[index]), | |
:title => t('blacklight.basic_search.form.search_indexes'), | |
:class=> 'btn search_index_select') %> | |
<%= label_tag('input' + (index+1).to_s, | |
t('blacklight.basic_search.form.q') + ' (' + (index+1).to_s + ')', | |
:class => 'hide-text') %> | |
<%= text_field_tag 'query[]', | |
nil, | |
:class => 'input-xlarge', | |
:autofocus => index == 0 ? true : false %> | |
</div> | |
<% end %> | |
<div class="advanced_search_field"> | |
<div id="advanced_operators"> | |
<label class="radio inline"> | |
<%= radio_button_tag(:op, 'AND', :checked) %> find all terms | |
</label> | |
<label class="radio inline"> | |
<%= radio_button_tag(:op, 'OR') %> find any terms | |
</label> | |
</div> | |
</div> | |
<div class="pull-right"> | |
<%= submit_tag 'Search', :class=>'btn btn-primary', :id=>'advanced_search' %> | |
<%= link_to 'Start over', {:controller => 'advanced', :action => 'index'}, :class =>'reset btn' %> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/blacklight_advanced_search/advanced_query_parser.rb | |
module BlacklightAdvancedSearch | |
class QueryParser | |
include ParsingNestingParser # only one strategy currently supported. if BlacklightAdvancedSearch.config[:solr_type] == "parsing_nesting" | |
include FilterParser | |
attr_reader :config, :params | |
# LOCAL ADDITION change params to be what's expected by gem | |
def prepare_params(params) | |
if params[:search_index] | |
params[:search_index].each_with_index do |field,index| | |
if params[field.to_sym] # check if field is set | |
unless params[:query][index].empty? | |
if params[:op] == 'OR' | |
params[field.to_sym] = params[field.to_sym] + ' OR ' + params[:query][index] | |
else | |
params[field.to_sym] = params[field.to_sym] + ' AND ' + params[:query][index] | |
end | |
else | |
params[field.to_sym] = params[field.to_sym] | |
end | |
else | |
params[field.to_sym] = params[:query][index] | |
end | |
end | |
params.delete(:search_index) | |
params.delete(:query) | |
end | |
params | |
end | |
# LOCAL OVERRIDE | |
def initialize(params,config) | |
@params = HashWithIndifferentAccess.new(prepare_params(params)) | |
@config = config | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/blacklight_advanced_search/parsing_nesting_parser.rb | |
require 'parsing_nesting/tree' | |
module BlacklightAdvancedSearch::ParsingNestingParser | |
# LOCAL OVERRIDE | |
def process_query(params,config) | |
queries = [] | |
keyword_queries.each do |field,query| | |
queries << ParsingNesting::Tree.parse(query).to_query( local_param_hash(field, config) ) | |
end | |
if params[:date_start].blank? && params[:date_end].blank? | |
queries.join( ' ' + keyword_op + ' ') | |
else | |
queries.join( ' ' + keyword_op + ' ') + ' AND ' + add_date_range_to_queries(params) | |
end | |
end | |
# LOCAL ADDITION | |
def add_date_range_to_queries(params) | |
range_start = params[:date_start].blank? ? '*' : params[:date_start] + '-01-01T00:00:00.000Z' | |
range_end = params[:date_end].blank? ? '*' : params[:date_end] + '-12-31T23:59:59.999Z' | |
date_query = 'date_start_dtsi:[' + range_start + ' TO ' + range_end + ']' | |
date_query | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment