blacklight_range_limit 5.1.0 → 5.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3332162f26f3c37988434d3f9f5cfcf4ad3f8ac
4
- data.tar.gz: 1b58632167c84866a291472c294540977417fce6
3
+ metadata.gz: 370e3efeb2a4d7b7256ed5110183816b00291c7a
4
+ data.tar.gz: a483e4d5767c82b12ba43445bf9d071ef318210d
5
5
  SHA512:
6
- metadata.gz: 8cae1eb92de55315ef2318ce89029b2bb70bcb2bcdea411b6adc5a94470fceadd6d3d3be551f0af364710ed01aab5125a7561a4d4a3c49ddabfdf422f8895005
7
- data.tar.gz: 7f2356c2213b6c1bf522f9ad7e7c555a497c44a187d50c8e185fc07c0bc6f178d23a8e22521bcbca31e7a2ca033f8843b67fb3e53ed07c7b3a9be4fe4b31b713
6
+ metadata.gz: 280bc39080fd5ec46d354422505ea09a2dec4a978f2ef8e6aef7ece8d4e974250aea22e412b9f91378b6a978132c6bb7d76cd98cb136186720a454daaaf99521
7
+ data.tar.gz: 5b393841ea0a2c52452b75b84d0bd4f5c5f69bc2846f652877054bd49f94027930ce59d30b98d4bf638312c0041292460968a7b441b193d76ea5d68e0b848e91
data/.travis.yml CHANGED
@@ -2,13 +2,17 @@ notifications:
2
2
  email: false
3
3
 
4
4
  language: ruby
5
- cache: bundler
6
5
  sudo: false
7
6
  rvm:
8
- - 1.9.3
9
- - 2.0.0
7
+ - 2.2.2
8
+
9
+ before_install:
10
+ - gem install bundler
10
11
 
11
12
  notifications:
12
13
  irc: "irc.freenode.org#blacklight"
13
14
  email:
14
15
  - blacklight-commits@googlegroups.com
16
+
17
+ global_env:
18
+ - NOKOGIRI_USE_SYSTEM_LIBRARIES=true
data/Gemfile CHANGED
@@ -16,3 +16,10 @@ else
16
16
  gem 'sass-rails', "< 5.0"
17
17
  end
18
18
  end
19
+
20
+ # I'm sorry, this is harsh and I think ought to be done some other way with
21
+ # engine_cart, but I don't understand how or what's going on, and this
22
+ # is all I could to avoid:
23
+ # undefined method `type' for .focus:Sass::Selector::Class
24
+ # (in .../blacklight_range_limit/spec/internal/app/assets/stylesheets/blacklight.css.scss)
25
+ gem 'sass', "~> 3.4"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.1.0
1
+ 5.2.0
@@ -18,10 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.license = "Apache 2.0"
19
19
 
20
20
  s.add_dependency "rails", ">= 3.0", "< 5.0"
21
- s.add_dependency "jquery-rails" # our JS needs jquery_rails
22
- # for blacklight, we want to allow 5.0.0.preX, as well as all 5.x.y,
23
- # but not 6. can't seem to make it do so other than this:
24
- s.add_dependency "blacklight", ">= 5.0.0.pre4", "< 6"
21
+ s.add_dependency "jquery-rails" # our JS needs jquery_rails
22
+ s.add_dependency "blacklight", "~> 5.15"
25
23
 
26
24
  s.add_development_dependency "rspec", "~> 3.0"
27
25
  s.add_development_dependency "rspec-rails"
@@ -1,9 +1,10 @@
1
1
  # BlacklightRangeLimit
2
2
 
3
3
  module BlacklightRangeLimit
4
- autoload :ControllerOverride, 'blacklight_range_limit/controller_override'
5
- autoload :ViewHelperOverride, 'blacklight_range_limit/view_helper_override'
6
- autoload :RouteSets, 'blacklight_range_limit/route_sets'
4
+ require 'blacklight_range_limit/range_limit_builder'
5
+ require 'blacklight_range_limit/controller_override'
6
+ require 'blacklight_range_limit/view_helper_override'
7
+ require 'blacklight_range_limit/route_sets'
7
8
 
8
9
  require 'blacklight_range_limit/version'
