blacklight_advanced_search 5.1.3 → 5.1.4

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: bff9b8e310bf1d4bc8712103ef0d4c3887662ebc
4
- data.tar.gz: dde5a134cceff1ff2c419f28fdf5c17760b55186
3
+ metadata.gz: ff76b283a42b92cb447e1a22d9c1db3e06f9663e
4
+ data.tar.gz: b53695523cade9db3640aa233ef422ea90c1428b
5
5
  SHA512:
6
- metadata.gz: c60a43939cf1b6f6acd6491b578d4d60dd4c2896261cd268284822e5b89eaec1f298d94aac23d32a87773f9430a2a98f20ac499277a38b62a1349446c54356da
7
- data.tar.gz: 6a63d2ef79e82bd6184cac02a67008f2bf3fdf8301b952f66f6e1141422de6e1fae13e3736eafc87eb4deb6a768447b658e6a08f4ce03b27a46a94d972489462
6
+ metadata.gz: 29dd20956b18315dac983e2757cec1f9571c53e91c9530fad07a66e40c02d3f02fdff9036124fb33c9995c38cef82f67ac1bb6dfcb55c82c3b36e87c98ce63db
7
+ data.tar.gz: 0114f011d414f3900857f052530880a41faa2e592a313a4ba430743a24cd922fcad9b9a84010e2ecb43fc2c9247d18fb881ad807bd06044de4ac9c779d601c0c
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.3
1
+ 5.1.4
@@ -1,5 +1,10 @@
1
+ require 'parslet'
2
+ require 'parsing_nesting/tree'
1
3
  module BlacklightAdvancedSearch
2
4
  module AdvancedSearchBuilder
5
+
6
+ include Blacklight::SearchFields
7
+
3
8
  def is_advanced_search?
4
9
  (blacklight_params[:search_field] == self.blacklight_config.advanced_search[:url_key]) || blacklight_params[:f_inclusive]
5
10
  end
@@ -27,5 +32,49 @@ module BlacklightAdvancedSearch
27
32
 
28
33
  end
29
34
  end
35
+
36
+ # Different versions of Parslet raise different exception classes,
37
+ # need to figure out which one exists to rescue
38
+ @@parslet_failed_exceptions = if defined? Parslet::UnconsumedInput
39
+ [Parslet::UnconsumedInput]
40
+ else
41
+ [Parslet::ParseFailed]
42
+ end
43
+
44
+
45
+ # This method can be included in search_params_logic to have us
46
+ # parse an ordinary entered :q for AND/OR/NOT and produce appropriate
47
+ # Solr query.
48
+ #
49
+ # Note: For syntactically invalid input, we'll just skip the adv
50
+ # parse and send it straight to solr same as if advanced_parse_q
51
+ # were not being used.
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 )
68
+
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
77
+ end
78
+ end
30
79
  end
31
80
  end
@@ -11,6 +11,9 @@ require 'parsing_nesting/tree'
11
11
  # in your CatalogController
12
12
  module BlacklightAdvancedSearch::ParseBasicQ
13
13
  extend ActiveSupport::Concern
14
+ extend Deprecation
15
+
16
+ self.deprecation_horizon = 'blacklight_advanced_search 6.0'
14
17
 
15
18
  include Blacklight::SearchFields
16
19
 
@@ -65,5 +68,6 @@ module BlacklightAdvancedSearch::ParseBasicQ
65
68
  end
66
69
  end
67
70
  end
71
+ deprecation_deprecate add_advanced_parse_q_to_solr: "use AdvancedSearchBuilder.add_advanced_parse_q_to_solr"
68
72
 
69
73
  end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe BlacklightAdvancedSearch::AdvancedSearchBuilder do
