cql-ruby 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,19 +116,19 @@ class CqlTermNode
116
116
  # match/exclude on partial matches too, not only complete matches.
117
117
  when "<>"
118
118
  negate = true
119
- maybe_quote(@term)
120
- when "cql.adj", "==" then maybe_quote(@term)
119
+ solr_maybe_quote(@term)
120
+ when "cql.adj", "==" then solr_maybe_quote(@term)
121
121
  when "cql.all" then '(' + @term.split(/\s/).collect{|a| '+'+a}.join(" ") + ')'
122
122
  when "cql.any" then '(' + @term.split(/\s/).join(" OR ") + ')'
123
- when ">=" then "[" + maybe_quote(@term) + " TO *]"
124
- when ">" then "{" + maybe_quote(@term) + " TO *}"
125
- when "<=" then "[* TO " + maybe_quote(@term) + "]"
126
- when "<" then "{* TO " + maybe_quote(@term) + "}"
123
+ when ">=" then "[" + solr_maybe_quote(@term) + " TO *]"
124
+ when ">" then "{" + solr_maybe_quote(@term) + " TO *}"
125
+ when "<=" then "[* TO " + solr_maybe_quote(@term) + "]"
126
+ when "<" then "{* TO " + solr_maybe_quote(@term) + "}"
127
127
  when "cql.within"
128
128
  bounds = @term.gsub('"', "").split(/\s/)
129
129
  raise CqlException.new("can not extract two bounding values from within relation term: #{@term}") unless bounds.length == 2
130
130
 
131
- "[" + maybe_quote(bounds[0]) + " TO " + maybe_quote(bounds[1]) + "]"
131
+ "[" + solr_maybe_quote(bounds[0]) + " TO " + solr_maybe_quote(bounds[1]) + "]"
132
132
  else
133
133
  raise CqlException.new("relation not supported: #{relation}")
134
134
  end
@@ -140,6 +140,17 @@ class CqlTermNode
140
140
 
141
141
  return ret
142
142
  end
143
+
144
+ # utility method, quotes/escapes value, if needed, for inclusion
145
+ # in solr lucene query parser term.
146
+ # wraps in double quotes if needed, backslash-escapes internal double
147
+ # quotes.
148
+ def solr_maybe_quote(term)
149
+ return term unless term =~ /[^a-zA-Z0-9_]/
150
+
151
+ return '"' + term.gsub('"', '\\"') + '"'
152
+ end
153
+
143
154
  end
144
155
 
145
156
  class CqlBooleanNode
@@ -89,6 +89,12 @@ class CqlToSolrTest < Test::Unit::TestCase
89
89
  assert_to_solr_eq("cql.allindexes = val", @@parser.parse("my_all_index = val").to_solr)
90
90
  end
91
91
  end
92
+
93
+ def test_escapes_terms
94
+ assert_to_solr_eq('text = ab[]cd', 'text:"ab[]cd"')
95
+
96
+ assert_to_solr_eq('text = "one\'s \" two"', 'text:"one\'s \" two"')
97
+ end
92
98
 
93
99
  #############
94
100
  # Helpers
metadata CHANGED
@@ -1,32 +1,39 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: cql-ruby
3
- version: !ruby/object:Gem::Version
4
- version: 0.9.0
3
+ version: !ruby/object:Gem::Version
4
+ hash: 57
5
5
  prerelease:
6
+ segments:
7
+ - 0
8
+ - 9
9
+ - 1
10
+ version: 0.9.1
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Jonathan Rochkind
9
14
  - Chick Markley
10
15
  autorequire:
11
16
  bindir: bin
12
17
  cert_chain: []
13
- date: 2012-02-29 00:00:00.000000000 Z
18
+
19
+ date: 2012-04-17 00:00:00 Z
14
20
  dependencies: []
15
- description: ! ' CQL Parser, with serialization from cql node tree to cql, xcql, and
16
- solr query'
21
+
22
+ description: " CQL Parser, with serialization from cql node tree to cql, xcql, and solr query"
17
23
  email: cql_ruby@googlegroups.com
18
24
  executables: []
25
+
19
26
  extensions: []
20
- extra_rdoc_files:
27
+
28
+ extra_rdoc_files:
21
29
  - README.md
22
- files:
30
+ files:
23
31
  - lib/cql_ruby.rb
24
32
  - lib/cql_ruby/cql_generator.rb
25
33
  - lib/cql_ruby/cql_lexer.rb
26
34
  - lib/cql_ruby/cql_nodes.rb
27
35
  - lib/cql_ruby/cql_parser.rb
28
36
  - lib/cql_ruby/cql_to_solr.rb
29
- - lib/cql_ruby/version.rb
30
37
  - README.md
31
38
  - test/test_cql_parser.rb
32
39
  - test/test_cql_nodes.rb
@@ -38,30 +45,38 @@ files:
38
45
  - test/test_cql_to_solr.rb
39
46
  homepage: https://github.com/jrochkind/cql-ruby
40
47
  licenses: []
48
+
41
49
  post_install_message:
42
- rdoc_options:
50
+ rdoc_options:
43
51
  - --charset=UTF-8
44
- require_paths:
52
+ require_paths:
45
53
  - lib
46
- required_ruby_version: !ruby/object:Gem::Requirement
54
+ required_ruby_version: !ruby/object:Gem::Requirement
47
55
  none: false
48
- requirements:
49
- - - ! '>='
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
64
  none: false
54
- requirements:
55
- - - ! '>='
56
- - !ruby/object:Gem::Version
57
- version: '0'
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ hash: 3
69
+ segments:
70
+ - 0
71
+ version: "0"
58
72
  requirements: []
73
+
59
74
  rubyforge_project: cql-ruby
60
75
  rubygems_version: 1.8.15
61
76
  signing_key:
62
77
  specification_version: 3
63
78
  summary: CQL Parser
64
- test_files:
79
+ test_files:
65
80
  - test/test_cql_parser.rb
66
81
  - test/test_cql_nodes.rb
67
82
  - test/test_cql_generator.rb
@@ -1,9 +0,0 @@
1
- module CqlRuby #:nodoc:
2
- module VERSION #:nodoc:
3
- MAJOR = 0
4
- MINOR = 7
5
- TINY = 1
6
-
7
- STRING = [MAJOR, MINOR, TINY].join('.')
8
- end
9
- end