blacklight_advanced_search 7.0.0 → 8.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +126 -0
  3. data/.gitignore +1 -0
  4. data/.rubocop.yml +3 -1
  5. data/Gemfile +2 -9
  6. data/README.md +43 -57
  7. data/VERSION +1 -1
  8. data/blacklight_advanced_search.gemspec +3 -2
  9. data/config/routes.rb +1 -1
  10. data/lib/blacklight_advanced_search/advanced_query_parser.rb +24 -38
  11. data/lib/blacklight_advanced_search/advanced_search_builder.rb +26 -23
  12. data/lib/blacklight_advanced_search/controller.rb +15 -16
  13. data/lib/blacklight_advanced_search/redirect_legacy_params_filter.rb +23 -6
  14. data/lib/blacklight_advanced_search.rb +0 -4
  15. data/lib/generators/blacklight_advanced_search/install_generator.rb +3 -37
  16. data/lib/parsing_nesting/grammar.rb +0 -12
  17. data/solr/conf/solrconfig.xml +2 -1
  18. data/spec/features/blacklight_advanced_search_form_spec.rb +10 -15
  19. data/spec/lib/advanced_search_builder_spec.rb +11 -8
  20. data/spec/spec_helper.rb +46 -14
  21. data/spec/test_app_templates/app/controllers/catalog_controller.rb +1 -3
  22. metadata +36 -51
  23. data/.travis.yml +0 -21
  24. data/app/assets/javascripts/blacklight_advanced_search.js +0 -5
  25. data/app/assets/stylesheets/blacklight_advanced_search/advanced_results.css +0 -21
  26. data/app/assets/stylesheets/blacklight_advanced_search/blacklight_advanced_search_styles.css.scss +0 -62
  27. data/app/assets/stylesheets/blacklight_advanced_search.css +0 -6
  28. data/app/controllers/advanced_controller.rb +0 -25
  29. data/app/controllers/blacklight_advanced_search/advanced_controller.rb +0 -25
  30. data/app/helpers/advanced_helper.rb +0 -4
  31. data/app/helpers/blacklight_advanced_search/advanced_helper_behavior.rb +0 -57
  32. data/app/views/advanced/_advanced_search_facets.html.erb +0 -16
  33. data/app/views/advanced/_advanced_search_facets_as_select.html.erb +0 -30
  34. data/app/views/advanced/_advanced_search_fields.html.erb +0 -8
  35. data/app/views/advanced/_advanced_search_form.html.erb +0 -43
  36. data/app/views/advanced/_advanced_search_help.html.erb +0 -24
  37. data/app/views/advanced/_advanced_search_submit_btns.html.erb +0 -12
  38. data/app/views/advanced/_facet_limit.html.erb +0 -15
  39. data/app/views/advanced/index.html.erb +0 -21
  40. data/app/views/blacklight_advanced_search/_facet_limit.html.erb +0 -16
  41. data/config/jetty.yml +0 -4
  42. data/config/locales/blacklight_advanced_search.en.yml +0 -12
  43. data/lib/blacklight_advanced_search/catalog_helper_override.rb +0 -30
  44. data/lib/blacklight_advanced_search/filter_parser.rb +0 -11
  45. data/lib/blacklight_advanced_search/parsing_nesting_parser.rb +0 -15
  46. data/lib/blacklight_advanced_search/render_constraints_override.rb +0 -136
  47. data/lib/generators/blacklight_advanced_search/assets_generator.rb +0 -53
  48. data/lib/generators/blacklight_advanced_search/templates/advanced_controller.rb +0 -56
  49. data/lib/generators/blacklight_advanced_search/templates/saved_searches_controller.rb +0 -6
  50. data/lib/generators/blacklight_advanced_search/templates/search_history_controller.rb +0 -6
  51. data/spec/helpers/advanced_helper_spec.rb +0 -13
  52. data/spec/lib/blacklight_advanced_search/parsing_nesting_parser_spec.rb +0 -20
  53. data/spec/lib/blacklight_advanced_search/render_constraints_override_spec.rb +0 -39
  54. data/spec/lib/filter_parser_spec.rb +0 -22
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e20cc9f13b893cec492aa6cc86da05dd170a7d05aee03ab8cd2907ab82d383b
4
- data.tar.gz: 4316c69ac26a65898b9b3a9c22486e353e49889e7134f87d49f391a3ff928966
3
+ metadata.gz: 4e9396af949fde0ccc4ecb6c3aed38179618b43fb94981cf703b45f7f4e0e9d9
4
+ data.tar.gz: '08420957e733036ac9bf41eebc1d85a0c0bf1904758239f3135f59c2395a7148'
5
5
  SHA512:
