Module: BlacklightAdvancedSearch::RenderConstraintsOverride
- Defined in:
- lib/blacklight_advanced_search/render_constraints_override.rb
Overview
Meant to be applied on top of Blacklight view helpers, to over-ride certain methods from RenderConstraintsHelper (newish in BL), to effect constraints rendering and search history rendering,
Instance Method Summary collapse
-
#facet_field_in_params?(field) ⇒ Boolean
override of BL method, so our inclusive facet selections are still recgonized for eg highlighting facet with selected values.
- #query_has_constraints?(localized_params = params) ⇒ Boolean
- #remove_advanced_filter_group(field, my_params = params) ⇒ Object
- #remove_advanced_keyword_query(field, my_params = params) ⇒ Object
-
#render_constraints_filters(my_params = params) ⇒ Object
Over-ride of Blacklight method, provide advanced constraints if needed, otherwise call super.
-
#render_constraints_query(my_params = params) ⇒ Object
Over-ride of Blacklight method, provide advanced constraints if needed, otherwise call super.
- #render_search_to_s_filters(my_params) ⇒ Object
- #render_search_to_s_q(my_params) ⇒ Object
Instance Method Details
#facet_field_in_params?(field) ⇒ Boolean
override of BL method, so our inclusive facet selections are still recgonized for eg highlighting facet with selected values.
61 62 63 64 65 66 67 68 69 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 61 def facet_field_in_params?(field) return true if super # otherwise use our own logic. query = BlacklightAdvancedSearch::QueryParser.new(params, self.blacklight_config) return true if query.filters.keys.include?(field) false end |
#query_has_constraints?(localized_params = params) ⇒ Boolean
5 6 7 8 9 10 11 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 5 def query_has_constraints?(localized_params = params) if is_advanced_search? localized_params true else !(localized_params[:q].blank? && localized_params[:f].blank? && localized_params[:f_inclusive].blank?) end end |
#remove_advanced_filter_group(field, my_params = params) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 126 def remove_advanced_filter_group(field, my_params = params) if (my_params[:f_inclusive]) my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h my_params[:f_inclusive] = my_params[:f_inclusive].dup my_params[:f_inclusive].delete(field) my_params.delete :f_inclusive if my_params[:f_inclusive].empty? end my_params end |
#remove_advanced_keyword_query(field, my_params = params) ⇒ Object
120 121 122 123 124 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 120 def remove_advanced_keyword_query(field, my_params = params) my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h my_params.delete(field) my_params end |
#render_constraints_filters(my_params = params) ⇒ Object
Over-ride of Blacklight method, provide advanced constraints if needed, otherwise call super.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 42 def render_constraints_filters(my_params = params) content = super(my_params) if advanced_query advanced_query.filters.each_pair do |field, value_list| label = facet_field_label(field) content << render_constraint_element(label, safe_join(Array(value_list), " <strong class='text-muted constraint-connector'>OR</strong> ".html_safe), :remove => search_action_path(remove_advanced_filter_group(field, my_params).except(:controller, :action)) ) end end content end |
#render_constraints_query(my_params = params) ⇒ Object
Over-ride of Blacklight method, provide advanced constraints if needed, otherwise call super.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 15 def render_constraints_query(my_params = params) if (advanced_query.nil? || advanced_query.keyword_queries.empty?) return super(my_params) else content = [] advanced_query.keyword_queries.each_pair do |field, query| label = search_field_def_for_key(field)[:label] content << render_constraint_element( label, query, :remove => search_action_path(remove_advanced_keyword_query(field, my_params).except(:controller, :action)) ) end if (advanced_query.keyword_op == "OR" && advanced_query.keyword_queries.length > 1) content.unshift content_tag(:span, "Any of:", class: 'operator') content_tag :span, class: "inclusive_or appliedFilter well" do safe_join(content.flatten, "\n") end else safe_join(content.flatten, "\n") end end end |
#render_search_to_s_filters(my_params) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 71 def render_search_to_s_filters(my_params) content = super(my_params) advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config) unless advanced_query.filters.empty? advanced_query.filters.each_pair do |field, values| # old-style, may still be in history values = values.keys if values.is_a? Hash label = facet_field_label(field) content << render_search_to_s_element( label, values.join(" OR ") ) end end content end |
#render_search_to_s_q(my_params) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/blacklight_advanced_search/render_constraints_override.rb', line 92 def render_search_to_s_q(my_params) content = super(my_params) advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config) if (advanced_query.keyword_queries.length > 1 && advanced_query.keyword_op == "OR") # Need to do something to make the inclusive-or search clear display_as = advanced_query.keyword_queries.collect do |field, query| h(search_field_def_for_key(field)[:label] + ": " + query) end.join(" ; ") content << render_search_to_s_element("Any of", display_as, :escape_value => false ) elsif !advanced_query.keyword_queries.empty? advanced_query.keyword_queries.each_pair do |field, query| label = search_field_def_for_key(field)[:label] content << render_search_to_s_element(label, query) end end content end |