9
10
  require 'blacklight_range_limit/engine'
@@ -51,5 +52,23 @@ module BlacklightRangeLimit
51
52
  def self.safe_arr_add(array, element)
52
53
  array << element unless array.include?(element)
53
54
  end
55
+
56
+ # Convenience method for returning range config hash from
57
+ # blacklight config, for a specific solr field, in a normalized
58
+ # way.
59
+ #
60
+ # Returns false if range limiting not configured.
61
+ # Returns hash even if configured to 'true'
62
+ # for consistency.
63
+ def self.range_config(blacklight_config, solr_field)
64
+ field = blacklight_config.facet_fields[solr_field.to_s]
65
+
66
+ return false unless field.range
67
+
68
+ config = field.range
69
+ config = {} if config === true
70
+
71
+ config
72
+ end
54
73
 
55
74
  end
@@ -4,19 +4,25 @@
4
4
  require 'blacklight_range_limit/segment_calculation'
5
5
  module BlacklightRangeLimit
6
6
  module ControllerOverride
7
- include SegmentCalculation
8
7
  extend ActiveSupport::Concern
9
8
 
10
- included do
11
- solr_search_params_logic << :add_range_limit_params
12
- helper_method :range_config
13
-
14
-
15
-
9
+ included do
16
10
  unless BlacklightRangeLimit.omit_inject[:view_helpers]
17
11
  helper BlacklightRangeLimit::ViewHelperOverride
18
12
  helper RangeLimitHelper
19
13
  end
14
+
15
+ if self.respond_to? :search_params_logic
16
+ search_params_logic << :add_range_limit_params
17
+ end
18
+ if self.blacklight_config.search_builder_class
19
+ unless self.blacklight_config.search_builder_class.include?(BlacklightRangeLimit::RangeLimitBuilder)
20
+ self.blacklight_config.search_builder_class.send(:include,
21
+ BlacklightRangeLimit::RangeLimitBuilder
22
+ )
23
+ self.blacklight_config.search_builder_class.default_processor_chain << :add_range_limit_params
24
+ end
25
+ end
20
26
  end
21
27
 
22
28
  # Action method of our own!
@@ -24,88 +30,17 @@ module BlacklightRangeLimit
24
30
  # Used when we need a second Solr query to get range facets, after the
25
31
  # first found min/max from result set.
26
32
  def range_limit
27
- solr_field = params[:range_field] # what field to fetch for
28
- start = params[:range_start].to_i
29
- finish = params[:range_end].to_i
30
-
31
- solr_params = solr_search_params(params)
32
-
33
- # Remove all field faceting for efficiency, we won't be using it.
34
- solr_params.delete("facet.field")
35
- solr_params.delete("facet.field".to_sym)
36
-
37
- add_range_segments_to_solr!(solr_params, solr_field, start, finish )
38
- # We don't need any actual rows or facets, we're just going to look
39
- # at the facet.query's
40
- solr_params[:rows] = 0
41
- solr_params[:facets] = nil
42
- solr_params[:qt] ||= blacklight_config.qt
43
- # Not really any good way to turn off facet.field's from the solr default,
44
- # no big deal it should be well-cached at this point.
45
-
46
- @response = Blacklight.default_index.connection.get( blacklight_config.solr_path, :params => solr_params )
33
+ # We need to swap out the add_range_limit_params search param filter,
34
+ # and instead add in our fetch_specific_range_limit filter,
35
+ # to fetch only the range limit segments for only specific
36
+ # field (with start/end params) mentioned in query params
37
+ # range_field, range_start, and range_end
47
38
 
