cyx-solr_query 0.1.0 → 0.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.
data/TODO ADDED
@@ -0,0 +1 @@
1
+ * more tests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/solr_query.rb CHANGED
@@ -37,9 +37,15 @@ class SolrQuery
37
37
  @stream[-1]
38
38
  end
39
39
 
40
- def condition( field, value, escaping = true )
40
+ def condition( field, value, args = [] )
41
41
  return if value.blank?
42
- stream.push("#{field}:#{escape(value, escaping)}")
42
+ escaping = !args.include?( :raw )
43
+
44
+ if args.include?(:not)
45
+ stream.push("NOT(#{field}:#{quote(escape(value, escaping))})")
46
+ else
47
+ stream.push("#{field}:#{quote(escape(value, escaping))}")
48
+ end
43
49
  end
44
50
 
45
51
  def term( value, escaping = true )
@@ -48,7 +54,7 @@ class SolrQuery
48
54
  end
49
55
 
50
56
  def like( value, escaping = true )
51
- "#{escape(value.downcase, escaping)}*"
57
+ "#{quote(escape(value.downcase, escaping))}*"
52
58
  end
53
59
 
54
60
  def to_s( operator = AND )
@@ -75,4 +81,14 @@ class SolrQuery
75
81
  str
76
82
  end
77
83
  end
84
+
85
+ def quote( str )
86
+ if str.to_s.index(' ')
87
+ "\"#{str}\""
88
+ elsif str.to_s.index(':')
89
+ str.gsub(':', ' ')
90
+ else
91
+ str
92
+ end
93
+ end
78
94
  end
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{solr_query}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Cyril David"]
9
+ s.date = %q{2009-06-08}
10
+ s.email = %q{cyx.ucron@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "TODO",
22
+ "VERSION",
23
+ "lib/solr_query.rb",
24
+ "solr_query.gemspec",
25
+ "test/solr_query_test.rb",
26
+ "test/test_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/cyx/solr_query}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.3}
32
+ s.summary = %q{TODO}
33
+ s.test_files = [
34
+ "test/solr_query_test.rb",
35
+ "test/test_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -153,4 +153,25 @@ class SolrQueryTest < Test::Unit::TestCase
153
153
  assert_equal 'allowed:all', result
154
154
  end
155
155
  end
156
+
157
+ context "given condition 'allowed', 'some user here'" do
158
+ should "be allowed:\"some user here\"" do
159
+ result = SolrQuery.create do |q|
160
+ q.condition 'allowed', 'some user here'
161
+ end
162
+
163
+ assert_equal 'allowed:"some user here"', result
164
+ end
165
+ end
166
+
167
+ context "given condition 'allowed', 'bla' :not " do
168
+ should "be NOT(allowed:bla)" do
169
+ result = SolrQuery.create do |q|
170
+ q.condition 'allowed', 'bla', [ :not ]
171
+ end
172
+
173
+ assert_equal 'NOT(allowed:bla)', result
174
+ end
175
+ end
176
+
156
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyx-solr_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril David
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-03 00:00:00 -07:00
12
+ date: 2009-06-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,8 +28,10 @@ files:
28
28
  - LICENSE
29
29
  - README.rdoc
30
30
  - Rakefile
31
+ - TODO
31
32
  - VERSION
32
33
  - lib/solr_query.rb
34
+ - solr_query.gemspec
33
35
  - test/solr_query_test.rb
34
36
  - test/test_helper.rb
35
37
  has_rdoc: false