blacklight_advanced_search 6.4.1 → 8.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ruby.yml +125 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +4 -2
  5. data/.rubocop_todo.yml +6 -374
  6. data/Gemfile +3 -8
  7. data/README.md +46 -60
  8. data/Rakefile +2 -2
  9. data/VERSION +1 -1
  10. data/blacklight_advanced_search.gemspec +6 -7
  11. data/config/routes.rb +1 -1
  12. data/lib/blacklight_advanced_search/advanced_query_parser.rb +24 -38
  13. data/lib/blacklight_advanced_search/advanced_search_builder.rb +27 -24
  14. data/lib/blacklight_advanced_search/controller.rb +15 -16
  15. data/lib/blacklight_advanced_search/engine.rb +0 -1
  16. data/lib/blacklight_advanced_search/redirect_legacy_params_filter.rb +24 -7
  17. data/lib/blacklight_advanced_search.rb +0 -4
  18. data/lib/generators/blacklight_advanced_search/install_generator.rb +3 -37
  19. data/lib/parsing_nesting/grammar.rb +0 -12
  20. data/solr/conf/schema.xml +326 -573
  21. data/solr/conf/solrconfig.xml +80 -294
  22. data/spec/features/blacklight_advanced_search_form_spec.rb +13 -18
  23. data/spec/lib/advanced_search_builder_spec.rb +11 -9
  24. data/spec/spec_helper.rb +46 -14
  25. data/spec/test_app_templates/app/controllers/catalog_controller.rb +5 -7
  26. metadata +41 -62
  27. data/.travis.yml +0 -21
  28. data/app/assets/javascripts/blacklight_advanced_search.js +0 -5
  29. data/app/assets/stylesheets/blacklight_advanced_search/advanced_results.css +0 -21
  30. data/app/assets/stylesheets/blacklight_advanced_search/blacklight_advanced_search_styles.css.scss +0 -58
  31. data/app/assets/stylesheets/blacklight_advanced_search.css +0 -6
  32. data/app/controllers/advanced_controller.rb +0 -25
  33. data/app/controllers/blacklight_advanced_search/advanced_controller.rb +0 -25
  34. data/app/helpers/advanced_helper.rb +0 -4
  35. data/app/helpers/blacklight_advanced_search/advanced_helper_behavior.rb +0 -57
  36. data/app/views/advanced/_advanced_search_facets.html.erb +0 -16
  37. data/app/views/advanced/_advanced_search_facets_as_select.html.erb +0 -30
  38. data/app/views/advanced/_advanced_search_fields.html.erb +0 -8
  39. data/app/views/advanced/_advanced_search_form.html.erb +0 -43
  40. data/app/views/advanced/_advanced_search_help.html.erb +0 -24
  41. data/app/views/advanced/_advanced_search_submit_btns.html.erb +0 -12
  42. data/app/views/advanced/_facet_limit.html.erb +0 -15
  43. data/app/views/advanced/index.html.erb +0 -21
  44. data/app/views/blacklight_advanced_search/_facet_limit.html.erb +0 -16
  45. data/config/jetty.yml +0 -4
  46. data/config/locales/blacklight_advanced_search.en.yml +0 -12
  47. data/lib/blacklight_advanced_search/catalog_helper_override.rb +0 -30
  48. data/lib/blacklight_advanced_search/filter_parser.rb +0 -11
  49. data/lib/blacklight_advanced_search/parsing_nesting_parser.rb +0 -15
  50. data/lib/blacklight_advanced_search/render_constraints_override.rb +0 -136
  51. data/lib/generators/blacklight_advanced_search/assets_generator.rb +0 -53
  52. data/lib/generators/blacklight_advanced_search/templates/advanced_controller.rb +0 -56
  53. data/lib/generators/blacklight_advanced_search/templates/saved_searches_controller.rb +0 -6
  54. data/lib/generators/blacklight_advanced_search/templates/search_history_controller.rb +0 -6
  55. data/solr/sample_solr_documents.yml +0 -2692
  56. data/spec/helpers/advanced_helper_spec.rb +0 -13
  57. data/spec/lib/blacklight_advanced_search/render_constraints_override_spec.rb +0 -39
  58. data/spec/lib/filter_parser_spec.rb +0 -22
