riddle 1.5.1 → 1.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. data/.travis.yml +2 -4
  2. data/HISTORY +13 -1
  3. data/README.textile +7 -1
  4. data/lib/riddle/0.9.9/client.rb +8 -8
  5. data/lib/riddle/auto_version.rb +2 -2
  6. data/lib/riddle/client.rb +6 -4
  7. data/lib/riddle/client/filter.rb +16 -11
  8. data/lib/riddle/client/response.rb +19 -19
  9. data/lib/riddle/query.rb +4 -1
  10. data/lib/riddle/version.rb +1 -1
  11. data/spec/fixtures/data/0.9.9/anchor.bin +0 -0
  12. data/spec/fixtures/data/0.9.9/any.bin +0 -0
  13. data/spec/fixtures/data/0.9.9/boolean.bin +0 -0
  14. data/spec/fixtures/data/0.9.9/comment.bin +0 -0
  15. data/spec/fixtures/data/0.9.9/distinct.bin +0 -0
  16. data/spec/fixtures/data/0.9.9/field_weights.bin +0 -0
  17. data/spec/fixtures/data/0.9.9/filter.bin +0 -0
  18. data/spec/fixtures/data/0.9.9/index.bin +0 -0
  19. data/spec/fixtures/data/0.9.9/index_weights.bin +0 -0
  20. data/spec/fixtures/data/0.9.9/overrides.bin +0 -0
  21. data/spec/fixtures/data/0.9.9/phrase.bin +0 -0
  22. data/spec/fixtures/data/0.9.9/rank_mode.bin +0 -0
  23. data/spec/fixtures/data/0.9.9/select.bin +0 -0
  24. data/spec/fixtures/data/0.9.9/simple.bin +0 -0
  25. data/spec/fixtures/data/0.9.9/sort.bin +0 -0
  26. data/spec/fixtures/data/0.9.9/weights.bin +0 -0
  27. data/spec/fixtures/data/1.10/anchor.bin +0 -0
  28. data/spec/fixtures/data/1.10/any.bin +0 -0
  29. data/spec/fixtures/data/1.10/boolean.bin +0 -0
  30. data/spec/fixtures/data/1.10/comment.bin +0 -0
  31. data/spec/fixtures/data/1.10/distinct.bin +0 -0
  32. data/spec/fixtures/data/1.10/field_weights.bin +0 -0
  33. data/spec/fixtures/data/1.10/filter.bin +0 -0
  34. data/spec/fixtures/data/1.10/index.bin +0 -0
  35. data/spec/fixtures/data/1.10/index_weights.bin +0 -0
  36. data/spec/fixtures/data/1.10/overrides.bin +0 -0
  37. data/spec/fixtures/data/1.10/phrase.bin +0 -0
  38. data/spec/fixtures/data/1.10/rank_mode.bin +0 -0
  39. data/spec/fixtures/data/1.10/select.bin +0 -0
  40. data/spec/fixtures/data/1.10/simple.bin +0 -0
  41. data/spec/fixtures/data/1.10/sort.bin +0 -0
  42. data/spec/fixtures/data/1.10/weights.bin +0 -0
  43. data/spec/fixtures/data/2.0.1/anchor.bin +0 -0
  44. data/spec/fixtures/data/2.0.1/any.bin +0 -0
  45. data/spec/fixtures/data/2.0.1/boolean.bin +0 -0
  46. data/spec/fixtures/data/2.0.1/comment.bin +0 -0
  47. data/spec/fixtures/data/2.0.1/distinct.bin +0 -0
  48. data/spec/fixtures/data/2.0.1/field_weights.bin +0 -0
  49. data/spec/fixtures/data/2.0.1/filter.bin +0 -0
  50. data/spec/fixtures/data/2.0.1/index.bin +0 -0
  51. data/spec/fixtures/data/2.0.1/index_weights.bin +0 -0
  52. data/spec/fixtures/data/2.0.1/overrides.bin +0 -0
  53. data/spec/fixtures/data/2.0.1/phrase.bin +0 -0
  54. data/spec/fixtures/data/2.0.1/rank_mode.bin +0 -0
  55. data/spec/fixtures/data/2.0.1/select.bin +0 -0
  56. data/spec/fixtures/data/2.0.1/simple.bin +0 -0
  57. data/spec/fixtures/data/2.0.1/sort.bin +0 -0
  58. data/spec/fixtures/data/2.0.1/weights.bin +0 -0
  59. data/spec/fixtures/data/2.1.0/anchor.bin +0 -0
  60. data/spec/fixtures/data/2.1.0/any.bin +0 -0
  61. data/spec/fixtures/data/2.1.0/boolean.bin +0 -0
  62. data/spec/fixtures/data/2.1.0/comment.bin +0 -0
  63. data/spec/fixtures/data/2.1.0/distinct.bin +0 -0
  64. data/spec/fixtures/data/2.1.0/field_weights.bin +0 -0
  65. data/spec/fixtures/data/2.1.0/filter.bin +0 -0
  66. data/spec/fixtures/data/2.1.0/index.bin +0 -0
  67. data/spec/fixtures/data/2.1.0/index_weights.bin +0 -0
  68. data/spec/fixtures/data/2.1.0/overrides.bin +0 -0
  69. data/spec/fixtures/data/2.1.0/phrase.bin +0 -0
  70. data/spec/fixtures/data/2.1.0/rank_mode.bin +0 -0
  71. data/spec/fixtures/data/2.1.0/select.bin +0 -0
  72. data/spec/fixtures/data/2.1.0/simple.bin +0 -0
  73. data/spec/fixtures/data/2.1.0/sort.bin +0 -0
  74. data/spec/fixtures/data/2.1.0/weights.bin +0 -0
  75. data/spec/fixtures/sphinxapi.0.9.8.php +8 -8
  76. data/spec/fixtures/sphinxapi.0.9.9.php +26 -26
  77. data/spec/fixtures/sphinxapi.1.10.php +27 -27
  78. data/spec/fixtures/sphinxapi.2.0.1.php +27 -27
  79. data/spec/fixtures/sphinxapi.2.1.0.php +2 -2
  80. data/spec/riddle/auto_version_spec.rb +14 -0
  81. data/spec/riddle/query_spec.rb +13 -8
  82. data/spec/unit/client_spec.rb +22 -0
  83. metadata +76 -49
