lsolr 0.2.3 → 0.2.4

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 +26 -23
  3. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4274e0bfec1e74ca2120624580aad73461057f1d5912d83ae0dba8ff82b52a5
4
- data.tar.gz: a5cb76c8d965d86d6d6b541604fc1a8a23b6a73ba68ae566953677f68b1d95da
3
+ metadata.gz: 6b61a359f44587f3d0427b918647b04a7f43ce6a9ec9e394ae4ca09c68f59386
4
+ data.tar.gz: f4b20307a1239c0277d218670401a5187c85df9a0147aae90a1435fb13c68dbe
5
5
  SHA512:
6
- metadata.gz: dcd93b2d0e788cac40d2f942dd67a4245b6bd20d5dcb89d296c5d8fe29379975e8e220399f77201c3e416a9d308044f55a4f9720d5c74022df5b0aeb12adb893
7
- data.tar.gz: 83e1c44d830e10fedf551c0fc77baf77adcc191a4da69defbfd8792a8deca754958e3c0751e7afacae73f6d7197bc02ab4942663a5636fd685152db64e8b3aae
6
+ metadata.gz: 40abee52d81c47d9a1ff70c86045d58f17869c43f2b8fc7cf054229ce50597b9a86a8a93a309e090c3ecf1d459676f2f9105ec409f24162a328c64c8cf9289b7
7
+ data.tar.gz: bb8d98b7c36eebc3425665d1d3c7661eed341e997aa8c09c2a1b99a9c3f78dd5fe50630e0183844c6446db14eb2bff0acfb33c7f0bd52d509ff75397200b6f09
@@ -66,7 +66,6 @@ require 'date'
66
66
  # #=> 'a:1 AND b:2'
67
67
  class LSolr
68
68
  ArgumentError = Class.new(::ArgumentError)
69
- RangeError = Class.new(::RangeError)
70
69
  TypeError = Class.new(::TypeError)
71
70
  IncompleteQueryError = Class.new(StandardError)
72
71
 
@@ -84,13 +83,15 @@ class LSolr
84
83
  PROXIMITY = '~'
85
84
  BOOST = '^'
86
85
  CONSTANT_SCORE = '^='
87
- PHRASE_MATCH_DELIMITER = ' '
88
- MULTI_VALUE_MATCH_DELIMITER = ' '
89
- FUZZY_MATCH_DISTANCE_RANGE = (0.0..2.0).freeze
90
- FORMAT_DATE_TIME = '%Y-%m-%dT%H:%M:%SZ' # rubocop:disable Style/FormatStringToken
86
+
87
+ DELIMITER_SPACE = ' '
88
+
89
+ RANGE_FUZZY_MATCH_DISTANCE = (0.0..2.0).freeze
90
+
91
+ FORMAT_DATE_TIME = '%Y-%m-%dT%H:%M:%SZ'
91
92
  FORMAT_MILLISECOND_FOR_DATE_TYPE = '%Q'
92
93
  FORMAT_MILLISECOND_FOR_TIME_TYPE = '%L'
93
- FORMAT_SECOND = '%s' # rubocop:disable Style/FormatStringToken
94
+ FORMAT_SECOND = '%s'
94
95
  FORMAT_INSPECT = '#<%<class>s:%<object>#018x `%<query>s`>'
95
96
 
96
97
  PARENTHESIS_LEFT = '('
@@ -114,7 +115,7 @@ class LSolr
114
115
  case params
115
116
  when Hash then params.map { |f, v| build_query(f, v) }.reduce { |a, e| a.and(e) }
116
117
  when String then build_raw_query(params)
117
- else raise TypeError, "Could not build solr query. Please specify a Hash or String value. #{params.inspect} given."
118
+ else raise TypeError, "Could not build solr query. Please specify a Hash or String value. `#{params}` given."
118
119
  end
119
120
  rescue TypeError => e
120
121
  raise ArgumentError, "#{e.message} It is not a supported type."
@@ -130,14 +131,12 @@ class LSolr
130
131
  when Array then build_array_query(field, value)
131
132
  when Range then build_range_query(field, value)
132
133
  when Enumerator then build_enumerator_query(field, value)
133
- else raise TypeError, "Could not build solr query. field: #{field.inspect}, value: #{value.inspect} given."
134
+ else raise TypeError, "Could not build solr query. field: `#{field}`, value: `#{value}` given."
134
135
  end
135
136
  end
136
137
 
137
138
  def build_array_query(field, values)
138
- return new(field) if values.empty?
139
-
140
- new(field).match_in(values)
139
+ values.empty? ? new(field) : new(field).match_in(values)
141
140
  end
142
141
 
143
142
  def build_range_query(field, value)
@@ -220,7 +219,7 @@ class LSolr
220
219
  #
221
220
  # @raise [LSolr::ArgumentError] if specified field name is empty
222
221
  def field(name)
223
- raise ArgumentError, "The field name must be a not empty string value. #{name.inspect} given." unless present_string?(name)
222
+ raise ArgumentError, "The field name must be a not empty string value. `#{name}` given." unless present_string?(name)
224
223
 
225
224
  @field = name.to_s
226
225
  self
@@ -234,7 +233,7 @@ class LSolr
234
233
  #
235
234
  # @raise [LSolr::ArgumentError] if specified raw query string is empty
236
235
  def raw(query)
237
- raise ArgumentError, "The raw query must be a not empty string value. #{query.inspect} given." unless present_string?(query)
236
+ raise ArgumentError, "The raw query must be a not empty string value. `#{query}` given." unless present_string?(query)
238
237
 
239
238
  @raw = query.to_s