4
+
5
+ describe "#add_advanced_parse_q_to_solr" do
6
+
7
+ let(:blacklight_config) do
8
+ Blacklight::Configuration.new do |config|
9
+ config.advanced_search = { }
10
+ config.add_search_field "all_fields"
11
+ config.add_search_field "special_field" do |field|
12
+ field.advanced_parse = false
13
+ end
14
+ end
15
+ end
16
+
17
+ let!(:obj) do
18
+ class BACTestClass
19
+ cattr_accessor :blacklight_config
20
+ include Blacklight::SearchHelper
21
+ include BlacklightAdvancedSearch::AdvancedSearchBuilder
22
+ def initialize blacklight_config
23
+ self.blacklight_config = blacklight_config
24
+ end
25
+ end
26
+ BACTestClass.new blacklight_config
27
+ end
28
+
29
+ context "with basic functionality" do
30
+ let(:solr_params) { {} }
31
+
32
+ describe "a simple example" do
33
+ let(:params) { double("params", params: {:q => "one two AND three OR four"} ) }
34
+ before { allow(obj).to receive(:scope).and_return(params) }
35
+ it "catches the query" do
36
+ obj.add_advanced_parse_q_to_solr(solr_params)
37
+ expect(solr_params[:defType]).to eq("lucene")
38
+ # We're not testing succesful parsing here, just that it's doing
39
+ # something that looks like we expect with subqueries.
40
+ expect(solr_params[:q]).to start_with("_query_:")
41
+ end
42
+ end
43
+
44
+ describe "an unparseable example" do
45
+ let(:unparseable_q) { "foo bar\'s AND" }
46
+ let(:params) { double("params", params: {:q => unparseable_q} ) }
47
+ before { allow(obj).to receive(:scope).and_return(params) }
48
+ it "passes through" do
49
+ obj.add_advanced_parse_q_to_solr(solr_params)
50
+ expect(solr_params[:q]).to eq(unparseable_q)
51
+ end
52
+ end
53
+
54
+ context "when advanced_parse is false" do
55
+ let(:params) { double("params", params: { :search_field => "special_field", :q => "one two AND three OR four" } ) }
56
+ before { allow(obj).to receive(:scope).and_return(params) }
57
+ it "ignores fields" do
58
+ obj.add_advanced_parse_q_to_solr(solr_params)
59
+ expect(solr_params).not_to have_key(:q)
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ end
@@ -32,7 +32,7 @@ describe "NestingParser" do
32
32
  end
33
33
 
34
34
  describe "basic functionality" do
35
- before do
35
+ before do
36
36
  @blacklight_config = Blacklight::Configuration.new do |config|
37
37
  config.advanced_search = {
38
38
 
@@ -50,6 +50,7 @@ describe "NestingParser" do
50
50
  end
51
51
 
52
52
  it "catches a simple example" do
53
+ expect(Deprecation).to receive(:warn)
53
54
  solr_params = {}
54
55
  @obj.add_advanced_parse_q_to_solr(solr_params, :q => "one two AND three OR four")
55
56
 
@@ -60,6 +61,7 @@ describe "NestingParser" do
60
61
  end
61
62
 
62
63
  it "passes through an unparseable example" do
64
+ expect(Deprecation).to receive(:warn)
63
65
  solr_params = {}
64
66
  unparseable_q = "foo bar\'s AND"
65
67
  @obj.add_advanced_parse_q_to_solr(solr_params, :q => unparseable_q)
@@ -68,6 +70,7 @@ describe "NestingParser" do
68
70
  end
69
71
 
70
72
  it "ignores field with advanced_parse=false" do
73
+ expect(Deprecation).to receive(:warn)
71
74
  solr_params = {}
72
75
  original_q = "one two AND three OR four"
73
76
  @obj.add_advanced_parse_q_to_solr(solr_params,
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.1.3
4
+ version: 5.1.4
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-03-13 00:00:00.000000000 Z
12
+ date: 2015-03-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight
@@ -165,6 +165,7 @@ files:
165
165
  - spec/features/blacklight_advanced_search_form_spec.rb
166
166
  - spec/helpers/advanced_helper_spec.rb
167
167
  - spec/integration/blacklight_stub_spec.rb
168
+ - spec/lib/advanced_search_builder_spec.rb
168
169
  - spec/lib/deep_merge_spec.rb
169
170
  - spec/lib/filter_parser_spec.rb
170
171
  - spec/parsing_nesting/build_tree_spec.rb
@@ -203,6 +204,7 @@ test_files:
203
204
  - spec/features/blacklight_advanced_search_form_spec.rb
204
205
  - spec/helpers/advanced_helper_spec.rb
205
206
  - spec/integration/blacklight_stub_spec.rb
207
+ - spec/lib/advanced_search_builder_spec.rb
206
208
  - spec/lib/deep_merge_spec.rb
207
209
  - spec/lib/filter_parser_spec.rb
208
210
  - spec/parsing_nesting/build_tree_spec.rb