data/.travis.yml CHANGED
@@ -1,12 +1,10 @@
1
+ language: ruby
1
2
  rvm:
2
- - 1.8.6
3
3
  - 1.8.7
4
4
  - 1.9.2
5
5
  - 1.9.3
6
- - rbx
7
- - rbx-2.0
8
6
  - ree
9
- - jruby
7
+ - jruby-18mode
10
8
  - ruby-head
11
9
  env:
12
10
  - SPHINX_BIN=/usr/local/sphinx-0.9.9/bin SPHINX_VERSION=0.9.9
data/HISTORY CHANGED
@@ -1,4 +1,16 @@
1
- 1.5.1 - January 2nd 2011
1
+ 1.5.2 - May 14th 2012
2
+ - Fixing 64-bit MVA support.
3
+ - Grouped searches now sort by weight instead of by group as a default. You can change this setting via Riddle::Client#group_clause.
4
+ - Use a local array of servers - don't clear the main set (S. Christoffer Eliesen).
5
+ - Fixing VersionError reference for Sphinx 0.9.9 or better (S. Christoffer Eliesen).
6
+ - Consistent documentation for default port: 9312 (Aleksey Morozov).
7
+ - Sphinx 2.0.4 support (Ilia Lobsanov).
8
+ - Handle single-value float filters (by translating them to a range) (Steven Bristol).
9
+ - Sphinx 2.0.2-dev handled as Sphinx 2.0.1.
10
+ - Sphinx 2.0.3 support.
11
+ - String options handled appropriately for SphinxQL excerpts calls.
12
+
13
+ 1.5.1 - January 2nd 2012
2
14
  - If no known servers work, raise an appropriate error.
3
15
  - Sphinx 2.1.0-dev support.
4
16
 
data/README.textile CHANGED
@@ -1,5 +1,7 @@
1
1
  h1. Riddle
2
2
 
3
+ "!https://secure.travis-ci.org/freelancing-god/riddle.png!":http://travis-ci.org/freelancing-god/riddle
4
+
3
5
  This client has been written to interface with "Sphinx":http://sphinxsearch.com/. It is written by "Pat Allan":http://freelancing-gods.com, and has been influenced by both Dmytro Shteflyuk's Ruby client and the original PHP client - credit where credit's due, after all.
4
6
 
5
7
  It does not follow the same syntax as those two, though (not much point writing this otherwise) - opting for a more Ruby-like structure.
@@ -17,7 +19,7 @@ require 'riddle/0.9.9'</code></pre>
17
19
 
18
20
  To get started, just instantiate a Client object:
19
21
 
20
- <pre><code>client = Riddle::Client.new # defaults to localhost and port 3312
22
+ <pre><code>client = Riddle::Client.new # defaults to localhost and port 9312
21
23
  client = Riddle::Client.new "sphinxserver.domain.tld", 3333 # custom settings</code></pre>