48
- render('blacklight_range_limit/range_segments', :locals => {:solr_field => solr_field}, :layout => !request.xhr?)
49
- end
50
-
51
- # Method added to solr_search_params_logic to fetch
52
- # proper things for date ranges.
53
- def add_range_limit_params(solr_params, req_params)
54
- ranged_facet_configs =
55
- blacklight_config.facet_fields.select { |key, config| config.range }
56
- # In ruby 1.8, hash.select returns an array of pairs, in ruby 1.9
57
- # it returns a hash. Turn it into a hash either way.
58
- ranged_facet_configs = Hash[ ranged_facet_configs ] unless ranged_facet_configs.kind_of?(Hash)
59
-
60
- ranged_facet_configs.each_pair do |solr_field, config|
61
- solr_params["stats"] = "true"
62
- solr_params["stats.field"] ||= []
63
- solr_params["stats.field"] << solr_field
64
-
65
- hash = req_params["range"] && req_params["range"][solr_field] ?
66
- req_params["range"][solr_field] :
67
- {}
68
-
69
- if !hash["missing"].blank?
70
- # missing specified in request params
71
- solr_params[:fq] ||= []
72
- solr_params[:fq] << "-#{solr_field}:[* TO *]"
73
-
74
- elsif !(hash["begin"].blank? && hash["end"].blank?)
75
- # specified in request params, begin and/or end, might just have one
76
- start = hash["begin"].blank? ? "*" : hash["begin"]
77
- finish = hash["end"].blank? ? "*" : hash["end"]
78
-
79
- solr_params[:fq] ||= []
80
- solr_params[:fq] << "#{solr_field}: [#{start} TO #{finish}]"
81
-
82
- if (config.segments != false && start != "*" && finish != "*")
83
- # Add in our calculated segments, can only do with both boundaries.
84
- add_range_segments_to_solr!(solr_params, solr_field, start.to_i, finish.to_i)
85
- end
86
-
87
- elsif (config.segments != false &&
88
- boundaries = config.assumed_boundaries)
89
- # assumed_boundaries in config
90
- add_range_segments_to_solr!(solr_params, solr_field, boundaries[0], boundaries[1])
91
- end
39
+ @response, _ = search_results(params, search_params_logic) do |search_builder|
40
+ search_builder.except(:add_range_limit_params).append(:fetch_specific_range_limit)
92
41
  end
93
-
94
- return solr_params
95
- end
96
-
97
- # Returns range config hash for named solr field. Returns false
98
- # if not configured. Returns hash even if configured to 'true'
99
- # for consistency.
100
- def range_config(solr_field)
101
- field = blacklight_config.facet_fields[solr_field.to_s]
102
-
103
- return false unless field.range
104
-
105
- config = field.range
106
- config = {} if config === true
107
42
 
108
- config
43
+ render('blacklight_range_limit/range_segments', :locals => {:solr_field => params[:range_field]}, :layout => !request.xhr?)
109
44
  end
110
45
  end
111
46
  end
