solr_query 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/solr_query.rb +12 -7
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ spec = Gem::Specification.new do |s|
33
33
 
34
34
  # Change these as appropriate
35
35
  s.name = "solr_query"
36
- s.version = "1.0.2"
36
+ s.version = "1.0.3"
37
37
  s.description = "Build SOLR queries, properly escaped, with a nice API"
38
38
  s.summary = "a ruby library designed to make building nested Solr queries simple and standardized. "
39
39
  s.author = "Matthew Rudy Jacobs"
@@ -30,7 +30,7 @@ module SolrQuery
30
30
  query_parts = []
31
31
  keyword = conditions.delete(keyword_key) # keyword is magical
32
32
  if !blank?(keyword) # ie. !keyword.blank?
33
- query_parts << "#{solr_value(keyword, true)}"
33
+ query_parts << "#{solr_value(keyword, :downcase => true)}"
34
34
  end
35
35
 
36
36
  conditions.each do |field, value|
@@ -46,13 +46,16 @@ module SolrQuery
46
46
  end
47
47
  end
48
48
 
49
- def solr_value(object, downcase=false)
49
+ def solr_value(object, opts={})
50
+ downcase = opts[:downcase]
51
+ dont_escape = opts[:dont_escape]
52
+
50
53
  if object.is_a?(Array) # case when Array will break for has_manys
51
54
  if object.empty?
52
55
  string = "NIL" # an empty array should be equivalent to "don't match anything"
53
56
  else
54
57
  string = object.map do |element|
55
- solr_value(element, downcase)
58
+ solr_value(element, opts.merge(:dont_escape => true))
56
59
  end.join(" OR ")
57
60
  downcase = false # don't downcase the ORs
58
61
  end
@@ -62,15 +65,17 @@ module SolrQuery
62
65
  string = object.id.to_s
63
66
  elsif object.is_a?(String)
64
67
  if downcase && (bits = object.split(" OR ")) && bits.length > 1
65
- return "(#{solr_value(bits, downcase)})"
68
+ return "(#{solr_value(bits, opts)})"
66
69
  else
67
70
  string = object
68
71
  end
69
72
  else
70
73
  string = object.to_s
71
74
  end
72
- string.downcase! if downcase
73
- return escape_solr_string(string)
75
+ string.downcase! if downcase
76
+ string = escape_solr_string(string) unless dont_escape
77
+
78
+ string
74
79
  end
75
80
  protected :solr_value
76
81
 
@@ -109,6 +114,6 @@ module SolrQuery
109
114
 
110
115
  end
111
116
 
112
- SOLR_ESCAPE_CHARACTERS = %w" \ + - ! ( ) : ; ^ [ ] { } ~ * ? "
117
+ SOLR_ESCAPE_CHARACTERS = %w" \\ + - ! ( ) : ; ^ [ ] { } ~ * ? "
113
118
  SOLR_ESCAPE_REGEXP = Regexp.new(SOLR_ESCAPE_CHARACTERS.map{|char| Regexp.escape(char)}.join("|"))
114
119
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 2
9
- version: 1.0.2
8
+ - 3
9
+ version: 1.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Matthew Rudy Jacobs