22
24
 
23
25
  And then set the parameters to what you want, before running a query:
@@ -83,3 +85,7 @@ Thanks to the following people who have contributed to Riddle in some shape or f
83
85
  * Paul Gibler
84
86
  * Ngan Pham
85
87
  * Aaron Gilbralter
88
+ * Steven Bristol
89
+ * Ilia Lobsanov
90
+ * Aleksey Morozov
91
+ * S. Christoffer Eliesen
@@ -3,33 +3,33 @@ Riddle::Client::Versions[:update] = 0x102
3
3
 
4
4
  class Riddle::Client
5
5
  private
6
-
6
+
7
7
  def initialise_connection
8
8
  socket = initialise_socket
9
9
 
10
10
  # Send version
11
11
  socket.send [1].pack('N'), 0
12
-
12
+
13
13
  # Checking version
14
14
  version = socket.recv(4).unpack('N*').first
15
15
  if version < 1
16
16
  socket.close
17
- raise VersionError, "Can only connect to searchd version 1.0 or better, not version #{version}"
17
+ raise Riddle::VersionError, "Can only connect to searchd version 1.0 or better, not version #{version}"
18
18
  end
19
-
19
+
20
20
  socket
21
21
  end
22
-
22
+
23
23
  def update_message(index, attributes, values_by_doc)
24
24
  message = Message.new
25
-
25
+
26
26
  message.append_string index
27
27
  message.append_int attributes.length
28
28
  attributes.each_with_index do |attribute, index|
29
29
  message.append_string attribute
30
30
  message.append_boolean values_by_doc.values.first[index].is_a?(Array)
31
31
  end
32
-
32
+
33
33
  message.append_int values_by_doc.length
34
34
  values_by_doc.each do |key,values|
35
35
  message.append_64bit_int key # document ID
@@ -43,7 +43,7 @@ class Riddle::Client
43
43
  end
44
44
  end
45
45
  end
46
-
46
+
47
47
  message.to_s
48
48
  end
49
49
  end
@@ -8,9 +8,9 @@ class Riddle::AutoVersion
8
8
  require "riddle/#{version}"
9
9
  when /1.10/
10
10
  require 'riddle/1.10'
11
- when /2.0.\d/
11
+ when /2.0.[12]/
12
12
  require 'riddle/2.0.1'
13
- when /2.1.\d/
13
+ when /2.0.3/, /2.0.4/, /2.1.\d/
14
14
  require 'riddle/2.1.0'
15
15
  end
16
16
  end
data/lib/riddle/client.rb CHANGED
@@ -136,7 +136,7 @@ module Riddle
136
136
  end
137
137
 
138
138
  # Can instantiate with a specific server and port - otherwise it assumes
139
- # defaults of localhost and 3312 respectively. All other settings can be
139
+ # defaults of localhost and 9312 respectively. All other settings can be
140
140
  # accessed and changed via the attribute accessors.
141
141
  def initialize(servers = nil, port = nil, key = nil)
142
142
  Riddle.version_warning
@@ -165,7 +165,7 @@ module Riddle
165
165
  @filters = []
166
166
  @group_by = ''
167
167
  @group_function = :day
168
- @group_clause = '@group desc'
168
+ @group_clause = '@weight DESC'
169
169
  @group_distinct = ''
170
170
  @cut_off = 0
171
171
  @retry_count = 0
@@ -495,6 +495,8 @@ module Riddle
495
495
  def open_socket
496
496
  raise "Already Connected" unless @socket.nil?
497
497
 
498
+ available_servers = servers.dup
499
+
498
500
  if @timeout == 0
499
501
  @socket = initialise_connection
500
502
  else
@@ -502,8 +504,8 @@ module Riddle
502
504
  Timeout.timeout(@timeout) { @socket = initialise_connection }
503
505
  rescue Timeout::Error, Riddle::ConnectionError => e
504
506
  failed_servers ||= []
505
- failed_servers << servers.shift
506
- retry if !servers.empty?
507
+ failed_servers << available_servers.shift
508
+ retry if !available_servers.empty?
507
509
 
508
510
  case e
509
511
  when Timeout::Error
@@ -2,21 +2,21 @@ module Riddle
2
2
  class Client
3
3
  class Filter
4
4
  attr_accessor :attribute, :values, :exclude
5
-
5
+
6
6
  # Attribute name, values (which can be an array or a range), and whether
7
7
  # the filter should be exclusive.
8
8
  def initialize(attribute, values, exclude=false)
9
9
  @attribute, @values, @exclude = attribute, values, exclude
10
10
  end
