lsolr 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/lsolr.rb +39 -33
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0de60c66ff9d0bcd24c7caa5c3d86f1bb829c341
|
4
|
+
data.tar.gz: dd3a5e496f35898ff3147860b83b912829f186bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daef2067c282dfc6bc0312800a6191cc31931e4fba5c15e13116fe9de9f7100f0da3109ca27941860c5987c97b1d7299dea4428ff22ce17ae56779572456c811
|
7
|
+
data.tar.gz: 16f091cd2ccfd556024ede8c33477ec5a888c175de2d6d1bc3b71d3234a1357cd82796d5b2f07e9ece6ef87a17914a7625ee301844b15a860629f8137430cb00
|
data/lib/lsolr.rb
CHANGED
@@ -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(
|
9
|
-
# #=> '
|
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
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
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
|
-
# #=> '
|
32
|
-
# # AND
|
33
|
-
# # AND
|
34
|
-
# # AND
|
35
|
-
# # AND
|
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
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
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
|
-
#
|
44
|
-
#
|
43
|
+
# left = bool1.and(date1).and(date2).wrap
|
44
|
+
# right = bool2.and(date1.or(date2).wrap).wrap
|
45
45
|
#
|
46
|
-
#
|
47
|
-
#
|
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
|
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
|
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
|
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.
|
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.
|
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
|