blacklight_advanced_search 5.2.1 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb68c4b7b6f6fbe62c4f6080aeba080f1f28af23
4
- data.tar.gz: dcc1f42eec4a0f45f64de6a5323dd620de0e0f8a
3
+ metadata.gz: 172b0f2d44251a5f580647cb4a13e9668ee5a45f
4
+ data.tar.gz: a03b5a8d9f1b4af69501a2982a63d5ccce7bdb43
5
5
  SHA512:
6
- metadata.gz: 71a9e1063c93f5daab27648cc616d892642d1560db2158f1f1a2585542db96adf7602159c81c7658c8f258d35fc3748564c741484941713f32841a02cdd23784
7
- data.tar.gz: 63a3c3aeba623484f6935a9c4faac5b99f104f5177633ad071f3e5cf508b1a8a8d6c9be6a31e8573040fc8fca0a201fe1b6ced03816d61f021112525833885d5
6
+ metadata.gz: b662d7d13d678ce82adbbdea4e0dc141a536b1f210f46895c846f7e7cbed338a55e88eb4762bf81d08b18ab019ab4aa2bc283d5a38744cbe197ed4daa8e70e6b
7
+ data.tar.gz: f5b1d3ec51e22e2754bbc80be9447141a1e24bfbdf8a31c88783d78b42dc759ec8626e89b26de5c1238fa738b92742092c9b38f3c758f5554cbf8c4bf8efe052
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.2.1
1
+ 5.3.0
@@ -35,7 +35,7 @@ module BlacklightAdvancedSearch
35
35
 
36
36
  # Different versions of Parslet raise different exception classes,
37
37
  # need to figure out which one exists to rescue
38
- @@parslet_failed_exceptions = if defined? Parslet::UnconsumedInput
38
+ PARSLET_FAILED_EXCEPTIONS = if defined? Parslet::UnconsumedInput
39
39
  [Parslet::UnconsumedInput]
40
40
  else
41
41
  [Parslet::ParseFailed]
@@ -50,30 +50,31 @@ module BlacklightAdvancedSearch
50
50
  # parse and send it straight to solr same as if advanced_parse_q
51
51
  # were not being used.
52
52
  def add_advanced_parse_q_to_solr(solr_parameters)
53
- unless scope.params[:q].blank?
54
- field_def = search_field_def_for_key( scope.params[:search_field]) ||
55
- default_search_field
56
-
57
-
58
- # If the individual field has advanced_parse_q suppressed, punt
59
- return if field_def[:advanced_parse] == false
60
-
61
- solr_direct_params = field_def[:solr_parameters] || {}
62
- solr_local_params = field_def[:solr_local_parameters] || {}
63
-
64
- # See if we can parse it, if we can't, we're going to give up
65
- # and just allow basic search, perhaps with a warning.
66
- begin
67
- adv_search_params = ParsingNesting::Tree.parse(scope.params[:q], blacklight_config.advanced_search[:query_parser]).to_single_query_params( solr_local_params )
53
+ blacklight_params = scope.params
68
54
 
69
- BlacklightAdvancedSearch.deep_merge!(solr_parameters, solr_direct_params)
70
- BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
71
- rescue *@@parslet_failed_exceptions => e
72
- # do nothing, don't merge our input in, keep basic search
73
- # optional TODO, display error message in flash here, but hard to
74
- # display a good one.
75
- return
76
- end
55
+ return if blacklight_params[:q].blank? || !blacklight_params[:q].respond_to?(:to_str)
56
+
57
+ field_def = search_field_def_for_key(blacklight_params[:search_field]) ||
58
+ default_search_field
59
+
60
+ # If the individual field has advanced_parse_q suppressed, punt
61
+ return if field_def[:advanced_parse] == false
62
+
63
+ solr_direct_params = field_def[:solr_parameters] || {}
64
+ solr_local_params = field_def[:solr_local_parameters] || {}
65
+
66
+ # See if we can parse it, if we can't, we're going to give up
67
+ # and just allow basic search, perhaps with a warning.
68
+ begin
69
+ adv_search_params = ParsingNesting::Tree.parse(blacklight_params[:q], blacklight_config.advanced_search[:query_parser]).to_single_query_params(solr_local_params)
70
+
71
+ BlacklightAdvancedSearch.deep_merge!(solr_parameters, solr_direct_params)
72
+ BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
73
+ rescue *PARSLET_FAILED_EXCEPTIONS => e
74
+ # do nothing, don't merge our input in, keep basic search
75
+ # optional TODO, display error message in flash here, but hard to
76
+ # display a good one.
77
+ return
77
78
  end
78
79
  end
79
80
 
@@ -23,7 +23,7 @@ module BlacklightAdvancedSearch::ParseBasicQ
23
23
 
24
24
  # Different versions of Parslet raise different exception classes,
25
25
  # need to figure out which one exists to rescue
26
- @@parslet_failed_exceptions = if defined? Parslet::UnconsumedInput
26
+ PARSLET_FAILED_EXCEPTIONS = if defined? Parslet::UnconsumedInput
27
27
  [Parslet::UnconsumedInput]
28
28
  else
29
29
  [Parslet::ParseFailed]
@@ -60,7 +60,7 @@ module BlacklightAdvancedSearch::ParseBasicQ
60
60
 
61
61
  BlacklightAdvancedSearch.deep_merge!(solr_parameters, solr_direct_params)
62
62
  BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
63
- rescue *@@parslet_failed_exceptions => e
63
+ rescue *PARSLET_FAILED_EXCEPTIONS => e
64
64
  # do nothing, don't merge our input in, keep basic search
65
65
  # optional TODO, display error message in flash here, but hard to
66
66
  # display a good one.
@@ -49,6 +49,23 @@ describe BlacklightAdvancedSearch::AdvancedSearchBuilder do
49
49
  obj.add_advanced_parse_q_to_solr(solr_params)
50
50
  expect(solr_params[:q]).to eq(unparseable_q)
51
51
  end
52
+
53
+ describe 'when parslet fails' do
54
+ let(:failing_q) { ")(" }
55
+ let(:params) { double("params", params: { :q => failing_q }) }
56
+ it 'does not return the query that could not be parsed' do
57
+ obj.add_advanced_parse_q_to_solr(solr_params)
58
+ expect(solr_params[:q]).to be_nil
59
+ end
60
+ end
61
+
62
+ describe 'when `q` is a hash' do
63
+ let(:params) { double("params", params: { q: { id: ['a'] } }) }
64
+ it 'does not return the query that could not be parsed' do
65
+ obj.add_advanced_parse_q_to_solr(solr_params)
66
+ expect(solr_params[:q]).to be_nil
67
+ end
68
+ end
52
69
  end
53
70
 
54
71
  context "when advanced_parse is false" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_advanced_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Rochkind
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-05 00:00:00.000000000 Z
12
+ date: 2017-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -196,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
196
  version: '0'
197
197
  requirements: []
198
198
  rubyforge_project: blacklight
199
- rubygems_version: 2.4.5.1
199
+ rubygems_version: 2.6.11
200
200
  signing_key:
201
201
  specification_version: 4
202
202
  summary: Blacklight Advanced Search plugin