lsolr 0.0.2 → 0.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. checksums.yaml +4 -4
  2. data/lib/lsolr.rb +95 -22
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3ff72ff796373dff95e027ae0121a55b69f15878
4
- data.tar.gz: 99d1e7d1a606578a907fea5aa167067de39e661c
3
+ metadata.gz: 611d522d19f5adbfae542ed8d066d5b9f7e0517e
4
+ data.tar.gz: 32066b63f4377d5d64e85f4c35965476d1ed6f81
5
5
  SHA512:
6
- metadata.gz: 76bbae287e7d4b159a7e7c05491a26c29259474f9d469eb22e5f2e84a9d74fdaef7d3e7dc2c87942cc8d6cc770cc7f461c722090f98c155b46acac49096256ee
7
- data.tar.gz: 3df9ee21192b7f2fad330a3a4e5e003d6866539e307a4a1689062e345a6d94e95f00c2203f08d7bf82915ada3d6fe428bbb294c957ca39f1e82034ee450dccef
6
+ metadata.gz: fab35b495e36c5d0754fd137f323b854ae08970dda8859d6a21c712175e11c0a95c4750ad7a5f83795e9ed6439c990be2e04c69e4913fd667b88517ce9ce754e
7
+ data.tar.gz: 67256e547e5dcdc89d96b89445d5bc119ae1d1b5bd0dfc355d03aeb8a6aec890496fade7e46ccef8987f433b4724b6417411fec6adf04f7a8f227373ed7a1c78
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # A query builder of Apache Solr standard Lucene type query for Ruby.
4
+ #
3
5
  # @example How to use.
4
6
  # monoclinic = LSolr.new(:crystal_system).match(:monoclinic)
5
7
  # cubic = LSolr.new(:crystal_system).match(:cubic)
@@ -35,7 +37,9 @@ class LSolr
35
37
 
36
38
  attr_accessor :prev, :operator, :left_parentheses, :right_parentheses
37
39
 
38
- # @param field [String] field name
40
+ # Create a new query builder instance.
41
+ #
42
+ # @param field [String] a field name
39
43
  # @return [LSolr] a instance
40
44
  def initialize(field)
41
45
  raise ArgumentError, 'Please specify a field name.' if field.nil? || field.empty?
@@ -50,7 +54,9 @@ class LSolr
50
54
  @right_parentheses = []
51
55
  end
52
56
 
53
- # @return [String] a stringigied query
57
+ # Returns Apache Solr standard lucene type query string.
58
+ #
59
+ # @return [String] a stringified query
54
60
  def to_s
55
61
  @value = "#{@range_first} #{TO} #{@range_last}" if range_search?
56
62
  raise 'Please specify a search condition.' if blank?
@@ -60,18 +66,24 @@ class LSolr
60
66
  "#{expr}#{@boost}"
61
67
  end
62
68
 
63
- # @return [true] unless search condition specified
64
- # @return [false] if search condition specified
69
+ alias to_str to_s
70
+
71
+ # A query is blank if value is empty in expression.
72
+ #
73
+ # @return [true, false]
65
74
  def blank?
66
75
  @value.empty? && (@range_first.empty? || @range_last.empty?)
67
76
  end
68
77
 
69
- # @return [true] if search condition specified
70
- # @return [false] unless search condition specified
78
+ # A query is present if it's not blank.
79
+ #
80
+ # @return [true, false]
71
81
  def present?
72
82
  !blank?
73
83
  end
74
84
 
85
+ # Adds parentheses to query expression.
86
+ #
75
87
  # @return [LSolr] copied self instance
76
88
  def wrap
77
89
  this = dup
@@ -80,47 +92,73 @@ class LSolr
80
92
  this
81
93
  end
82
94
 
95
+ # Adds the boolean operator `NOT` to query expression.
96
+ #
97
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#the-boolean-operator-not The Boolean Operator NOT ("!")
98
+ #
83
99
  # @return [LSolr] self instance
84
100
  def not
85
101
  @not = "#{NOT} "
86
102
  self
87
103
  end
88
104
 
105
+ # Boosts a query expression.
106
+ #
107
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#boosting-a-term-with Boosting a Term with "^"
108
+ #
89
109
  # @param weight [Float] boost weight
110
+ #
90
111
  # @return [LSolr] self instance
91
112
  def boost(weight)
92
113
  @boost = "#{BOOST}#{weight}"
93
114
  self
94
115
  end
95
116
 
96
- # @param value [String, Integer, true, false] search word or filter value
117
+ # Builds a normal query expression.
118
+ #
119
+ # @param value [String, Integer, true, false] a search word or a filter value
120
+ #
97
121
  # @return [LSolr] self instance
98
122
  def match(value)
99
123
  values = clean(value).split
100
124
  if values.size > 1
101
125
  phrase_match(values)
102
126
  else
103
- @value = values.join('')
127
+ @value = values.join
104
128
  self
105
129
  end
106
130
  end
107
131
 
108
- # @param value [String] filter value
132
+ # Builds a normal query expression with dates and times.
133
+ #
134
+ # @param value [String] a filter value
135
+ #
109
136
  # @return [LSolr] self instance
110
137
  def date_time_match(value)
