blacklight_advanced_search 5.1.0 → 5.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,8 +2,8 @@ notifications:
2
2
  email: false
3
3
 
4
4
  rvm:
5
- - 2.1.0
6
- - 2.0.0
5
+ - 2.1
6
+ - 2.0
7
7
  - 1.9.3
8
8
  - jruby-19mode
9
9
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.0
1
+ 5.1.1
@@ -1,3 +1,6 @@
1
+ require 'parslet'
2
+ require 'parsing_nesting/tree'
3
+
1
4
  # A solr search logic mix-in to CatalogController.
2
5
  # If mixed-in, adds Advanced Search parsing behavior
3
6
  # to queries entered on basic/standard/simple search
@@ -12,6 +15,14 @@ module BlacklightAdvancedSearch::ParseBasicQ
12
15
  included do
13
16
  self.solr_search_params_logic += [:add_advanced_parse_q_to_solr]
14
17
  end
18
+
19
+ # Different versions of Parslet raise different exception classes,
20
+ # need to figure out which one exists to rescue
21
+ @@parslet_failed_exceptions = if defined? Parslet::UnconsumedInput
22
+ [Parslet::UnconsumedInput]
23
+ else
24
+ [Parslet::ParseFailed]
25
+ end
15
26
 
16
27
 
17
28
  # This method can be included in solr_search_params_logic to have us
@@ -41,10 +52,10 @@ module BlacklightAdvancedSearch::ParseBasicQ
41
52
  # and just allow basic search, perhaps with a warning.
42
53
  begin
43
54
  adv_search_params = ParsingNesting::Tree.parse(req_params[:q], blacklight_config.advanced_search[:query_parser]).to_single_query_params( solr_local_params )
44
-
55
+
45
56
  BlacklightAdvancedSearch.deep_merge!(solr_parameters, solr_direct_params)
46
57
  BlacklightAdvancedSearch.deep_merge!(solr_parameters, adv_search_params)
47
- rescue Parslet::UnconsumedInput => e
58
+ rescue *@@parslet_failed_exceptions => e
48
59
  # do nothing, don't merge our input in, keep basic search
49
60
  # optional TODO, display error message in flash here, but hard to
50
61
  # display a good one.
@@ -4,7 +4,7 @@ module BlacklightAdvancedSearch::ParsingNestingParser
4
4
  def process_query(params,config)
5
5
  queries = []
6
6
  keyword_queries.each do |field,query|
7
- queries << ParsingNesting::Tree.parse(query).to_query( local_param_hash(field, config) )
7
+ queries << ParsingNesting::Tree.parse(query, config.advanced_search[:query_parser]).to_query( local_param_hash(field, config) )
8
8
  end
9
9
  queries.join( ' ' + keyword_op + ' ')
10
10
  end
@@ -0,0 +1,85 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "NestingParser" do
4
+
5
+ # Our ParseBasicQ mixin assumes a SolrHelper context.
6
+ # SolrHelper is a controller layer mixin, which depends
7
+ # on being mixed into a class which has #params (from Rails)
8
+ # and #blacklight_config
9
+ #
10
+ # This technique of testing is copied from Blacklight solr_helper_spec.rb
11
+ #
12
+ # It gets kind of a mess of dependencies, sorry.
13
+ class ParseBasicQTestClass
14
+ cattr_accessor :blacklight_config
15
+ cattr_accessor :blacklight_solr
16
+
17
+ include Blacklight::SolrHelper
18
+
19
+ include BlacklightAdvancedSearch::ParseBasicQ
20
+
21
+
22
+ def initialize blacklight_config, blacklight_solr
23
+ self.blacklight_config = blacklight_config
24
+ self.blacklight_solr = blacklight_solr
25
+ end
26
+
27
+ def params
28
+ {}
29
+ end
30
+
31
+ def logger
32
+ Rails.logger
33
+ end
34
+ end
35
+
36
+ describe "basic functionality" do
37
+ before do
38
+ @blacklight_config = Blacklight::Configuration.new do |config|
39
+ config.advanced_search = {
40
+
41
+ }
42
+
43
+ config.add_search_field "all_fields" do |field|
44
+
45
+ end
46
+
47
+ config.add_search_field "special_field" do |field|
48
+ field.advanced_parse = false
49
+ end
50
+ end
51
+ @obj = ParseBasicQTestClass.new @blacklight_config, Blacklight.solr
52
+ end
53
+
54
+ it "catches a simple example" do
55
+ solr_params = {}
56
+ @obj.add_advanced_parse_q_to_solr(solr_params, :q => "one two AND three OR four")
57
+
58
+ expect(solr_params[:defType]).to eq("lucene")
59
+ # We're not testing succesful parsing here, just that it's doing
60
+ # something that looks like we expect with subqueries.
61
+ expect(solr_params[:q]).to start_with("_query_:")
62
+ end
63
+
64
+ it "passes through an unparseable example" do
65
+ solr_params = {}
66
+ unparseable_q = "foo bar\'s AND"
67
+ @obj.add_advanced_parse_q_to_solr(solr_params, :q => unparseable_q)
68
+
69
+ expect(solr_params[:q]).to eq(unparseable_q)
70
+ end
71
+
72
+ it "ignores field with advanced_parse=false" do
73
+ solr_params = {}
74
+ original_q = "one two AND three OR four"
75
+ @obj.add_advanced_parse_q_to_solr(solr_params,
76
+ :search_field => "special_field",
77
+ :q => original_q
78
+ )
79
+
80
+ expect(solr_params).not_to have_key(:q)
81
+ end
82
+
83
+ end
84
+
85
+ end
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.0
4
+ version: 5.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-06-05 00:00:00.000000000 Z
13
+ date: 2014-08-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: blacklight
@@ -187,6 +187,7 @@ files:
187
187
  - spec/lib/filter_parser_spec.rb
188
188
  - spec/parsing_nesting/build_tree_spec.rb
189
189
  - spec/parsing_nesting/consuming_spec.rb
190
+ - spec/parsing_nesting/parse_basic_q_spec.rb
190
191
  - spec/parsing_nesting/to_solr_spec.rb
191
192
  - spec/rcov.opts
192
193
  - spec/spec.opts
@@ -209,7 +210,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
210
  version: '0'
210
211
  segments:
211
212
  - 0
212
- hash: 816155266112980095
213
+ hash: 378368463660479159
213
214
  required_rubygems_version: !ruby/object:Gem::Requirement
214
215
  none: false
215
216
  requirements:
@@ -218,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
218
219
  version: '0'
219
220
  segments:
220
221
  - 0
221
- hash: 816155266112980095
222
+ hash: 378368463660479159
222
223
  requirements: []
223
224
  rubyforge_project: blacklight
224
225
  rubygems_version: 1.8.23
@@ -232,6 +233,7 @@ test_files:
232
233
  - spec/lib/filter_parser_spec.rb
233
234
  - spec/parsing_nesting/build_tree_spec.rb
234
235
  - spec/parsing_nesting/consuming_spec.rb
236
+ - spec/parsing_nesting/parse_basic_q_spec.rb
235
237
  - spec/parsing_nesting/to_solr_spec.rb
236
238
  - spec/rcov.opts
237
239
  - spec/spec.opts