lsolr 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/lsolr.rb +39 -33
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 5e5ca288040ec046e3df00c273dcd6c3ccc6bd31e6db172bb652ff377dddaaf4
4
- data.tar.gz: d87df9ae56c1aa37c1b92e11c00c82b0a3afb44abdd7e918e48ab88cce69a7e8
2
+ SHA1:
3
+ metadata.gz: 0de60c66ff9d0bcd24c7caa5c3d86f1bb829c341
4
+ data.tar.gz: dd3a5e496f35898ff3147860b83b912829f186bc
5
5
  SHA512:
6
- metadata.gz: 4da503d0ce9a2627630c35848d8e3dc0d1b5fdacbf60839d9973f82a7ac2cd79d29a73a57a4583ed2ebf3a98de9bd14a5488da55f77cc41f24010cb76c091e70
7
- data.tar.gz: b0ad4353b239b32cfdaf828cfc201dae3b917f21f861c4c460787b575d0630ec60276ff9cd6a36d3daa8d9ee0cc24730df68206a11ae83ea8d283c83453de95c
6
+ metadata.gz: daef2067c282dfc6bc0312800a6191cc31931e4fba5c15e13116fe9de9f7100f0da3109ca27941860c5987c97b1d7299dea4428ff22ce17ae56779572456c811
7
+ data.tar.gz: 16f091cd2ccfd556024ede8c33477ec5a888c175de2d6d1bc3b71d3234a1357cd82796d5b2f07e9ece6ef87a17914a7625ee301844b15a860629f8137430cb00
@@ -5,47 +5,53 @@ require 'date'
5
5
  # A query builder of Apache Solr standard Lucene type query for Ruby.
6
6
  #
7
7
  # @example How to use. Part 1:
8
- # LSolr.build(term1: 'hoge', term2: true).to_s
9
- # #=> 'term1:hoge AND term2:true'
8
+ # LSolr.build(field1: 'hoge', field2: true).to_s
9
+ # #=> 'field1:hoge AND field2:true'
10
10
  #
11
11
  # @example How to use. Part 2:
12
12
  # params = {
13
- # term01: 'hoge',
14
- # term02: :fuga,
15
- # term03: 14,
16
- # term04: 7.3,
17
- # term05: true,
18
- # term06: false,
19
- # term07: Date.new(7000, 7, 1),
20
- # term08: DateTime.new(6000, 5, 31, 6, 31, 43),
21
- # term09: Time.new(5000, 6, 30, 12, 59, 3),
22
- # term10: LSolr.new(:term10).fuzzy_match('foo'),
23
- # term11: [1, 2, 3],
24
- # term12: 1..10,
25
- # term13: 20...40,
26
- # term14: Date.new(3000, 1, 1)..Date.new(4000, 12, 31),
27
- # term15: (3.0..4.0).step(0.1)
13
+ # field01: 'hoge',
14
+ # field02: :fuga,
15
+ # field03: 14,
16
+ # field04: 7.3,
17
+ # field05: true,
18
+ # field06: false,
19
+ # field07: Date.new(7000, 7, 1),
20
+ # field08: DateTime.new(6000, 5, 31, 6, 31, 43),
21
+ # field09: Time.new(5000, 6, 30, 12, 59, 3),
22
+ # field10: LSolr.new(:field10).fuzzy_match('foo'),
23
+ # field11: [1, 2, 3],
24
+ # field12: 1..10,
25
+ # field13: 20...40,
26
+ # field14: Date.new(3000, 1, 1)..Date.new(4000, 12, 31),
27
+ # field15: (3.0..4.0).step(0.1)
28
28
  # }
29
29
  #
30
30
  # LSolr.build(params).to_s
31
- # #=> 'term01:hoge AND term02:fuga AND term03:14 AND term04:7.3 AND term05:true
32
- # # AND term06:false AND term07:"7000-07-01T00:00:00Z" AND term08:"6000-05-31T06:31:43Z"
33
- # # AND term09:"5000-06-30T12:59:03Z" AND term10:foo~2.0 AND (term11:1 OR term11:2 OR term11:3)
34
- # # AND term12:[1 TO 10] AND term13:[20 TO 40} AND term14:[3000-01-01T00:00:00Z TO 4000-12-31T00:00:00Z]
35
- # # AND term15:[3.0 TO 4.0]'
31
+ # #=> 'field01:hoge AND field02:fuga AND field03:14 AND field04:7.3 AND field05:true
32
+ # # AND field06:false AND field07:"7000-07-01T00:00:00Z" AND field08:"6000-05-31T06:31:43Z"
33
+ # # AND field09:"5000-06-30T12:59:03Z" AND field10:foo~2.0 AND (field11:1 OR field11:2 OR field11:3)
34
+ # # AND field12:[1 TO 10] AND field13:[20 TO 40} AND field14:[3000-01-01T00:00:00Z TO 4000-12-31T00:00:00Z]
35
+ # # AND field15:[3.0 TO 4.0]'
36
36
  #