111
138
  @value = clean(value, symbols: RESERVED_SYMBOLS - %w[- : . / +])
112
139
  self
113
140
  end
114
141
 
115
- # @param value [String] search word
142
+ # Builds a prefix search query expression.
143
+ #
144
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#wildcard-searches Wildcard Searches
145
+ #
146
+ # @param value [String] a search word
147
+ #
116
148
  # @return [LSolr] self instance
117
149
  def prefix_match(value)
118
150
  @value = clean(value, symbols: RESERVED_SYMBOLS - %w[* ?])
119
151
  self
120
152
  end
121
153
 
122
- # @param values [Array<String>] search word
154
+ # Builds a phrase or proximity search query expression.
155
+ #
156
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#grouping-clauses-within-a-field Grouping Clauses within a Field
157
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#proximity-searches Proximity Searches
158
+ #
159
+ # @param values [Array<String>] search words
123
160
  # @param distance [Integer] proximity distance
161
+ #
124
162
  # @return [LSolr] self instance
125
163
  def phrase_match(values, distance: 0)
126
164
  value = values.map { |v| clean(v) }.join(REPLACEMENT_CHAR)
@@ -129,8 +167,13 @@ class LSolr
129
167
  self
130
168
  end
131
169
 
132
- # @param value [String] search word
133
- # @param distance [Float] proximity distance
170
+ # Builds a fuzzy search query expression.
171
+ #
172
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#fuzzy-searches Fuzzy Searches
173
+ #
174
+ # @param value [String] a search word
175
+ # @param distance [Float] a proximity distance
176
+ #
134
177
  # @return [LSolr] self instance
135
178
  def fuzzy_match(value, distance: 0.0)
136
179
  raise RangeError, "Out of #{FUZZY_MATCH_DISTANCE_RANGE}. #{distance} given." unless FUZZY_MATCH_DISTANCE_RANGE.member?(distance)
@@ -138,42 +181,72 @@ class LSolr
138
181
  self
139
182
  end
140
183
 
141
- # @param value [String, Integer] filter value
184
+ # Builds a range search query expression.
185
+ #
186
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#range-searches Range Searches
187
+ #
188
+ # @param value [String, Integer] a filter value
189
+ #
142
190
  # @return [LSolr] self instance
143
191
  def greater_than(value)
144
192
  @range_first = "#{GREATER_THAN}#{value}"
145
193
  self
146
194
  end
147
195
 
148
- # @param value [String, Integer] filter value
196
+ # Builds a range search query expression.
197
+ #
198
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#range-searches Range Searches
199
+ #
200
+ # @param value [String, Integer] a filter value
201
+ #
149
202
  # @return [LSolr] self instance
150
203
  def less_than(value)
151
204
  @range_last = "#{value}#{LESS_THAN}"
152
205
  self
153
206
  end
154
207
 
155
- # @param value [String, Integer] filter value
208
+ # Builds a range search query expression.
209
+ #
210
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#range-searches Range Searches
211
+ #
212
+ # @param value [String, Integer] a filter value
213
+ #
156
214
  # @return [LSolr] self instance
157
215
  def greater_than_or_equal_to(value)
158
216
  @range_first = "#{GREATER_THAN_OR_EQUAL_TO}#{value}"
159
217
  self
160
218
  end
161
219
 
162
- # @param value [String, Integer] filter value
220
+ # Builds a range search query expression.
221
+ #
222
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#range-searches Range Searches
223
+ #
224
+ # @param value [String, Integer] a filter value
225
+ #
163
226
  # @return [LSolr] self instance
164
227
  def less_than_or_equal_to(value)
165
228
  @range_last = "#{value}#{LESS_THAN_OR_EQUAL_TO}"
166
229
  self
167
230
  end
168
231
 
169
- # @param another [LSolr] another instance
170
- # @return [LSolr] copied another instance
232
+ # Builds a composite query expression.
233
+ #
234
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#the-boolean-operator-and The Boolean Operator AND ("&&")
235
+ #
236
+ # @param another [LSolr] another query builder instance
237
+ #
238
+ # @return [LSolr] copied another query builder instance
171
239
  def and(another)
172
240
  link(another, AND)
173
241
  end
174
242
 
175
- # @param another [LSolr] another instance
176
- # @return [LSolr] copied another instance
243
+ # Builds a composite query expression.
244
+ #
245
+ # @see https://lucene.apache.org/solr/guide/7_1/the-standard-query-parser.html#boolean-operators-supported-by-the-standard-query-parser Boolean Operators Supported by the Standard Query Parser
246
+ #
247
+ # @param another [LSolr] another query builder instance
248
+ #
249
+ # @return [LSolr] copied another query builder instance
177
250
  def or(another)
178
251
  link(another, OR)
179
252
  end
@@ -192,7 +265,7 @@ class LSolr
192
265
 
193
266
  def clean(value, symbols: RESERVED_SYMBOLS)
194
267
  value.to_s
195
- .tr(symbols.join(''), REPLACEMENT_CHAR)
268
+ .tr(symbols.join, REPLACEMENT_CHAR)
196
269
  .gsub(RESERVED_WORDS) { |match| "\\#{match}" }
197
270
  end
198
271
 
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.2
4
+ version: 0.0.3
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.6.14
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