240
239
  self
@@ -273,7 +272,7 @@ class LSolr
273
272
  #
274
273
  # @raise [LSolr::ArgumentError] if specified boost factor is invalid
275
274
  def boost(factor)
276
- raise ArgumentError, "The boost factor must be a positive number. #{factor.inspect} given." unless valid_boost_factor?(factor)
275
+ raise ArgumentError, "The boost factor must be a positive number. `#{factor}` given." unless valid_boost_factor?(factor)
277
276
 
278
277
  @boost = "#{BOOST}#{factor}"
279
278
  self
@@ -289,7 +288,7 @@ class LSolr
289
288
  #
290
289
  # @raise [LSolr::ArgumentError] if specified score number is invalid
291
290
  def constant_score(score)
292
- raise ArgumentError, "The constant score must be a number. #{score.inspect} given." unless valid_score?(score)
291
+ raise ArgumentError, "The constant score must be a number. `#{score}` given." unless valid_score?(score)
293
292
 
294
293
  @constant_score = "#{CONSTANT_SCORE}#{score}"
295
294
  self
@@ -319,10 +318,10 @@ class LSolr
319
318
  #
320
319
  # @raise [LSolr::ArgumentError] if specified value is a empty array or not array
321
320
  def match_in(values)
322
- raise ArgumentError, "#{values.inspect} given. It must be a not empty array." unless present_array?(values)
321
+ raise ArgumentError, "`#{values}` given. It must be a not empty array." unless present_array?(values)
323
322
 
324
323
  values = values.map { |v| clean(v) }
325
- @value = "(#{values.join(MULTI_VALUE_MATCH_DELIMITER)})"
324
+ @value = "(#{values.join(DELIMITER_SPACE)})"
326
325
  self
327
326
  end
328
327
 
@@ -361,8 +360,8 @@ class LSolr
361
360
  #
362
361
  # @return [LSolr] self instance
363
362
  def phrase_match(values, distance: 0)
364
- value = values.map { |v| clean(v).split }.flatten.join(PHRASE_MATCH_DELIMITER)
365
- proximity_match = distance > 0 ? "#{PROXIMITY}#{distance}" : ''
363
+ value = values.map { |v| clean(v).split }.flatten.join(DELIMITER_SPACE)
364
+ proximity_match = distance.to_s.to_i > 0 ? "#{PROXIMITY}#{distance}" : ''
366
365
  @value = %("#{value}"#{proximity_match})
367
366
  self
368
367
  end
@@ -376,9 +375,9 @@ class LSolr
376
375
  #
377
376
  # @return [LSolr] self instance
378
377
  #
379
- # @raise [LSolr::RangeError] if specified distance is out of range
378
+ # @raise [LSolr::ArgumentError] if specified distance is out of range
380
379
  def fuzzy_match(value, distance: 2.0)
381
- raise RangeError, "Out of #{FUZZY_MATCH_DISTANCE_RANGE}. #{distance} given." unless FUZZY_MATCH_DISTANCE_RANGE.member?(distance)
380
+ raise ArgumentError, "Out of #{RANGE_FUZZY_MATCH_DISTANCE}. `#{distance}` given." unless valid_fuzzy_match_distance?(distance)
382
381
  @value = "#{clean(value).split.join}#{PROXIMITY}#{distance}"
383
382
  self
384
383
  end
@@ -500,6 +499,10 @@ class LSolr
500
499
  v.is_a?(Float) || v.is_a?(Integer)
501
500
  end
502
501
 
502
+ def valid_fuzzy_match_distance?(v)
503
+ (v.is_a?(Float) || v.is_a?(Integer)) && RANGE_FUZZY_MATCH_DISTANCE.member?(v)
504
+ end
505
+
503
506
  def clean(value, symbols: RESERVED_SYMBOLS)
504
507
  value.to_s
505
508
  .tr(symbols.join, REPLACEMENT_CHAR)
@@ -518,12 +521,12 @@ class LSolr
518
521
  msec_str = case date
519
522
  when Date then date.strftime(FORMAT_MILLISECOND_FOR_DATE_TYPE).gsub(date.strftime(FORMAT_SECOND), '')
520
523
  when Time then date.strftime(FORMAT_MILLISECOND_FOR_TIME_TYPE)
521
- else raise TypeError, "Could not format dates or times. Given value: #{date.inspect}"
524
+ else raise TypeError, "Could not format dates or times. `#{date}` given."
522
525
  end
523
526
 
524
527
  return date.strftime(FORMAT_DATE_TIME) if msec_str == '000'
525
528
 
526
- "#{date.strftime('%Y-%m-%dT%H:%M:%S')}.#{msec_str}Z" # rubocop:disable Style/FormatStringToken
529
+ "#{date.strftime('%Y-%m-%dT%H:%M:%S')}.#{msec_str}Z"
527
530
  end
528
531
 
529
532
  def link(another, operator)
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lsolr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taishi Kasuga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-18 00:00:00.000000000 Z
11
+ date: 2018-02-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: LSolr is a query builder of Apache Solr standard Lucene type query for
14
- Ruby.
13
+ description: LSolr is a query builder for Apache Solr in Ruby. It supports only the
14
+ standard query.
15
15
  email: supercaracal@yahoo.co.jp
16
16
  executables: []
17
17
  extensions: []
@@ -41,5 +41,5 @@ rubyforge_project:
41
41
  rubygems_version: 2.7.4
42
42
  signing_key:
43
43
  specification_version: 4
44
- summary: A query builder of Apache Solr for Ruby
44
+ summary: A query builder for Apache Solr in Ruby
45
45
  test_files: []