37
37
  # @example How to use. Part 3:
38
- # monoclinic = LSolr.new(:crystal_system).match(:monoclinic)
39
- # cubic = LSolr.new(:crystal_system).match(:cubic)
40
- # soft = LSolr.new(:mohs_scale).greater_than_or_equal_to('*').less_than(5.0)
41
- # hard = LSolr.new(:mohs_scale).greater_than_or_equal_to(5.0).less_than_or_equal_to(10.0)
38
+ # bool1 = LSolr.new(:bool_field).match(true)
39
+ # bool2 = LSolr.new(:bool_field).match(false)
40
+ # date1 = LSolr.new(:date_field1).greater_than_or_equal_to('*').less_than_or_equal_to(Time.new(2000, 6, 30, 23, 59, 59))
41
+ # date2 = LSolr.new(:date_field2).greater_than(Time.new(2000, 7, 1, 0, 0, 0)).less_than(Time.new(2001, 1, 1, 0, 0, 0))
42
42
  #
43
- # phosphophyllite = monoclinic.and(soft).wrap
44
- # diamond = cubic.and(hard).wrap
43
+ # left = bool1.and(date1).and(date2).wrap
44
+ # right = bool2.and(date1.or(date2).wrap).wrap
45
45
  #
46
- # phosphophyllite.or(diamond).to_s
47
- # #=> '(crystal_system:monoclinic AND mohs_scale:[* TO 5.0}) OR (crystal_system:cubic AND mohs_scale:[5.0 TO 10.0])'
46
+ # left.or(right).to_s
47
+ # #=> '(bool_field:true AND date_field1:[* TO 2000-06-30T23:59:59Z] AND date_field2:{2000-07-01T00:00:00Z TO 2001-01-01T00:00:00Z})
48
+ # # OR (bool_field:false AND (date_field1:[* TO 2000-06-30T23:59:59Z] OR date_field2:{2000-07-01T00:00:00Z TO 2001-01-01T00:00:00Z}))'
48
49
  class LSolr
50
+ ArgumentError = Class.new(::ArgumentError)
51
+ RangeError = Class.new(::RangeError)
52
+ TypeError = Class.new(::TypeError)
53
+ IncompleteQueryError = Class.new(StandardError)
54
+
49
55
  NOT = 'NOT'
50
56
  AND = 'AND'
51
57
  OR = 'OR'
@@ -95,7 +101,7 @@ class LSolr
95
101
  when Array then build_array_query(field, value)
96
102
  when Range then build_range_query(field, value)
97
103
  when Enumerator then build_enumerator_query(field, value)
98
- else raise ArgumentError, "Could not build solr query. field: #{field}, value: #{value.inspect}"
104
+ else raise TypeError, "Could not build solr query. field: #{field}, value: #{value.inspect}"
99
105
  end
100
106
  end
101
107
 
@@ -140,7 +146,7 @@ class LSolr
140
146
  # @return [String] a stringified query
141
147
  def to_s
142
148
  @value = "#{@range_first} #{TO} #{@range_last}" if range_search?
143
- raise 'Please specify a search condition.' if blank?
149
+ raise IncompleteQueryError, 'Please specify a search value.' if blank?
144
150
 
145
151
  expr = "#{left_parentheses.join}#{@not}#{@field}:#{@value}#{right_parentheses.join}"
146
152
  expr = "#{prev} #{operator} #{expr}" if !prev.nil? && prev.present?
@@ -385,7 +391,7 @@ class LSolr
385
391
  msec_str = case date
386
392
  when Date then date.strftime(FORMAT_MILLISECOND_FOR_DATE_TYPE).gsub(date.strftime(FORMAT_SECOND), '')
387
393
  when Time then date.strftime(FORMAT_MILLISECOND_FOR_TIME_TYPE)
388
- else raise ArgumentError, "Unknown type #{date.inspect}"
394
+ else raise TypeError, "Could not format dates or times. Given value: #{date.inspect}"
389
395
  end
390
396
 
391
397
  return date.strftime(FORMAT_DATE_TIME) if msec_str == '000'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
@@ -38,7 +38,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
38
38
  version: '0'
39
39
  requirements: []
40
40
  rubyforge_project:
41
- rubygems_version: 2.7.3
41
+ rubygems_version: 2.6.13
42
42
  signing_key:
43
43
  specification_version: 4
44
44
  summary: A query builder of Apache Solr for Ruby