11
-
11
+
12
12
  def exclude?
13
13
  self.exclude
14
14
  end
15
-
15
+
16
16
  # Returns the message for this filter to send to the Sphinx service
17
17
  def query_message
18
18
  message = Message.new
19
-
19
+
20
20
  message.append_string self.attribute.to_s
21
21
  case self.values
22
22
  when Range
@@ -28,21 +28,26 @@ module Riddle
28
28
  append_integer_range message, self.values
29
29
  end
30
30
  when Array
31
- message.append_int FilterTypes[:values]
32
- message.append_int self.values.length
33
- append_array message, self.values
31
+ if self.values.first.is_a?(Float) && self.values.length == 1
32
+ message.append_int FilterTypes[:float_range]
33
+ message.append_floats self.values.first, self.values.first
34
+ else
35
+ message.append_int FilterTypes[:values]
36
+ message.append_int self.values.length
37
+ append_array message, self.values
38
+ end
34
39
  end
35
40
  message.append_int self.exclude? ? 1 : 0
36
-
41
+
37
42
  message.to_s
38
43
  end
39
-
44
+
40
45
  private
41
-
46
+
42
47
  def append_integer_range(message, range)
43
48
  message.append_ints self.values.first, self.values.last
44
49
  end
45
-
50
+
46
51
  # Using to_f is a hack from the PHP client - to workaround 32bit signed
47
52
  # ints on x32 platforms
48
53
  def append_array(message, array)
@@ -10,39 +10,39 @@ module Riddle
10
10
  @str = str
11
11
  @marker = 0
12
12
  end
13
-
13
+
14
14
  # Return the next string value in the stream
15
15
  def next
16
16
  len = next_int
17
17
  result = @str[@marker, len]
18
18
  @marker += len
19
-
19
+
20
20
  Riddle.encode(result)
21
21
  end
22
-
22
+
23
23
  # Return the next integer value from the stream
24
24
  def next_int
25
25
  int = @str[@marker, 4].unpack('N*').first
26
26
  @marker += 4
27
-
27
+
28
28
  int
29
29
  end
30
-
30
+
31
31
  def next_64bit_int
32
32
  high, low = @str[@marker, 8].unpack('N*N*')[0..1]
33
33
  @marker += 8
34
-
34
+
35
35
  (high << 32) + low
36
36
  end
37
-
37
+
38
38
  # Return the next float value from the stream
39
39
  def next_float
40
40
  float = @str[@marker, 4].unpack('N*').pack('L').unpack('f*').first
41
41
  @marker += 4
42
-
42
+
43
43
  float
44
44
  end
45
-
45
+
46
46
  # Returns an array of string items
47
47
  def next_array
48
48
  count = next_int
@@ -50,10 +50,10 @@ module Riddle
50
50
  count.times do
51
51
  items << self.next
52
52
  end
53
-
53
+
54
54
  items
55
55
  end
56
-
56
+
57
57
  # Returns an array of int items
58
58
  def next_int_array
59
59
  count = next_int
@@ -61,30 +61,30 @@ module Riddle
61
61
  count.times do
62
62
  items << self.next_int
63
63
  end
64
-
64
+
65
65
  items
66
66
  end
67
-
67
+
68
68
  def next_float_array
69
69
  count = next_int
70
70
  items = []
71
71
  count.times do
72
72
  items << self.next_float
73
73
  end
74
-
74
+
75
75
  items
76
76
  end
77
-
77
+
78
78
  def next_64bit_int_array
79
- count = next_int
79
+ byte_count = next_int
80
80
  items = []
81
- count.times do
81
+ (byte_count / 2).times do
82
82
  items << self.next_64bit_int
83
83
  end
84
-
84
+
85
85
  items
86
86
  end
87
-
87
+
88
88
  # Returns the length of the streamed data
89
89
  def length
90
90
  @str.length
data/lib/riddle/query.rb CHANGED
@@ -59,7 +59,10 @@ module Riddle::Query
59
59
 
60
60
  def self.snippets(data, index, query, options = nil)
61
61
  options = ', ' + options.keys.collect { |key|
62
- "#{options[key]} AS #{key}"
62
+ value = options[key]
63
+ value = "'#{value}'" if value.is_a?(String)
64
+
65
+ "#{value} AS #{key}"
63
66
  }.join(', ') unless options.nil?
64
67
 
65
68
  "CALL SNIPPETS('#{data}', '#{index}', '#{query}'#{options})"
@@ -1,3 +1,3 @@
1
1
  module Riddle
2
- Version = '1.5.1'
2
+ Version = '1.5.2'
3
3
  end
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file