@@ -0,0 +1,83 @@
1
+ require 'blacklight_range_limit/segment_calculation'
2
+
3
+ module BlacklightRangeLimit
4
+ module RangeLimitBuilder
5
+ include BlacklightRangeLimit::SegmentCalculation
6
+
7
+ # Method added to solr_search_params_logic to fetch
8
+ # proper things for date ranges. This should be added in by default to standard
9
+ # processing chain.
10
+ def add_range_limit_params(solr_params)
11
+ ranged_facet_configs =
12
+ blacklight_config.facet_fields.select { |key, config| config.range }
13
+ # In ruby 1.8, hash.select returns an array of pairs, in ruby 1.9
14
+ # it returns a hash. Turn it into a hash either way.
15
+ ranged_facet_configs = Hash[ ranged_facet_configs ] unless ranged_facet_configs.kind_of?(Hash)
16
+
17
+ ranged_facet_configs.each_pair do |solr_field, config|
18
+ solr_params["stats"] = "true"
19
+ solr_params["stats.field"] ||= []
20
+ solr_params["stats.field"] << solr_field
21
+
22
+ hash = blacklight_params["range"] && blacklight_params["range"][solr_field] ?
23
+ blacklight_params["range"][solr_field] :
24
+ {}
25
+
26
+ if !hash["missing"].blank?
27
+ # missing specified in request params
28
+ solr_params[:fq] ||= []
29
+ solr_params[:fq] << "-#{solr_field}:[* TO *]"
30
+
31
+ elsif !(hash["begin"].blank? && hash["end"].blank?)
32
+ # specified in request params, begin and/or end, might just have one
33
+ start = hash["begin"].blank? ? "*" : hash["begin"]
34
+ finish = hash["end"].blank? ? "*" : hash["end"]
35
+
36
+ solr_params[:fq] ||= []
37
+ solr_params[:fq] << "#{solr_field}: [#{start} TO #{finish}]"
38
+
39
+ if (config.segments != false && start != "*" && finish != "*")
40
+ # Add in our calculated segments, can only do with both boundaries.
41
+ add_range_segments_to_solr!(solr_params, solr_field, start.to_i, finish.to_i)
42
+ end
43
+
44
+ elsif (config.segments != false &&
45
+ boundaries = config.assumed_boundaries)
46
+ # assumed_boundaries in config
47
+ add_range_segments_to_solr!(solr_params, solr_field, boundaries[0], boundaries[1])
48
+ end
49
+ end
50
+
51
+ return solr_params
52
+ end
53
+
54
+
55
+ # Another processing method, this one is NOT included in default processing chain,
56
+ # it is specifically swapped in *instead of* add_range_limit_params for
57
+ # certain ajax requests that only want to fetch range limit segments for
58
+ # ONE field.
59
+ #
60
+ # It turns off facetting and sets rows to 0 as well, only results for
61
+ # single specified field are needed.
62
+ #
63
+ # Specified field and parameters are specified in incoming parameters
64
+ # range_field, range_start, range_end
65
+ def fetch_specific_range_limit(solr_params)
66
+ solr_field = blacklight_params[:range_field] # what field to fetch for
67
+ start = blacklight_params[:range_start].to_i
68
+ finish = blacklight_params[:range_end].to_i
69
+
70
+ add_range_segments_to_solr!(solr_params, solr_field, start, finish )
71
+
72
+ # Remove all field faceting for efficiency, we won't be using it.
73
+ solr_params.delete("facet.field")
74
+ solr_params.delete("facet.field".to_sym)
75
+
76
+ # We don't need any actual rows either
77
+ solr_params[:rows] = 0
78
+
79
+ return solr_params
80
+ end
81
+
82
+ end
83
+ end
@@ -12,7 +12,7 @@ module BlacklightRangeLimit
12
12
  #
13
13
  # Changes solr_params passed in.
14
14
  def add_range_segments_to_solr!(solr_params, solr_field, min, max)
15
- field_config = range_config(solr_field)
15
+ field_config = BlacklightRangeLimit.range_config(blacklight_config, solr_field)
16
16
 
17
17
  solr_params[:"facet.query"] ||= []
18
18
 
@@ -98,6 +98,8 @@ module BlacklightRangeLimit
98
98
  def floorInBase(n, base)
99
99
  return base * (n / base).floor
100
100
  end
101
+
102
+
101
103
 
102
104
  end
103
105
  end
@@ -103,6 +103,10 @@
103
103
 
104
104
  return array
105
105
  end
106
+
107
+ def range_config(solr_field)
108
+ BlacklightRangeLimit.range_config(blacklight_config, solr_field)
109
+ end
106
110
 
107
111
  end
108
112
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blacklight_range_limit
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.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-07-14 00:00:00.000000000 Z
12
+ date: 2015-10-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -49,22 +49,16 @@ dependencies:
49
49
  name: blacklight
50
50
  requirement: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 5.0.0.pre4
55
- - - "<"
52
+ - - "~>"
56
53
  - !ruby/object:Gem::Version
57
- version: '6'
54
+ version: '5.15'
58
55
  type: :runtime
59
56
  prerelease: false
60
57
  version_requirements: !ruby/object:Gem::Requirement
61
58
  requirements:
62
- - - ">="
63
- - !ruby/object:Gem::Version
64
- version: 5.0.0.pre4
65
- - - "<"
59
+ - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '6'
61
+ version: '5.15'
68
62
  - !ruby/object:Gem::Dependency
69
63
  name: rspec
70
64
  requirement: !ruby/object:Gem::Requirement
@@ -202,6 +196,7 @@ files:
202
196
  - lib/blacklight_range_limit.rb
203
197
  - lib/blacklight_range_limit/controller_override.rb
204
198
  - lib/blacklight_range_limit/engine.rb
199
+ - lib/blacklight_range_limit/range_limit_builder.rb
205
200
  - lib/blacklight_range_limit/route_sets.rb
206
201
  - lib/blacklight_range_limit/segment_calculation.rb
207
202
  - lib/blacklight_range_limit/version.rb