data/config/jetty.yml DELETED
@@ -1,4 +0,0 @@
1
- default:
2
- startup_wait: 15
3
- jetty_port: <%= ENV['TEST_JETTY_PORT'] || 8888 %>
4
- <%= ENV['TEST_JETTY_PATH'] ? "jetty_home: " + ENV['TEST_JETTY_PATH'] : '' %>
@@ -1,12 +0,0 @@
1
- en:
2
- blacklight_advanced_search:
3
- all: all
4
- any: any
5
- form:
6
- title: More Search Options
7
- search_context: Within search
8
- limit_criteria_heading_html: "<strong>AND</strong> have these attributes"
9
- query_criteria_heading_html: "Find items that match %{select_menu} of"
10
- sort_label: "Sort results by"
11
- start_over: "Start over"
12
- search_btn: 'Search'
@@ -1,30 +0,0 @@
1
- module BlacklightAdvancedSearch::CatalogHelperOverride
2
- # Special display for facet limits that include adv search inclusive
3
- # or limits.
4
- def facet_partial_name(display_facet = nil)
5
- return "blacklight_advanced_search/facet_limit" if advanced_query && advanced_query.filters.keys.include?(display_facet.name)
6
- super
7
- end
8
-
9
- def remove_advanced_facet_param(field, value, my_params = params)
10
- my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h
11
- if (my_params[:f_inclusive] &&
12
- my_params[:f_inclusive][field] &&
13
- my_params[:f_inclusive][field].include?(value))
14
-
15
- my_params[:f_inclusive] = my_params[:f_inclusive].dup
16
- my_params[:f_inclusive][field] = my_params[:f_inclusive][field].dup
17
- my_params[:f_inclusive][field].delete(value)
18
-
19
- my_params[:f_inclusive].delete(field) if my_params[:f_inclusive][field].empty?
20
-
21
- my_params.delete(:f_inclusive) if my_params[:f_inclusive].empty?
22
- end
23
-
24
- my_params.delete_if do |key, _value|
25
- [:page, :id, :counter, :commit].include?(key)
26
- end
27
-
28
- my_params
29
- end
30
- end
@@ -1,11 +0,0 @@
1
- module BlacklightAdvancedSearch::FilterParser
2
- # Returns an array of solr :fq params. taking advanced search inclusive
3
- # facet value lists out of params.
4
- def generate_solr_fq
5
- filters.map do |solr_field, value_list|
6
- "#{solr_field}:(" +
7
- Array(value_list).collect { |v| '"' + v.gsub('"', '\"') + '"' }.join(" OR ") +
8
- ")"
9
- end
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- require 'parsing_nesting/tree'
2
- module BlacklightAdvancedSearch::ParsingNestingParser
3
- def process_query(_params, config)
4
- queries = keyword_queries.map do |field, query|
5
- ParsingNesting::Tree.parse(query, config.advanced_search[:query_parser]).to_query(local_param_hash(field, config))
6
- end
7
- queries.join(" #{keyword_op} ")
8
- end
9
-
10
- def local_param_hash(key, config)
11
- field_def = config.search_fields[key]
12
-
13
- (field_def[:solr_adv_parameters] || field_def[:solr_parameters] || {}).merge(field_def[:solr_local_parameters] || {})
14
- end
15
- end
@@ -1,136 +0,0 @@
1
- # Meant to be applied on top of Blacklight view helpers, to over-ride
2
- # certain methods from RenderConstraintsHelper (newish in BL),
3
- # to effect constraints rendering and search history rendering,
4
- module BlacklightAdvancedSearch::RenderConstraintsOverride
5
- def query_has_constraints?(localized_params = params)
6
- if is_advanced_search? localized_params
7
- true
8
- else
9
- !(localized_params[:q].blank? && localized_params[:f].blank? && localized_params[:f_inclusive].blank?)
10
- end
11
- end
12
-
13
- # Over-ride of Blacklight method, provide advanced constraints if needed,
14
- # otherwise call super.
15
- def render_constraints_query(my_params = params)
16
- if (advanced_query.nil? || advanced_query.keyword_queries.empty?)
17
- return super(my_params)
18
- else
19
- content = []
20
- advanced_query.keyword_queries.each_pair do |field, query|
21
- label = search_field_def_for_key(field)[:label]
22
- content << render_constraint_element(
23
- label, query,
24
- :remove =>
25
- search_action_path(remove_advanced_keyword_query(field, my_params).except(:controller, :action))
26
- )
27
- end
28
- if (advanced_query.keyword_op == "OR" &&
29
- advanced_query.keyword_queries.length > 1)
30
- content.unshift content_tag(:span, "Any of:", class: 'operator')
31
- content_tag :span, class: "inclusive_or appliedFilter well" do
32
- safe_join(content.flatten, "\n")
33
- end
34
- else
35
- safe_join(content.flatten, "\n")
36
- end
37
- end
38
- end
39
-
40
- # Over-ride of Blacklight method, provide advanced constraints if needed,
41
- # otherwise call super.
42
- def render_constraints_filters(my_params = params)
43
- content = super(my_params)
44
-
45
- if advanced_query
46
- advanced_query.filters.each_pair do |field, value_list|
47
- label = facet_field_label(field)
48
- content << render_constraint_element(label,
49
- safe_join(Array(value_list), " <strong class='text-muted constraint-connector'>OR</strong> ".html_safe),
50
- :remove => search_action_path(remove_advanced_filter_group(field, my_params).except(:controller, :action))
51
- )
52
- end
53
- end
54
-
55
- content
56
- end
57
-
58
- # override of BL method, so our inclusive facet selections
59
- # are still recgonized for eg highlighting facet with selected
60
- # values.
61
- def facet_field_in_params?(field)
62
- return true if super
63
-
64
- # otherwise use our own logic.
65
- query = BlacklightAdvancedSearch::QueryParser.new(params, self.blacklight_config)
66
- return true if query.filters.keys.include?(field)
67
-
68
- false
69
- end
70
-
71
- def render_search_to_s_filters(my_params)
72
- content = super(my_params)
73
-
74
- advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config)
75
-
76
- unless advanced_query.filters.empty?
77
- advanced_query.filters.each_pair do |field, values|
78
- # old-style, may still be in history
79
- values = values.keys if values.is_a? Hash
80
-
81
- label = facet_field_label(field)
82
-
83
- content << render_search_to_s_element(
84
- label,
85
- values.join(" OR ")
86
- )
87
- end
88
- end
89
- content
90
- end
91
-
92
- def render_search_to_s_q(my_params)
93
- content = super(my_params)
94
-
95
- advanced_query = BlacklightAdvancedSearch::QueryParser.new(my_params, blacklight_config)
96
-
97
- if (advanced_query.keyword_queries.length > 1 &&
98
- advanced_query.keyword_op == "OR")
99
- # Need to do something to make the inclusive-or search clear
100
-
101
- display_as = advanced_query.keyword_queries.collect do |field, query|
102
- h(search_field_def_for_key(field)[:label] + ": " + query)
103
- end.join(" ; ")
104
-
105
- content << render_search_to_s_element("Any of",
106
- display_as,
107
- :escape_value => false
108
- )
109
- elsif !advanced_query.keyword_queries.empty?
110
- advanced_query.keyword_queries.each_pair do |field, query|
111
- label = search_field_def_for_key(field)[:label]
112
-
113
- content << render_search_to_s_element(label, query)
114
- end
115
- end
116
-
117
- content
118
- end
119
-
120
- def remove_advanced_keyword_query(field, my_params = params)
121
- my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h
122
- my_params.delete(field)
123
- my_params
124
- end
125
-
126
- def remove_advanced_filter_group(field, my_params = params)
127
- if (my_params[:f_inclusive])
128
- my_params = Blacklight::SearchState.new(my_params, blacklight_config).to_h
129
- my_params[:f_inclusive] = my_params[:f_inclusive].dup
130
- my_params[:f_inclusive].delete(field)
131
-
132
- my_params.delete :f_inclusive if my_params[:f_inclusive].empty?
133
- end
134
- my_params
135
- end
136
- end
@@ -1,53 +0,0 @@
1
- # Copy BlacklightAdvancedSearch assets to public folder in current app.
2
- # If you want to do this on application startup, you can
3
- # add this next line to your one of your environment files --
4
- # generally you'd only want to do this in 'development', and can
5
- # add it to environments/development.rb:
6
- # require File.join(BlacklightAdvancedSearch.root, "lib", "generators", "blacklight", "assets_generator.rb")
7
- # BlacklightAdvancedSearch::AssetsGenerator.start(["--force", "--quiet"])
8
-
9
- # Need the requires here so we can call the generator from environment.rb
10
- # as suggested above.
11
- require 'rails/generators'
12
- require 'rails/generators/base'
13
- module BlacklightAdvancedSearch
14
- class AssetsGenerator < Rails::Generators::Base
15
- source_root File.join(BlacklightAdvancedSearch::Engine.root, 'app', 'assets')
16
-
17
- def css_asset
18
- application_css_location = Dir["app/assets/stylesheets/application{.css,.scss,.css.scss}"].first
19
-
20
- unless application_css_location
21
- say_status "skipped", "Can not find an application.css, did not insert our require", :red
22
- return
23
- end
24
-
25
- original_css = File.binread(application_css_location)
26
- if original_css.include?("require 'blacklight_advanced_search'")
27
- say_status("skipped", "insert into app/assets/stylesheets/application.css", :yellow)
28
- else
29
- insert_into_file application_css_location, :before => "*/" do
30
- "\n *= require 'blacklight_advanced_search'\n\n"
31
- end
32
- end
33
- end
34
-
35
- def js_asset
36
- application_js_location = Dir["app/assets/javascripts/application{.js,.coffee,.js.coffee}"].first
37
-
38
- unless application_js_location
39
- say_status "skipped", "Can not find an application.js, did not insert our require", :red
40
- return
41
- end
42
-
43
- original_js = File.binread(application_js_location)
44
- if original_js.include?("require 'blacklight_advanced_search'")
45
- say_status("skipped", "insert into app/assets/javascripts/application.js", :yellow)
46
- else
47
- insert_into_file application_js_location, :after => %r{//= require ['"]?jquery['"]?$} do
48
- "\n//= require 'blacklight_advanced_search'\n\n"
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,56 +0,0 @@
1
- class AdvancedController < BlacklightAdvancedSearch::AdvancedController
2
- blacklight_config.configure do |config|
3
- # name of Solr request handler, leave unset to use the same one your Blacklight
4
- # is ordinarily using (recommended if possible)
5
- # config.advanced_search.qt = 'advanced'
6
-
7
- ##
8
- # The advanced search form displays facets as a limit option.
9
- # By default it will use whatever facets, if any, are returned
10
- # by the Solr request handler in use. However, you can use
11
- # this config option to have it request other facet params than
12
- # default in the Solr request handler, in desired.
13
- config.advanced_search.form_solr_parameters = {}
14
-
15
- # name of key in Blacklight URL, no reason to change usually.
16
- config.advanced_search.url_key = 'advanced'
17
-
18
- # We are going to completely override the inherited search fields
19
- config.search_fields.clear
20
-
21
- config.add_search_field 'author' do |field|
22
- field.solr_local_parameters = {
23
- :pf => "$pf_author",
24
- :qf => "$qf_author"
25
- }
26
- end
27
-
28
- config.add_search_field 'title' do |field|
29
- field.solr_local_parameters = {
30
- :pf => "$pf_title",
31
- :qf => "$qf_title"
32
- }
33
- end
34
-
35
- config.add_search_field 'subject' do |field|
36
- field.solr_local_parameters = {
37
- :pf => "$pf_subject",
38
- :qf => "$qf_subject"
39
- }
40
- end
41
-
42
- config.add_search_field 'keyword' do |field|
43
- field.solr_local_parameters = {
44
- :pf => "$pf_keyword",
45
- :qf => "$qf_keyword"
46
- }
47
- end
48
-
49
- config.add_search_field 'number' do |field|
50
- field.solr_local_parameters = {
51
- :pf => "$pf_number",
52
- :qf => "$qf_number"
53
- }
54
- end
55
- end
56
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- class SavedSearchesController < ApplicationController
3
- include Blacklight::SavedSearches
4
-
5
- helper BlacklightAdvancedSearch::RenderConstraintsOverride
6
- end
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
- class SearchHistoryController < ApplicationController
3
- include Blacklight::SearchHistory
4
-
5
- helper BlacklightAdvancedSearch::RenderConstraintsOverride
6
- end