6
- metadata.gz: feb9014523f4833d4b60fcb981e0ea403c3026a3ad8f93d9dc5ba66e6b52f1ba80a878b93a88324d8f3b0a608f1119da38909d49d1e446dee88e9f83fc17af5c
7
- data.tar.gz: 9fd6367a4945caf22686dade81b1daf60ac8865079106e311098a8ad3765910ada88ee8c2132ff95743c5d939266912ea5f40947048e14245d917602c06209a5
6
+ metadata.gz: aa70a1c801b2a471341b5521259f6b30614a8fb1df8d2006531170632dcbbd5e82dca2d3e6d4f496dab47b0d43bd6766224206a0e0766f5ab438f72765b39bb4
7
+ data.tar.gz: e636fc6d32911b8254eac38fe35842ec5f310f50fcacee0fdf59679b52dec3d0f38fee2954e425ead63f82f4c43b96c9cd9f24818ba19b786c0943b134aa08d4
@@ -0,0 +1,126 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: CI
9
+
10
+ on:
11
+ push:
12
+ branches:
13
+ - main
14
+ - master
15
+ - 'release-*'
16
+ pull_request:
17
+
18
+ jobs:
19
+ lint:
20
+ runs-on: ubuntu-latest
21
+ steps:
22
+ - uses: actions/checkout@v2
23
+ - name: Set up Ruby
24
+ uses: ruby/setup-ruby@v1
25
+ with:
26
+ ruby-version: 2.7
27
+ - name: Install dependencies
28
+ run: bundle install
29
+ - name: Run linter
30
+ run: bundle exec rake rubocop
31
+ test:
32
+ runs-on: ubuntu-latest
33
+ strategy:
34
+ matrix:
35
+ ruby: [2.7, '3.0', 3.1]
36
+ steps:
37
+ - uses: actions/checkout@v2
38
+ - name: Set up Ruby
39
+ uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: ${{ matrix.ruby }}
42
+ - name: Install dependencies
43
+ run: bundle install
44
+ - name: Run tests
45
+ run: bundle exec rake ci
46
+ env:
47
+ ENGINE_CART_RAILS_OPTIONS: '-a propshaft --skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
48
+ test_bootstrap5:
49
+ runs-on: ubuntu-latest
50
+ strategy:
51
+ matrix:
52
+ ruby: ['3.0']
53
+ steps:
54
+ - uses: actions/checkout@v2
55
+ - name: Set up Ruby
56
+ uses: ruby/setup-ruby@v1
57
+ with:
58
+ ruby-version: ${{ matrix.ruby }}
59
+ - name: Install dependencies
60
+ run: bundle install
61
+ - name: Run tests
62
+ run: bundle exec rake ci
63
+ env:
64
+ BOOTSTRAP_VERSION: '~> 5.0'
65
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
66
+ test_rails6_0:
67
+ runs-on: ubuntu-latest
68
+ strategy:
69
+ matrix:
70
+ ruby: [2.6]
71
+ steps:
72
+ - uses: actions/checkout@v2
73
+ - name: Set up Ruby
74
+ uses: ruby/setup-ruby@v1
75
+ with:
76
+ ruby-version: ${{ matrix.ruby }}
77
+ - name: Install dependencies
78
+ run: bundle install
79
+ env:
80
+ RAILS_VERSION: 6.0.3.7
81
+ - name: Run tests
82
+ run: bundle exec rake ci
83
+ env:
84
+ RAILS_VERSION: 6.0.3.7
85
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
86
+ test_rails5_2:
87
+ runs-on: ubuntu-latest
88
+ strategy:
89
+ matrix:
90
+ ruby: [2.7]
91
+ steps:
92
+ - uses: actions/checkout@v2
93
+ - name: Set up Ruby
94
+ uses: ruby/setup-ruby@v1
95
+ with:
96
+ ruby-version: ${{ matrix.ruby }}
97
+ - name: Install dependencies
98
+ run: bundle install
99
+ env:
100
+ RAILS_VERSION: 5.2.4.6
101
+ - name: Run tests
102
+ run: bundle exec rake ci
103
+ env:
104
+ RAILS_VERSION: 5.2.4.6
105
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-listen --skip-spring --skip-keeps --skip-action-cable --skip-coffee --skip-test'
106
+
107
+ test_rails6_1:
108
+ runs-on: ubuntu-latest
109
+ strategy:
110
+ matrix:
111
+ ruby: ['3.0']
112
+ steps:
113
+ - uses: actions/checkout@v2
114
+ - name: Set up Ruby
115
+ uses: ruby/setup-ruby@v1
116
+ with:
117
+ ruby-version: ${{ matrix.ruby }}
118
+ - name: Install dependencies
119
+ run: bundle install
120
+ env:
121
+ RAILS_VERSION: 6.1.5
122
+ - name: Run tests
123
+ run: bundle exec rake ci
124
+ env:
125
+ RAILS_VERSION: 6.1.5
126
+ ENGINE_CART_RAILS_OPTIONS: '--skip-git --skip-keeps --skip-action-cable --skip-test'
data/.gitignore CHANGED
@@ -9,3 +9,4 @@ log/*
9
9
  Gemfile.lock
10
10
  pkg/*
11
11
  tmp/*
12
+ /spec/examples.txt
data/.rubocop.yml CHANGED
@@ -1,5 +1,7 @@
1
1
  inherit_from: .rubocop_todo.yml
2
- require: rubocop-rspec
2
+ require:
3
+ - rubocop-rspec
4
+ - rubocop-rails
3
5
 
4
6
  AllCops:
5
7
  DisplayCopNames: true
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
@@ -27,15 +27,8 @@ else
27
27
  end
28
28
 
29
29
  case ENV['RAILS_VERSION']
30
- when /^5.[12]/, /^6.0/
30
+ when /^5.2/, /^6.0/
31
31
  gem 'sass-rails', '~> 5.0'
32
- when /^4.2/
33
- gem 'responders', '~> 2.0'
34
- gem 'sass-rails', '>= 5.0'
35
- gem 'coffee-rails', '~> 4.1.0'
36
- gem 'json', '~> 1.8'
37
- when /^4.[01]/
38
- gem 'sass-rails', '< 5.0'
39
32
  end
40
33
  end
41
34
  # END ENGINE_CART BLOCK
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- This is an advanced search plugin for Blacklight ( http://www.projectblacklight.org ).
1
+ This is an advanced search plugin for Blacklight ( http://www.projectblacklight.org ).
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/blacklight_advanced_search.svg)](http://badge.fury.io/rb/blacklight_advanced_search) [![Build Status](https://travis-ci.org/projectblacklight/blacklight_advanced_search.svg)](https://travis-ci.org/projectblacklight/blacklight_advanced_search)
4
4
 
@@ -14,15 +14,15 @@ work with which versions of `blacklight`. Some notes:
14
14
  facet selections, from the advanced form. If you'd like to keep old-style possibly
15
15
  bookmarked URLs working, by redirecting to new format, add this to your
16
16
  `CatalogController`:
17
-
17
+
18
18
  before_filter BlacklightAdvancedSearch::RedirectLegacyParamsFilter, :only => :index
19
19
 
20
- * version 2.2 of `blacklight_advanced_search` should work with `blacklight` 4.x.
20
+ * version 2.2 of `blacklight_advanced_search` should work with `blacklight` 4.x.
21
21
  * versions `1.2.*` of Advanced Search plugin can work with blacklight 3.2.2 through latest 3.2.x
22
- * 1.2.0 was an aborted version, don't use it, if you did, re-do your configuration according to current instructions and delete any local ./app/controllers/advanced_controller.rb file.
22
+ * 1.2.0 was an aborted version, don't use it, if you did, re-do your configuration according to current instructions and delete any local ./app/controllers/advanced_controller.rb file.
23
23
  * advanced search 1.1.x versions will work with Blacklights 3.0.x through 3.1.x
24
- * advanced search plugin latest 0.X.X version will work with Blacklight 2.9/Rails2.
25
- * Older tagged versions of Advanced Search may work with even older BL.
24
+ * advanced search plugin latest 0.X.X version will work with Blacklight 2.9/Rails2.
25
+ * Older tagged versions of Advanced Search may work with even older BL.
26
26
 
27
27
  ## Installation
28
28
 
@@ -37,24 +37,24 @@ then run 'bundle install'. Then run:
37
37
  rails generate blacklight_advanced_search
38
38
 
39
39
  * The 'generate' command will install 'require' statements for the plugin's assets into your application's application.js/application.css asset pipeline files
40
- * And it can optionally install a localized search form with a link to advanced search. If you've already localized your search form you'll want to do this manually instead.
40
+ * And it can optionally install a localized search form with a link to advanced search. If you've already localized your search form you'll want to do this manually instead.
41
41
 
42
- You may want turn to enable AND/OR/NOT parsing even in ordinary search, this is not on by default. See "Expression parsing in ordinary search" below.
42
+ You may want turn to enable AND/OR/NOT parsing even in ordinary search, this is not on by default. See "Expression parsing in ordinary search" below.
43
43
 
44
44
  ## Accessing
45
-
45
+
46
46
  The advanced search form will be available in your app at /advanced, and in your app using
47
- routing helper `advanced_search_path`.
47
+ routing helper `advanced_search_path`.
48
48
 
49
49
  advanced_search_path
50
-
50
+
51
51
  You can also send the advanced search form url parameters representing a search, to have the form add on additional 'advanced' criteria to the search. For example:
52
52
 
53
53
  advanced_search_path( params )
54
-
55
- By default there won't be any links in your application to the search form. If you've heavily customized your app, you can put them wherever you want as above.
56
54
 
57
- However, especially if your app isn't much customized, the optional installer can write a localized Blacklight search form into your application with a 'more options' link to advanced. You may need to adjust your styles to make room for the new link, depending on what you've done with your app.
55
+ By default there won't be any links in your application to the search form. If you've heavily customized your app, you can put them wherever you want as above.
56
+
57
+ However, especially if your app isn't much customized, the optional installer can write a localized Blacklight search form into your application with a 'more options' link to advanced. You may need to adjust your styles to make room for the new link, depending on what you've done with your app.
58
58
 
59
59
 
60
60
  ## Configuration
@@ -68,7 +68,7 @@ Turn this feature on by adding to your SearchBuilder definition:
68
68
 
69
69
  self.default_processor_chain << :add_advanced_parse_q_to_solr
70
70
 
71
- This will intercept queries entered in ordinary Blacklight search interface, and parse them for AND/OR/NOT (and parens), producing appropriate Solr query. This allows single-field boolean expressions to be entered in ordinary search, providing a consistent experience with advanced search.
71
+ This will intercept queries entered in ordinary Blacklight search interface, and parse them for AND/OR/NOT (and parens), producing appropriate Solr query. This allows single-field boolean expressions to be entered in ordinary search, providing a consistent experience with advanced search.
72
72
 
73
73
  Individual blacklight 'search fields' can have advanced parsing turned off:
74
74
 
@@ -78,39 +78,39 @@ Individual blacklight 'search fields' can have advanced parsing turned off:
78
78
  end
79
79
 
80
80
 
81
- When this feature is turned on, queries that don't have any special operators (eg: AND, OR, NOT, parens) will still be passed to Solr much the same as they were before. But queries with special operators will have appropriate Solr queries generated for them, usually including nested "_query_" elements, to have the same meaning they would in advanced search. If a user enters something that is a syntax error for parsed search (for instance an unclosed phrase quote or paren), the logic will rescue from the parse erorr by running the exact user entered query direct to solr without advanced parsing.
81
+ When this feature is turned on, queries that don't have any special operators (eg: AND, OR, NOT, parens) will still be passed to Solr much the same as they were before. But queries with special operators will have appropriate Solr queries generated for them, usually including nested "_query_" elements, to have the same meaning they would in advanced search. If a user enters something that is a syntax error for parsed search (for instance an unclosed phrase quote or paren), the logic will rescue from the parse erorr by running the exact user entered query direct to solr without advanced parsing.
82
82
 
83
83
  Due to limitations of the logic, sometimes these generated Solr queries may not really be as simple as they could be, they may include a *single* nested _query_, which really doens't need to be a nested query at all, although it will still work fine.
84
84
 
85
- If there'a a parse error trying to parse as boolean expression, it'll give up and pass the query on through same as it would without ParseBasicQ.
85
+ If there'a a parse error trying to parse as boolean expression, it'll give up and pass the query on through same as it would without ParseBasicQ.
86
86
 
87
87
  ### Search fields
88
88
 
89
- Your main blacklight search fields are generally defined in CatalogController blacklight_config using `add_search_field`. They are all by default used in advanced search.
89
+ Your main blacklight search fields are generally defined in CatalogController blacklight_config using `add_search_field`. They are all by default used in advanced search.
90
90
 
91
91
  If there are particular search fields in your main blacklight config you want excluded from the advanced search form, you can set ":include_in_advanced_search => false"
92
92
 
93
93
  config.add_search_field("isbn") do |field|
94
94
  field.include_in_advanced_search = false
95
- field.solr_parameters = { :qf => "isbn_t" }
96
- end
95
+ field.solr_parameters = { :qf => "isbn_t" }
96
+ end
97
97
 
98
98
  If you want search fields ONLY available in advanced search, you can suppress them from ordinary search:
99
99
 
100
100
  config.add_search_field("publisher") do |field|
101
101
  field.include_in_simple_select = false
102
- field.solr_parameters = { :qf => "publisher_t" }
102
+ field.solr_parameters = { :qf => "publisher_t" }
103
103
  end
104
104
 
105
105
  All advanced search fields must share the same Solr request handler (":qt"). As such, search fields that use a custom ":qt" parameter may not be re-used by the advanced search plugin. However, you may use a separate Solr request handler than the Blacklight default. If you would like the advanced search to use a different Solr request handler than your app's default, set:
106
-
107
- config.advanced_search = {
106
+
107
+ config.advanced_search = {
108
108
  :qt => 'advanced'
109
109
  }
110
-
111
- If you use a separate Solr request handler for advanced search, you must supply a completely separate list of search fields for the advanced search form, just define them with `:include_in_advanced_search => true` and `:include_in_simple_search => false` as above.
112
110
 
113
- Additionally, to make your advanced search solr requests more concise, you are strongly encouraged to take advantage of the :local_solr_parameters option in your search field definition to use a solr parameter substitution with $variables.
111
+ If you use a separate Solr request handler for advanced search, you must supply a completely separate list of search fields for the advanced search form, just define them with `:include_in_advanced_search => true` and `:include_in_simple_search => false` as above.
112
+
113
+ Additionally, to make your advanced search solr requests more concise, you are strongly encouraged to take advantage of the :local_solr_parameters option in your search field definition to use a solr parameter substitution with $variables.
114
114
 
115
115
  configure_blacklight do |config|
116
116
  config.add_search_field('author') do |field|
@@ -145,10 +145,9 @@ Within your solrconfig.xml you may then provide the appropriate custom configura
145
145
  </lst>
146
146
  </requestHandler>
147
147
 
148
-
149
148
  ### Facets on advanced search form
150
149
 
151
- By default, the advanced search form will show as limits whatever facets are configured as default in your Solr request handler. To have the advanced search form request specific facets and/or specific facet parameters, you can set config[:form_solr_parameters].
150
+ By default, the advanced search form will show as limits whatever facets are configured as default in your Solr request handler. To have the advanced search form request specific facets and/or specific facet parameters, you can set config[:form_solr_parameters].
152
151
 
153
152
  config.advanced_search = {
154
153
  :form_solr_parameters => {
@@ -158,22 +157,11 @@ By default, the advanced search form will show as limits whatever facets are con
158
157
  }
159
158
  }
160
159
 
161
- Multiply selected advanced search form facets are combined with `or` (ie `any` or `union`).
160
+ Multiply selected advanced search form facets are combined with `or` (ie `any` or `union`).
162
161
 
163
162
  The default advanced search form facet display is very much like Blacklight's
164
163
  sidebar facets (and uses some code straight from BL to render), but with checkboxes
165
- next to each value.
166
-
167
- (IN PROGRESS) An alternate view using a multi-element HTML `select` is available, and can also
168
- be combined with [chosen.js](http://harvesthq.github.io/chosen/) for a fancy type-ahead style of UI.
169
- This can be especially useful if you want to offer many facet values at once on
170
- the form (beware, they are all still loaded in HTML, so this is probably good for
171
- at most hundreds, not thousands.)
172
-
173
- config.advanced_search = {
174
- # ...
175
- :form_facet_partial => "advanced_search_facets_as_select"
176
- }
164
+ next to each value.
177
165
 
178
166
  ### Advanced Search Config Options
179
167
 
@@ -181,30 +169,28 @@ Complete list of keys that can be supplied inside your configure_blacklight `adv
181
169
 
182
170
  * :qt
183
171
  * Solr request handler to use for any search that includes advanced search criteria. Defaults to what the application has set as blacklight_config.default_solr_params[:qt]
184
- * :url_key
185
- * Key to use in application URLs to indicate advanced search is included in a query, defaults to "advanced". URLs will have "&search_field=[url key]".
186
- * :form_solr_paramters
187
- * A hash of solr parameters which will be included in Solr request sent before display of advanced search form. Can be used to set facet parameters for advanced search form display.
172
+ * :form_solr_parameters
173
+ * A hash of solr parameters which will be included in Solr request sent before display of advanced search form. Can be used to set facet parameters for advanced search form display.
188
174
  * :query_parser
189
- * advanced searches are translated to solr nested queries, where the inner queries are of a dismax-type.
190
- By default, they are actually specifically 'dismax', but you can set :query_parser to 'edismax' instead.
175
+ * advanced searches are translated to solr nested queries, where the inner queries are of a dismax-type.
176
+ By default, they are actually specifically 'dismax', but you can set :query_parser to 'edismax' instead.
191
177
  This may make additional features available like * wildcards in advanced searches; but it may also
192
178
  cause some user query elements to be interpreted as operators for edismax when they
193
- were intended as literals. Somewhat experimental. See Github issues #11 and #14.
179
+ were intended as literals. Somewhat experimental. See Github issues #11 and #14.
194
180
 
195
181
  ## Customizing the advanced search form
196
182
 
197
183
  Most of the labels on the advanced search form are [provided via Rails i18n](./config/locales), and can
198
- be customized in a local app i18n file.
184
+ be customized in a local app i18n file.
199
185
 
200
- Additionally, you can override the templates from this gem used to display the form.
186
+ Additionally, you can override the templates from this gem used to display the form.
201
187
  We've tried to break it up into partials at the right granularity for over-riding
202
188
  in likely ways. For one example, see the wiki page on [Adding a range limit to the advanced search form](https://github.com/projectblacklight/blacklight_advanced_search/wiki/Adding-a-range-limit-to-the-advanced-search-form).
203
189
 
204
190
 
205
191
  ## Translation to Solr Query, technical details
206
192
 
207
- The code for mapping a user-entered query to a Solr query is called "nesting_parsing", and maps to a 'lucene' query parser query, with nested 'dismax' query parser queries.
193
+ The code for mapping a user-entered query to a Solr query is called "nesting_parsing", and maps to a 'lucene' query parser query, with nested 'dismax' query parser queries.
208
194
 
209
195
  Some technical details can be found in the nesting_parsing README: [https://github.com/projectblacklight/blacklight_advanced_search/tree/master/lib/parsing_nesting]
210
196
 
@@ -212,17 +198,17 @@ You may also find the rspecs for parsing a user-entered query and converting it
212
198
 
213
199
  1. Converting user-entered query to Solr: [https://github.com/projectblacklight/blacklight_advanced_search/blob/master/spec/parsing_nesting/to_solr_spec.rb]
214
200
  2. Parsing user-entered query to internal syntax tree: [https://github.com/projectblacklight/blacklight_advanced_search/blob/master/spec/parsing_nesting/build_tree_spec.rb]
215
-
201
+
216
202
  ## Running tests
217
203
 
218
204
 
219
205
  (Limited) test coverage is provided with rspec, run all tests (and start the jetty instance) by running:
220
- rake ci
206
+ rake ci
207
+
208
+ from the blacklight_advanced_search directory. Note: you may need to `bundle install` first.
221
209
 
222
- from the blacklight_advanced_search directory. Note: you may need to `bundle install` first.
223
210
 
224
-
225
211
  ## To Do
226
212
 
227
- * Alphabetical sorting of facet values returned by solr in count order (perhaps with limit).
228
- * Parse for fielded search too like << title:"some title" >>. 'field:' that doesn't match an actual known field should be passed through same as now, while recognized fields should generate nested queries tied to those blacklight search types.
213
+ * Alphabetical sorting of facet values returned by solr in count order (perhaps with limit).
214
+ * Parse for fielded search too like << title:"some title" >>. 'field:' that doesn't match an actual known field should be passed through same as now, while recognized fields should generate nested queries tied to those blacklight search types.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0
1
+ 8.0.0.alpha1
@@ -16,15 +16,16 @@ Gem::Specification.new do |s|
16
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_dependency 'blacklight', '~> 7.0'
19
+ s.add_dependency 'blacklight', '>= 7.15', '< 9'
20
20
  s.add_dependency "parslet"
21
21
 
22
22
  s.add_development_dependency "rails"
23
- s.add_development_dependency "rspec-rails", "~> 3.0"
23
+ s.add_development_dependency "rspec-rails", "~> 5.0"
24
24
  s.add_development_dependency "capybara"
25
25
  s.add_development_dependency 'solr_wrapper'
26
26
  s.add_development_dependency 'engine_cart', "~> 2.0"
27
27
  s.add_development_dependency 'rubocop'
28
+ s.add_development_dependency 'rubocop-rails'
28
29
  s.add_development_dependency 'rubocop-rspec'
29
30
  s.add_development_dependency 'rsolr'
30
31
  end
data/config/routes.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  BlacklightAdvancedSearch::Engine.routes.draw do
2
- get 'advanced' => 'advanced#index', as: 'advanced_search'
2
+ get 'advanced' => 'catalog#advanced_search', as: 'advanced_search'
3
3
  end
@@ -1,3 +1,5 @@
1
+ require 'parsing_nesting/tree'
2
+
1
3
  module BlacklightAdvancedSearch
2
4
  # Can extract query elements from rails #params query params, and then parse
3
5
  # them and convert them into a solr query with #to_solr
@@ -5,66 +7,50 @@ module BlacklightAdvancedSearch
5
7
  # #keyword_queries and #filters, which just return extracted elements of query
6
8
  # params, may also be useful in display etc.
7
9
  class QueryParser
8
- include ParsingNestingParser # only one strategy currently supported. if BlacklightAdvancedSearch.config[:solr_type] == "parsing_nesting"
9
- include FilterParser
10
- attr_reader :config, :params
10
+ attr_reader :config, :search_state
11
11
 
12
- def initialize(params, config)
13
- @params = Blacklight::SearchState.new(params, config).to_h
12
+ def initialize(search_state, config)
13
+ @search_state = search_state
14
14
  @config = config
15
15
  end
16
16
 
17
17
  def to_solr
18
18
  @to_solr ||= begin
19
19
  {
20
- :q => process_query(params, config),
21
- :fq => generate_solr_fq
20
+ q: process_query(config)
22
21
  }
23
22
  end
24
23
  end
25
24
 
26
25
  # Returns "AND" or "OR", how #keyword_queries will be combined
27
26
  def keyword_op
28
- @params["op"] || "AND"
27
+ op = search_state.params[:op]&.to_sym || :must
28
+
29
+ if op == :should
30
+ 'OR'
31
+ else
32
+ 'AND'
33
+ end
29
34
  end
30
35
 
31
- # extracts advanced-type keyword query elements from query params,
32
- # returns as a kash of field => query.
33
- # see also keyword_op
34
36
  def keyword_queries
35
- unless @keyword_queries
36
- @keyword_queries = {}
37
-
38
- return @keyword_queries unless @params[:search_field] == ::AdvancedController.blacklight_config.advanced_search[:url_key]
39
-
40
- config.search_fields.each do |key, _field_def|
41
- unless @params[key.to_sym].blank?
42
- @keyword_queries[key] = @params[key.to_sym]
43
- end
44
- end
45
- end
46
- @keyword_queries
37
+ search_state.clause_params.values.select { |clause| clause[:query].present? }
47
38
  end
48
39
 
49
- # extracts advanced-type filters from query params,
50
- # returned as a hash of field => [array of values]
51
- def filters
52
- unless @filters
53
- @filters = {}
54
- return @filters unless @params[:f_inclusive] && @params[:f_inclusive].respond_to?(:each_pair)
55
- @params[:f_inclusive].each_pair do |field, value_array|
56
- @filters[field] ||= value_array.dup
57
- end
40
+ def process_query(config)
41
+ queries = keyword_queries.map do |clause|
42
+ field = clause[:field]
43
+ query = clause[:query]
44
+
45
+ ParsingNesting::Tree.parse(query, config.advanced_search[:query_parser]).to_query(local_param_hash(field, config))
58
46
  end
59
- @filters
47
+ queries.join(" #{keyword_op} ")
60
48
  end
61
49
 
62
- def filters_include_value?(field, value)
63
- filters[field.to_s].try { |array| array.include? value }
64
- end
50
+ def local_param_hash(key, config)
51
+ field_def = config.search_fields[key] || {}
65
52
 
66
- def empty?
67
- filters.empty? && keyword_queries.empty?
53
+ (field_def[:solr_adv_parameters] || field_def[:solr_parameters] || {}).merge(field_def[:solr_local_parameters] || {})
68
54
  end
69
55
  end
70
56
  end
@@ -2,36 +2,37 @@ require 'parslet'
2
2
  require 'parsing_nesting/tree'
3
3
  module BlacklightAdvancedSearch
4
4
  module AdvancedSearchBuilder
5
- include Blacklight::SearchFields
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ self.default_processor_chain += [
9
+ :facets_for_advanced_search_form
10
+ ]
11
+ end
6
12
 
7
13
  def is_advanced_search?
8
- (self.blacklight_config.advanced_search && blacklight_params[:search_field] == self.blacklight_config.advanced_search[:url_key]) || blacklight_params[:f_inclusive]
14
+ search_state.clause_params.any?
9
15
  end
10
16
 
11
- # this method should get added into the processor chain
12
- # in a position AFTER normal query handling (:add_query_to_solr),
13
- # so it'll overwrite that if and only if it's an advanced search.
14
- # adds a 'q' and 'fq's based on advanced search form input.
15
- def add_advanced_search_to_solr(solr_parameters)
17
+ # Override the upstream adv. search implementation to use our own
18
+ def add_adv_search_clauses(solr_parameters)
19
+ return unless is_advanced_search?
16
20
  # If we've got the hint that we're doing an 'advanced' search, then
17
21
  # map that to solr #q, over-riding whatever some other logic may have set, yeah.
18
- # the hint right now is :search_field request param is set to a magic
19
- # key. OR of :f_inclusive is set for advanced params, we need processing too.
20
- if is_advanced_search?
21
- # Set this as a controller instance variable, not sure if some views/helpers depend on it. Better to leave it as a local variable
22
- # if not, more investigation later.
23
- advanced_query = BlacklightAdvancedSearch::QueryParser.new(blacklight_params, self.blacklight_config)
24
- BlacklightAdvancedSearch.deep_merge!(solr_parameters, advanced_query.to_solr)
25
- unless advanced_query.keyword_queries.empty?
26
- # force :qt if set, fine if it's nil, we'll use whatever CatalogController
27
- # ordinarily uses.
28
- solr_parameters[:qt] = self.blacklight_config.advanced_search[:qt]
29
- solr_parameters[:defType] = "lucene"
30
- end
31
-
22
+ advanced_query = BlacklightAdvancedSearch::QueryParser.new(search_state, blacklight_config)
23
+ BlacklightAdvancedSearch.deep_merge!(solr_parameters, advanced_query.to_solr)
24
+ unless advanced_query.keyword_queries.empty?
25
+ # force :qt if set, fine if it's nil, we'll use whatever CatalogController
26
+ # ordinarily uses.
27
+ solr_parameters[:qt] = self.blacklight_config.advanced_search[:qt]
28
+ solr_parameters[:defType] = "lucene"
32
29
  end
33
30
  end
34
31
 
32
+ # this method is left for backwards compatibility.
33
+ def add_advanced_search_to_solr(solr_parameters)
34
+ end
35
+
35
36
  # Different versions of Parslet raise different exception classes,
36
37
  # need to figure out which one exists to rescue
37
38
  PARSLET_FAILED_EXCEPTIONS = if defined? Parslet::UnconsumedInput
@@ -51,7 +52,7 @@ module BlacklightAdvancedSearch
51
52
  return if blacklight_params[:q].blank? || !blacklight_params[:q].respond_to?(:to_str)
52
53
 
53
54
  field_def = blacklight_config.search_fields[blacklight_params[:search_field]] ||
54
- default_search_field
55
+ blacklight_config.default_search_field
55
56
 
56
57
  # If the individual field has advanced_parse_q suppressed, punt
57
58
  return if field_def[:advanced_parse] == false
@@ -75,12 +76,14 @@ module BlacklightAdvancedSearch
75
76
  end
76
77
 
77
78
  # A Solr param filter that is NOT included by default in the chain,
78
- # but is appended by AdvancedController#index, to do a search
79
+ # but is appended for advanced searches, to do a search
79
80
  # for facets _ignoring_ the current query, we want the facets
80
81
  # as if the current query weren't there.
81
82
  #
82
83
  # Also adds any solr params set in blacklight_config.advanced_search[:form_solr_parameters]
83
84
  def facets_for_advanced_search_form(solr_p)
85
+ return unless search_state.controller&.action_name == "advanced_search"
86
+
84
87
  # ensure empty query is all records, to fetch available facets on entire corpus
85
88
  solr_p["q"] = '{!lucene}*:*'
86
89
  # explicitly use lucene defType since we are passing a lucene query above (and appears to be required for solr 7)
@@ -1,23 +1,22 @@
1
- require 'blacklight_advanced_search/parsing_nesting_parser'
2
-
3
1
  # This module gets included into CatalogController, or another SearchHelper
4
- # includer, to add advanced search behavior
2
+ # includer, to override
5
3
  module BlacklightAdvancedSearch::Controller
6
- extend ActiveSupport::Concern
4
+ if Blacklight::VERSION < '7.27'
5
+ # before Blacklight 7.27, the provided search service didn't receive this controller
6
+ def advanced_search
7
+ (@response, _deprecated_document_list) = blacklight_advanced_search_form_search_service.search_results
8
+ end
7
9
 
8
- included do
9
- # Display advanced search constraints properly
10
- helper BlacklightAdvancedSearch::RenderConstraintsOverride
11
- helper BlacklightAdvancedSearch::CatalogHelperOverride
12
- helper_method :is_advanced_search?, :advanced_query
13
- end
10
+ private
14
11
 
15
- def is_advanced_search?(req_params = params)
16
- (req_params[:search_field] == blacklight_config.advanced_search[:url_key]) ||
17
- req_params[:f_inclusive]
18
- end
12
+ def blacklight_advanced_search_form_search_service
13
+ form_search_state = search_state_class.new(blacklight_advanced_search_form_params, blacklight_config, self)
14
+
15
+ search_service_class.new(config: blacklight_config, search_state: form_search_state, user_params: form_search_state.to_h, **search_service_context)
16
+ end
19
17
 
20
- def advanced_query
21
- BlacklightAdvancedSearch::QueryParser.new(params, blacklight_config) if is_advanced_search?
18
+ def blacklight_advanced_search_form_params
19
+ {}
20
+ end
22
21
  end
23
22
  end