multi-solr 01.07.07 → 01.08.00

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,24 +23,27 @@ class MultiSolr::SolrFilterCollection < MultiSolr::SolrFilterSimple
23
23
  @collection_proc = options.delete(:collection_data)
24
24
  @after_collect_proc = options.delete(:after_collect)
25
25
  if options[:render_value].nil?
26
- options[:render_value] = lambda{|value| compact_values(value).join(' oder ') }
26
+ options[:render_value] = lambda{|value| compact_values(value).join(', ') }
27
27
  end
28
- if options[:solr_query].nil?
29
- options[:solr_query] = lambda do |value|
30
- if value.is_a?(Array)
31
- values = compact_values(value)
32
- if values.empty?
33
- ''
34
- else
35
- q = values.map{|val| "#{@name}:#{val}"}.join(' OR ')
36
- "(#{q})"
37
- end
38
- else
39
- "#{@name}:#{value}"
40
- end
28
+ super filter_name, options
29
+ end
30
+
31
+
32
+ # overwrite super for array handling
33
+ def build_solr_query value
34
+ return super(value) unless value.is_a? Array
35
+ values = compact_values(value)
36
+ return nil if values.empty?
37
+ sanitize_values! values
38
+ if @solr_query_proc
39
+ q = @solr_query_proc.call(values)
40
+ else
41
+ q = values.map{|val| "#{@name}:#{val}"}.join(' OR ')
42
+ if values.size > 1
43
+ q = "(#{q})"
41
44
  end
42
45
  end
43
- super filter_name, options
46
+ q
44
47
  end
45
48
 
46
49
 
@@ -73,6 +76,12 @@ class MultiSolr::SolrFilterCollection < MultiSolr::SolrFilterSimple
73
76
  def compact_values value
74
77
  value = [value] unless value.is_a?(Array)
75
78
  value.delete_if(&:blank?)
79
+ value
80
+ end
81
+
82
+ # Sanitize solr query value in a array of values
83
+ def sanitize_values! values
84
+ values.map!{|val| sanitize_value(val) }
76
85
  end
77
86
 
78
87
  end
@@ -22,7 +22,7 @@ class MultiSolr::SolrFilterSimple
22
22
  @name = name
23
23
  @field_name = options[:field_name] || @name
24
24
  @value_render_proc = options.delete(:render_value) || lambda{|value| value.to_s }
25
- @solr_query_proc = options.delete(:solr_query) || lambda{|value| "#{@field_name}:#{value}"}
25
+ @solr_query_proc = options.delete(:solr_query)
26
26
  @options = options || {}
27
27
  end
28
28
 
@@ -37,9 +37,13 @@ class MultiSolr::SolrFilterSimple
37
37
  # returns: String in SOLR-Query-Syntax
38
38
  def build_solr_query value
39
39
  return nil if value.blank?
40
- # wenn Leerzeichen vorkommen dann String in " einschliessen
41
- value = "\"#{value}\"" if value =~ /\s+/
42
- @solr_query_proc.call(value)
40
+ # wenn Leerzeichen vorkommen dann String in "" einschliessen
41
+ value = sanitize_value value
42
+ if @solr_query_proc
43
+ @solr_query_proc.call(value)
44
+ else
45
+ "#{@field_name}:#{value}"
46
+ end
43
47
  end
44
48
 
45
49
 
@@ -61,6 +65,14 @@ class MultiSolr::SolrFilterSimple
61
65
  I18n.t("solr_search.#{@name}", :default => [@name, @name.to_s])
62
66
  end
63
67
 
68
+ def sanitize_value value
69
+ if value =~ /\s+/
70
+ "\"#{value}\""
71
+ else
72
+ value
73
+ end
74
+ end
75
+
64
76
  end
65
77
 
66
78
 
@@ -1,3 +1,3 @@
1
1
  module MultiSolr
2
- VERSION = "01.07.07"
2
+ VERSION = "01.08.00"
3
3
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ require 'multi_solr/utils'
3
+
4
+ describe MultiSolr::SolrFilterCollection do
5
+
6
+ subject{ MultiSolr::SolrFilterCollection.new('test') }
7
+
8
+
9
+ context 'build_solr_query' do
10
+ it "should return fieldnam:value for single value" do
11
+ subject.build_solr_query('111').should == 'test:111'
12
+ end
13
+
14
+ it "should return fieldnam:value for single value array" do
15
+ subject.build_solr_query(['111']).should == 'test:111'
16
+ end
17
+
18
+ it "should return 'OR' query for multiple values" do
19
+ subject.build_solr_query(['11', 'a 2']).should == '(test:11 OR test:"a 2")'
20
+ end
21
+ end
22
+
23
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi-solr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 55
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 7
9
- - 7
10
- version: 01.07.07
8
+ - 8
9
+ - 0
10
+ version: 01.08.00
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bernd Ledig
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-07-12 00:00:00 Z
18
+ date: 2013-07-24 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  prerelease: false
@@ -150,6 +150,7 @@ files:
150
150
  - spec/multi_solr/search_result_spec.rb
151
151
  - spec/multi_solr/single_core_handler_spec.rb
152
152
  - spec/multi_solr/solr_filter_boolean_spec.rb
153
+ - spec/multi_solr/solr_filter_collection_spec.rb
153
154
  - spec/multi_solr/solr_filter_range_spec.rb
154
155
  - spec/multi_solr/timeline_core_handler_spec.rb
155
156
  - spec/multi_solr/utils_spec.rb