riddle 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -5
  3. data/Gemfile +10 -0
  4. data/HISTORY +4 -0
  5. data/README.markdown +1 -1
  6. data/lib/riddle.rb +1 -0
  7. data/lib/riddle/0.9.9/configuration/searchd.rb +1 -1
  8. data/lib/riddle/client.rb +4 -1
  9. data/lib/riddle/client/message.rb +15 -14
  10. data/lib/riddle/configuration/parser.rb +1 -0
  11. data/lib/riddle/configuration/section.rb +9 -9
  12. data/lib/riddle/configuration/source.rb +5 -5
  13. data/lib/riddle/query/select.rb +3 -2
  14. data/riddle.gemspec +2 -4
  15. metadata +4 -329
  16. data/spec/fixtures/.gitignore +0 -2
  17. data/spec/fixtures/data/0.9.9/anchor.bin +0 -0
  18. data/spec/fixtures/data/0.9.9/any.bin +0 -0
  19. data/spec/fixtures/data/0.9.9/boolean.bin +0 -0
  20. data/spec/fixtures/data/0.9.9/comment.bin +0 -0
  21. data/spec/fixtures/data/0.9.9/distinct.bin +0 -0
  22. data/spec/fixtures/data/0.9.9/field_weights.bin +0 -0
  23. data/spec/fixtures/data/0.9.9/filter.bin +0 -0
  24. data/spec/fixtures/data/0.9.9/filter_array.bin +0 -0
  25. data/spec/fixtures/data/0.9.9/filter_array_exclude.bin +0 -0
  26. data/spec/fixtures/data/0.9.9/filter_boolean.bin +0 -0
  27. data/spec/fixtures/data/0.9.9/filter_floats.bin +0 -0
  28. data/spec/fixtures/data/0.9.9/filter_floats_exclude.bin +0 -0
  29. data/spec/fixtures/data/0.9.9/filter_range.bin +0 -0
  30. data/spec/fixtures/data/0.9.9/filter_range_exclude.bin +0 -0
  31. data/spec/fixtures/data/0.9.9/group.bin +0 -0
  32. data/spec/fixtures/data/0.9.9/index.bin +0 -0
  33. data/spec/fixtures/data/0.9.9/index_weights.bin +0 -0
  34. data/spec/fixtures/data/0.9.9/keywords_with_hits.bin +0 -0
  35. data/spec/fixtures/data/0.9.9/keywords_without_hits.bin +0 -0
  36. data/spec/fixtures/data/0.9.9/overrides.bin +0 -0
  37. data/spec/fixtures/data/0.9.9/phrase.bin +0 -0
  38. data/spec/fixtures/data/0.9.9/rank_mode.bin +0 -0
  39. data/spec/fixtures/data/0.9.9/select.bin +0 -0
  40. data/spec/fixtures/data/0.9.9/simple.bin +0 -0
  41. data/spec/fixtures/data/0.9.9/sort.bin +0 -0
  42. data/spec/fixtures/data/0.9.9/update_simple.bin +0 -0
  43. data/spec/fixtures/data/0.9.9/weights.bin +0 -0
  44. data/spec/fixtures/data/1.10/anchor.bin +0 -0
  45. data/spec/fixtures/data/1.10/any.bin +0 -0
  46. data/spec/fixtures/data/1.10/boolean.bin +0 -0
  47. data/spec/fixtures/data/1.10/comment.bin +0 -0
  48. data/spec/fixtures/data/1.10/distinct.bin +0 -0
  49. data/spec/fixtures/data/1.10/field_weights.bin +0 -0
  50. data/spec/fixtures/data/1.10/filter.bin +0 -0
  51. data/spec/fixtures/data/1.10/filter_array.bin +0 -0
  52. data/spec/fixtures/data/1.10/filter_array_exclude.bin +0 -0
  53. data/spec/fixtures/data/1.10/filter_boolean.bin +0 -0
  54. data/spec/fixtures/data/1.10/filter_floats.bin +0 -0
  55. data/spec/fixtures/data/1.10/filter_floats_exclude.bin +0 -0
  56. data/spec/fixtures/data/1.10/filter_range.bin +0 -0
  57. data/spec/fixtures/data/1.10/filter_range_exclude.bin +0 -0
  58. data/spec/fixtures/data/1.10/group.bin +0 -0
  59. data/spec/fixtures/data/1.10/index.bin +0 -0
  60. data/spec/fixtures/data/1.10/index_weights.bin +0 -0
  61. data/spec/fixtures/data/1.10/keywords_with_hits.bin +0 -0
  62. data/spec/fixtures/data/1.10/keywords_without_hits.bin +0 -0
  63. data/spec/fixtures/data/1.10/overrides.bin +0 -0
  64. data/spec/fixtures/data/1.10/phrase.bin +0 -0
  65. data/spec/fixtures/data/1.10/rank_mode.bin +0 -0
  66. data/spec/fixtures/data/1.10/select.bin +0 -0
  67. data/spec/fixtures/data/1.10/simple.bin +0 -0
  68. data/spec/fixtures/data/1.10/sort.bin +0 -0
  69. data/spec/fixtures/data/1.10/update_simple.bin +0 -0
  70. data/spec/fixtures/data/1.10/weights.bin +0 -0
  71. data/spec/fixtures/data/2.0.1/anchor.bin +0 -0
  72. data/spec/fixtures/data/2.0.1/any.bin +0 -0
  73. data/spec/fixtures/data/2.0.1/boolean.bin +0 -0
  74. data/spec/fixtures/data/2.0.1/comment.bin +0 -0
  75. data/spec/fixtures/data/2.0.1/distinct.bin +0 -0
  76. data/spec/fixtures/data/2.0.1/field_weights.bin +0 -0
  77. data/spec/fixtures/data/2.0.1/filter.bin +0 -0
  78. data/spec/fixtures/data/2.0.1/filter_array.bin +0 -0
  79. data/spec/fixtures/data/2.0.1/filter_array_exclude.bin +0 -0
  80. data/spec/fixtures/data/2.0.1/filter_boolean.bin +0 -0
  81. data/spec/fixtures/data/2.0.1/filter_floats.bin +0 -0
  82. data/spec/fixtures/data/2.0.1/filter_floats_exclude.bin +0 -0
  83. data/spec/fixtures/data/2.0.1/filter_range.bin +0 -0
  84. data/spec/fixtures/data/2.0.1/filter_range_exclude.bin +0 -0
  85. data/spec/fixtures/data/2.0.1/group.bin +0 -0
  86. data/spec/fixtures/data/2.0.1/index.bin +0 -0
  87. data/spec/fixtures/data/2.0.1/index_weights.bin +0 -0
  88. data/spec/fixtures/data/2.0.1/keywords_with_hits.bin +0 -0
  89. data/spec/fixtures/data/2.0.1/keywords_without_hits.bin +0 -0
  90. data/spec/fixtures/data/2.0.1/overrides.bin +0 -0
  91. data/spec/fixtures/data/2.0.1/phrase.bin +0 -0
  92. data/spec/fixtures/data/2.0.1/rank_mode.bin +0 -0
  93. data/spec/fixtures/data/2.0.1/select.bin +0 -0
  94. data/spec/fixtures/data/2.0.1/simple.bin +0 -0
  95. data/spec/fixtures/data/2.0.1/sort.bin +0 -0
  96. data/spec/fixtures/data/2.0.1/update_simple.bin +0 -0
  97. data/spec/fixtures/data/2.0.1/weights.bin +0 -0
  98. data/spec/fixtures/data/2.1.0/anchor.bin +0 -0
  99. data/spec/fixtures/data/2.1.0/any.bin +0 -0
  100. data/spec/fixtures/data/2.1.0/boolean.bin +0 -0
  101. data/spec/fixtures/data/2.1.0/comment.bin +0 -0
  102. data/spec/fixtures/data/2.1.0/distinct.bin +0 -0
  103. data/spec/fixtures/data/2.1.0/field_weights.bin +0 -0
  104. data/spec/fixtures/data/2.1.0/filter.bin +0 -0
  105. data/spec/fixtures/data/2.1.0/filter_array.bin +0 -0
  106. data/spec/fixtures/data/2.1.0/filter_array_exclude.bin +0 -0
  107. data/spec/fixtures/data/2.1.0/filter_boolean.bin +0 -0
  108. data/spec/fixtures/data/2.1.0/filter_floats.bin +0 -0
  109. data/spec/fixtures/data/2.1.0/filter_floats_exclude.bin +0 -0
  110. data/spec/fixtures/data/2.1.0/filter_range.bin +0 -0
  111. data/spec/fixtures/data/2.1.0/filter_range_exclude.bin +0 -0
  112. data/spec/fixtures/data/2.1.0/group.bin +0 -0
  113. data/spec/fixtures/data/2.1.0/index.bin +0 -0
  114. data/spec/fixtures/data/2.1.0/index_weights.bin +0 -0
  115. data/spec/fixtures/data/2.1.0/keywords_with_hits.bin +0 -0
  116. data/spec/fixtures/data/2.1.0/keywords_without_hits.bin +0 -0
  117. data/spec/fixtures/data/2.1.0/overrides.bin +0 -0
  118. data/spec/fixtures/data/2.1.0/phrase.bin +0 -0
  119. data/spec/fixtures/data/2.1.0/rank_mode.bin +0 -0
  120. data/spec/fixtures/data/2.1.0/select.bin +0 -0
  121. data/spec/fixtures/data/2.1.0/simple.bin +0 -0
  122. data/spec/fixtures/data/2.1.0/sort.bin +0 -0
  123. data/spec/fixtures/data/2.1.0/update_simple.bin +0 -0
  124. data/spec/fixtures/data/2.1.0/weights.bin +0 -0
  125. data/spec/fixtures/data_generator.0.9.8.php +0 -208
  126. data/spec/fixtures/data_generator.0.9.9.php +0 -5
  127. data/spec/fixtures/data_generator.1.10.php +0 -5
  128. data/spec/fixtures/data_generator.2.0.1.php +0 -5
  129. data/spec/fixtures/data_generator.2.1.0.php +0 -5
  130. data/spec/fixtures/data_generator.php +0 -223
  131. data/spec/fixtures/sphinxapi.0.9.8.php +0 -1228
  132. data/spec/fixtures/sphinxapi.0.9.9.php +0 -1646
  133. data/spec/fixtures/sphinxapi.1.10.php +0 -1728
  134. data/spec/fixtures/sphinxapi.2.0.1.php +0 -1731
  135. data/spec/fixtures/sphinxapi.2.1.0.php +0 -1752
  136. data/spec/fixtures/sql/conf.example.yml +0 -3
  137. data/spec/fixtures/sql/data.sql +0 -25000
  138. data/spec/fixtures/sql/data.tsv +0 -25000
  139. data/spec/fixtures/sql/structure.sql +0 -16
  140. data/spec/functional/connection_spec.rb +0 -64
  141. data/spec/functional/escaping_spec.rb +0 -49
  142. data/spec/functional/excerpt_spec.rb +0 -139
  143. data/spec/functional/keywords_spec.rb +0 -40
  144. data/spec/functional/persistance_spec.rb +0 -17
  145. data/spec/functional/search_spec.rb +0 -67
  146. data/spec/functional/status_spec.rb +0 -21
  147. data/spec/functional/update_spec.rb +0 -41
  148. data/spec/riddle/auto_version_spec.rb +0 -95
  149. data/spec/riddle/client_spec.rb +0 -11
  150. data/spec/riddle/configuration_spec.rb +0 -28
  151. data/spec/riddle/controller_spec.rb +0 -39
  152. data/spec/riddle/query/delete_spec.rb +0 -18
  153. data/spec/riddle/query/insert_spec.rb +0 -25
  154. data/spec/riddle/query/select_spec.rb +0 -226
  155. data/spec/riddle/query_spec.rb +0 -97
  156. data/spec/riddle_spec.rb +0 -27
  157. data/spec/spec_helper.rb +0 -34
  158. data/spec/support/binary_fixtures.rb +0 -18
  159. data/spec/support/sphinx.rb +0 -137
  160. data/spec/unit/client_spec.rb +0 -290
  161. data/spec/unit/configuration/common_spec.rb +0 -60
  162. data/spec/unit/configuration/distributed_index_spec.rb +0 -58
  163. data/spec/unit/configuration/index_spec.rb +0 -124
  164. data/spec/unit/configuration/indexer_spec.rb +0 -73
  165. data/spec/unit/configuration/realtime_index_spec.rb +0 -65
  166. data/spec/unit/configuration/searchd_spec.rb +0 -228
  167. data/spec/unit/configuration/source_spec.rb +0 -5
  168. data/spec/unit/configuration/sql_source_spec.rb +0 -137
  169. data/spec/unit/configuration/template_index_spec.rb +0 -91
  170. data/spec/unit/configuration/tsv_source_spec.rb +0 -53
  171. data/spec/unit/configuration/xml_source_spec.rb +0 -51
  172. data/spec/unit/configuration_spec.rb +0 -25
  173. data/spec/unit/filter_spec.rb +0 -38
  174. data/spec/unit/message_spec.rb +0 -94
  175. data/spec/unit/response_spec.rb +0 -64
  176. data/spec/unit/riddle_spec.rb +0 -17
@@ -1,97 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Query, :live => true do
4
- describe '.connection' do
5
- let(:connection) { Riddle::Query.connection 'localhost', 9306 }
6
-
7
- it "returns a MySQL Client" do
8
- connection.should be_a(Mysql2::Client)
9
- end
10
-
11
- it "should handle search requests" do
12
- connection.query(Riddle::Query.tables).to_a[0].should == {
13
- 'Index' => 'people', 'Type' => 'local'
14
- }
15
- end
16
- end
17
- end unless RUBY_PLATFORM == 'java' || Riddle.loaded_version.to_i < 2
18
-
19
- describe Riddle::Query do
20
- describe '.set' do
21
- it 'handles a single value' do
22
- Riddle::Query.set('foo', 'bar').should == 'SET GLOBAL foo = bar'
23
- end
24
-
25
- it 'handles multiple values' do
26
- Riddle::Query.set('foo', [1, 2, 3]).should == 'SET GLOBAL foo = (1, 2, 3)'
27
- end
28
-
29
- it 'handles non-global settings' do
30
- Riddle::Query.set('foo', 'bar', false).should == 'SET foo = bar'
31
- end
32
- end
33
-
34
- describe '.snippets' do
35
- it 'handles a basic request' do
36
- Riddle::Query.snippets('foo bar baz', 'foo_core', 'foo').
37
- should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo')"
38
- end
39
-
40
- it 'handles a request with options' do
41
- Riddle::Query.snippets('foo bar baz', 'foo_core', 'foo', :around => 5).
42
- should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo', 5 AS around)"
43
- end
44
-
45
- it 'handles string options' do
46
- Riddle::Query.snippets('foo bar baz', 'foo_core', 'foo',
47
- :before_match => '<strong>').should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo', '<strong>' AS before_match)"
48
- end
49
-
50
- it "handles boolean options" do
51
- Riddle::Query.snippets('foo bar baz', 'foo_core', 'foo',
52
- :exact_phrase => true).should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo', 1 AS exact_phrase)"
53
- end
54
-
55
- it "escapes quotes in the text data" do
56
- Riddle::Query.snippets("foo bar 'baz", 'foo_core', 'foo').
57
- should == "CALL SNIPPETS('foo bar \\'baz', 'foo_core', 'foo')"
58
- end
59
-
60
- it "escapes quotes in the query data" do
61
- Riddle::Query.snippets("foo bar baz", 'foo_core', "foo'").
62
- should == "CALL SNIPPETS('foo bar baz', 'foo_core', 'foo\\'')"
63
- end
64
- end
65
-
66
- describe '.create_function' do
67
- it 'handles a basic create request' do
68
- Riddle::Query.create_function('foo', :bigint, 'foo.sh').
69
- should == "CREATE FUNCTION foo RETURNS BIGINT SONAME 'foo.sh'"
70
- end
71
- end
72
-
73
- describe '.update' do
74
- it 'handles a basic update request' do
75
- Riddle::Query.update('foo_core', 5, :deleted => 1).
76
- should == 'UPDATE foo_core SET deleted = 1 WHERE id = 5'
77
- end
78
- end
79
-
80
- describe '.escape' do
81
- %w(( ) | - ! @ ~ / ^ $ " > < ?).each do |reserved|
82
- it "escapes #{reserved}" do
83
- Riddle::Query.escape(reserved).should == "\\#{reserved}"
84
- end
85
- end
86
-
87
- it "escapes word-operators correctly" do
88
- operators = ['MAYBE', 'NEAR', 'PARAGRAPH', 'SENTENCE', 'ZONE', 'ZONESPAN']
89
- operators.each do |operator|
90
- base = "string with #{operator} operator"
91
- Riddle::Query.escape(base).should == base.gsub(operator, "\\#{operator}")
92
- end
93
-
94
- Riddle::Query.escape("FIND THE ZONES").should == "FIND THE ZONES"
95
- end
96
- end
97
- end
data/spec/riddle_spec.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle do
4
- describe '.version_warning' do
5
- before :each do
6
- @existing_version = Riddle.loaded_version
7
- end
8
-
9
- after :each do
10
- Riddle.loaded_version = @existing_version
11
- end
12
-
13
- it "should do nothing if there is a Sphinx version loaded" do
14
- STDERR.should_not_receive(:puts)
15
-
16
- Riddle.loaded_version = '0.9.8'
17
- Riddle.version_warning
18
- end
19
-
20
- it "should output a warning if no version is loaded" do
21
- STDERR.should_receive(:puts)
22
-
23
- Riddle.loaded_version = nil
24
- Riddle.version_warning
25
- end
26
- end
27
- end
data/spec/spec_helper.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
-
4
- $:.unshift File.dirname(__FILE__) + '/../lib'
5
- $:.unshift File.dirname(__FILE__) + '/..'
6
-
7
- Dir['spec/support/**/*.rb'].each { |f| require f }
8
-
9
- Bundler.require :default, :development
10
-
11
- require 'riddle'
12
-
13
- RSpec.configure do |config|
14
- config.include BinaryFixtures
15
-
16
- sphinx = Sphinx.new
17
- sphinx.setup_mysql
18
- sphinx.generate_configuration
19
- sphinx.index
20
-
21
- BinaryFixtures.build_fixtures Riddle.loaded_version
22
-
23
- config.before :all do |group|
24
- sphinx.start if group.class.metadata[:live]
25
- end
26
-
27
- config.after :all do |group|
28
- sphinx.stop if group.class.metadata[:live]
29
- end
30
-
31
- # enable filtering for examples
32
- config.filter_run :wip => true
33
- config.run_all_when_everything_filtered = true
34
- end
@@ -1,18 +0,0 @@
1
- module BinaryFixtures
2
- def self.build_fixtures(version = nil)
3
- return if ENV['TRAVIS']
4
-
5
- version ||= %w(0.9.9 1.10 2.0.1 2.1.0)
6
- Array(version).each do |version|
7
- FileUtils.mkdir_p "spec/fixtures/data/#{version}"
8
- `php -f spec/fixtures/data_generator.#{version}.php`
9
- end
10
- end
11
-
12
- def query_contents(key)
13
- path = "spec/fixtures/data/#{Riddle.loaded_version}/#{key}.bin"
14
- contents = open(path) { |f| f.read }
15
- contents.respond_to?(:encoding) ?
16
- contents.force_encoding('ASCII-8BIT') : contents
17
- end
18
- end
@@ -1,137 +0,0 @@
1
- require 'erb'
2
- require 'yaml'
3
-
4
- if RUBY_PLATFORM == 'java'
5
- require 'java'
6
- require 'jdbc/mysql'
7
- end
8
-
9
- class Sphinx
10
- attr_accessor :host, :username, :password
11
-
12
- def initialize
13
- self.host = 'localhost'
14
- self.username = 'root'
15
- self.password = ''
16
-
17
- if File.exist?('spec/fixtures/sql/conf.yml')
18
- config = YAML.load(File.open('spec/fixtures/sql/conf.yml'))
19
- self.host = config['host']
20
- self.username = config['username']
21
- self.password = config['password']
22
- end
23
- end
24
-
25
- def setup_mysql
26
- return setup_mysql_on_jruby if RUBY_PLATFORM == 'java'
27
-
28
- client = Mysql2::Client.new(
29
- :host => host,
30
- :username => username,
31
- :password => password
32
- )
33
-
34
- databases = client.query('SHOW DATABASES', :as => :array).to_a.flatten
35
- unless databases.include?('riddle')
36
- client.query 'CREATE DATABASE riddle'
37
- end
38
-
39
- client.query 'USE riddle'
40
-
41
- structure = File.open('spec/fixtures/sql/structure.sql') { |f| f.read }
42
- structure.split(/;/).each { |sql| client.query sql }
43
- client.query <<-SQL
44
- LOAD DATA INFILE '#{fixtures_path}/sql/data.tsv' INTO TABLE
45
- `riddle`.`people` FIELDS TERMINATED BY ',' ENCLOSED BY "'" (gender,
46
- first_name, middle_initial, last_name, street_address, city, state,
47
- postcode, email, birthday)
48
- SQL
49
-
50
- client.close
51
- end
52
-
53
- def setup_mysql_on_jruby
54
- address = "jdbc:mysql://#{host}"
55
- client = java.sql.DriverManager.getConnection(address, username, password)
56
-
57
- set = client.createStatement.executeQuery('SHOW DATABASES')
58
- databases = []
59
- databases << set.getString(1) while set.next
60
-
61
- unless databases.include?('riddle')
62
- client.createStatement.execute 'CREATE DATABASE riddle'
63
- end
64
-
65
- client.createStatement.execute 'USE riddle'
66
-
67
- structure = File.open('spec/fixtures/sql/structure.sql') { |f| f.read }
68
- structure.split(/;/).each { |sql| client.createStatement.execute sql }
69
- client.createStatement.execute <<-SQL
70
- LOAD DATA INFILE '#{fixtures_path}/sql/data.tsv' INTO TABLE
71
- `riddle`.`people` FIELDS TERMINATED BY ',' ENCLOSED BY "'" (gender,
72
- first_name, middle_initial, last_name, street_address, city, state,
73
- postcode, email, birthday)
74
- SQL
75
- end
76
-
77
- def generate_configuration
78
- template = File.open('spec/fixtures/sphinx/configuration.erb') { |f| f.read }
79
- File.open('spec/fixtures/sphinx/spec.conf', 'w') { |f|
80
- f.puts ERB.new(template).result(binding)
81
- }
82
-
83
- FileUtils.mkdir_p "spec/fixtures/sphinx/binlog"
84
- end
85
-
86
- def index
87
- cmd = "#{bin_path}indexer --config #{fixtures_path}/sphinx/spec.conf --all"
88
- cmd << ' --rotate' if running?
89
- `#{cmd}`
90
- end
91
-
92
- def start
93
- return if running?
94
-
95
- `#{bin_path}searchd --config #{fixtures_path}/sphinx/spec.conf`
96
-
97
- sleep(1)
98
-
99
- unless running?
100
- puts 'Failed to start searchd daemon. Check fixtures/sphinx/searchd.log.'
101
- end
102
- end
103
-
104
- def stop
105
- return unless running?
106
-
107
- stop_flag = '--stopwait'
108
- stop_flag = '--stop' if Riddle.loaded_version.to_i < 1
109
- `#{bin_path}searchd --config #{fixtures_path}/sphinx/spec.conf #{stop_flag}`
110
- end
111
-
112
- private
113
-
114
- def pid
115
- if File.exists?("#{fixtures_path}/sphinx/searchd.pid")
116
- `cat #{fixtures_path}/sphinx/searchd.pid`[/\d+/]
117
- else
118
- nil
119
- end
120
- end
121
-
122
- def running?
123
- pid && `ps #{pid} | wc -l`.to_i > 1
124
- end
125
-
126
- def fixtures_path
127
- File.expand_path File.join(File.dirname(__FILE__), '..', 'fixtures')
128
- end
129
-
130
- def bin_path
131
- @bin_path ||= begin
132
- path = (ENV['SPHINX_BIN'] || '').dup
133
- path.insert -1, '/' if path.length > 0 && path[/\/$/].nil?
134
- path
135
- end
136
- end
137
- end
@@ -1,290 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Riddle::Client do
4
- it "should have the same keys for both commands and versions, except persist" do
5
-
6
- (Riddle::Client::Commands.keys - [:persist]).should == Riddle::Client::Versions.keys
7
- end
8
-
9
- it "should default to localhost as the server" do
10
- Riddle::Client.new.server.should == "localhost"
11
- end
12
-
13
- it "should default to port 9312" do
14
- Riddle::Client.new.port.should == 9312
15
- end
16
-
17
- it "should accept an array of servers" do
18
- servers = ["1.1.1.1", "2.2.2.2", "3.3.3.3"]
19
- client = Riddle::Client.new(servers)
20
- client.servers.should == servers
21
- end
22
-
23
- it "should translate anchor arguments correctly" do
24
- client = Riddle::Client.new
25
- client.set_anchor "latitude", 10.0, "longitude", 95.0
26
- client.anchor.should == {
27
- :latitude_attribute => "latitude",
28
- :latitude => 10.0,
29
- :longitude_attribute => "longitude",
30
- :longitude => 95.0
31
- }
32
- end
33
-
34
- it "should add queries to the queue" do
35
- client = Riddle::Client.new
36
- client.queue.should be_empty
37
- client.append_query "spec"
38
- client.queue.should_not be_empty
39
- end
40
-
41
- describe 'query contents' do
42
- it "should build a basic search message correctly" do
43
- client = Riddle::Client.new
44
- client.append_query "test "
45
- client.queue.first.should == query_contents(:simple)
46
- end
47
-
48
- it "should build a message with a specified index correctly" do
49
- client = Riddle::Client.new
50
- client.append_query "test ", "edition"
51
- client.queue.first.should == query_contents(:index)
52
- end
53
-
54
- it "should build a message using match mode :any correctly" do
55
- client = Riddle::Client.new
56
- client.match_mode = :any
57
- client.append_query "test this "
58
- client.queue.first.should == query_contents(:any)
59
- end
60
-
61
- it "should build a message using sort by correctly" do
62
- client = Riddle::Client.new
63
- client.sort_by = 'id'
64
- client.sort_mode = :extended
65
- client.append_query "testing "
66
- client.queue.first.should == query_contents(:sort)
67
- end
68
-
69
- it "should build a message using match mode :boolean correctly" do
70
- client = Riddle::Client.new
71
- client.match_mode = :boolean
72
- client.append_query "test "
73
- client.queue.first.should == query_contents(:boolean)
74
- end
75
-
76
- it "should build a message using match mode :phrase correctly" do
77
- client = Riddle::Client.new
78
- client.match_mode = :phrase
79
- client.append_query "testing this "
80
- client.queue.first.should == query_contents(:phrase)
81
- end
82
-
83
- it "should build a message with a filter correctly" do
84
- client = Riddle::Client.new
85
- client.filters << Riddle::Client::Filter.new("id", [10, 100, 1000])
86
- client.append_query "test "
87
- client.queue.first.should == query_contents(:filter)
88
- end
89
-
90
- it "should build a message with group values correctly" do
91
- client = Riddle::Client.new
92
- client.group_by = "id"
93
- client.group_function = :attr
94
- client.group_clause = "id"
95
- client.append_query "test "
96
- client.queue.first.should == query_contents(:group)
97
- end
98
-
99
- it "should build a message with group distinct value correctly" do
100
- client = Riddle::Client.new
101
- client.group_distinct = "id"
102
- client.append_query "test "
103
- client.queue.first.should == query_contents(:distinct)
104
- end
105
-
106
- it "should build a message with weights correctly" do
107
- client = Riddle::Client.new
108
- client.weights = [100, 1]
109
- client.append_query "test "
110
- client.queue.first.should == query_contents(:weights)
111
- end
112
-
113
- it "should build a message with an anchor correctly" do
114
- client = Riddle::Client.new
115
- client.set_anchor "latitude", 10.0, "longitude", 95.0
116
- client.append_query "test "
117
- client.queue.first.should == query_contents(:anchor)
118
- end
119
-
120
- it "should build a message with index weights correctly" do
121
- client = Riddle::Client.new
122
- client.index_weights = {"people" => 101}
123
- client.append_query "test "
124
- client.queue.first.should == query_contents(:index_weights)
125
- end
126
-
127
- it "should build a message with field weights correctly" do
128
- client = Riddle::Client.new
129
- client.field_weights = {"city" => 101}
130
- client.append_query "test "
131
- client.queue.first.should == query_contents(:field_weights)
132
- end
133
-
134
- it "should build a message with a comment correctly" do
135
- client = Riddle::Client.new
136
- client.append_query "test ", "*", "commenting"
137
- client.queue.first.should == query_contents(:comment)
138
- end
139
-
140
- if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
141
- it "should build a message with overrides correctly" do
142
- client = Riddle::Client.new
143
- client.add_override("rating", :float, {1 => 10.0})
144
- client.append_query "test "
145
- client.queue.first.should == query_contents(:overrides)
146
- end
147
-
148
- it "should build a message with selects correctly" do
149
- client = Riddle::Client.new
150
- client.select = "selecting"
151
- client.append_query "test "
152
- client.queue.first.should == query_contents(:select)
153
- end
154
- end
155
-
156
- it "should keep multiple messages in the queue" do
157
- client = Riddle::Client.new
158
- client.weights = [100, 1]
159
- client.append_query "test "
160
- client.append_query "test "
161
- client.queue.length.should == 2
162
- client.queue.each { |item| item.should == query_contents(:weights) }
163
- end
164
-
165
- it "should keep multiple messages in the queue with different params" do
166
- client = Riddle::Client.new
167
- client.weights = [100, 1]
168
- client.append_query "test "
169
- client.weights = []
170
- client.append_query "test ", "edition"
171
- client.queue.first.should == query_contents(:weights)
172
- client.queue.last.should == query_contents(:index)
173
- end
174
-
175
- it "should build a basic update message correctly" do
176
- client = Riddle::Client.new
177
- client.send(
178
- :update_message,
179
- "people",
180
- ["birthday"],
181
- {1 => [191163600]}
182
- ).should == query_contents(:update_simple)
183
- end
184
-
185
- it "should build a keywords request without hits correctly" do
186
- client = Riddle::Client.new
187
- client.send(
188
- :keywords_message,
189
- "pat",
190
- "people",
191
- false
192
- ).should == query_contents(:keywords_without_hits)
193
- end
194
-
195
- it "should build a keywords request with hits correctly" do
196
- client = Riddle::Client.new
197
- client.send(
198
- :keywords_message,
199
- "pat",
200
- "people",
201
- true
202
- ).should == query_contents(:keywords_with_hits)
203
- end
204
- end
205
-
206
- it "should timeout after a specified time" do
207
- client = Riddle::Client.new
208
- client.port = 9314
209
- client.timeout = 1
210
-
211
- server = TCPServer.new "localhost", 9314
212
-
213
- lambda {
214
- client.send(:connect) { |socket| }
215
- }.should raise_error(Riddle::ConnectionError)
216
-
217
- server.close
218
- end unless RUBY_PLATFORM == 'java' # JRuby doesn't like Timeout
219
-
220
- context "connection retrying" do
221
- it "should try fives time when connection refused" do
222
- client = Riddle::Client.new
223
- client.port = 3314
224
-
225
- TCPSocket.should_receive(:new).with('localhost', 3314).exactly(5).times.
226
- and_raise(Errno::ECONNREFUSED)
227
-
228
- lambda {
229
- client.send(:connect) { |socket| }
230
- }.should raise_error(Riddle::ConnectionError)
231
- end
232
- end
233
-
234
- context "connection fail over" do
235
- it "should try each of several server addresses after timeouts" do
236
- client = Riddle::Client.new
237
- client.port = 3314
238
- client.servers = %w[localhost 127.0.0.1 0.0.0.0]
239
- client.timeout = 1
240
-
241
- TCPSocket.should_receive(:new).with(
242
- an_instance_of(String), 3314
243
- ).exactly(3).and_raise Timeout::Error
244
-
245
- lambda {
246
- client.send(:connect) { |socket| }
247
- }.should raise_error(Riddle::ConnectionError)
248
- end unless RUBY_PLATFORM == 'java' # JRuby doesn't like Timeout
249
-
250
- it "should try each of several server addresses after a connection refused" do
251
- client = Riddle::Client.new
252
- client.port = 3314
253
- client.servers = %w[localhost 127.0.0.1 0.0.0.0]
254
- client.timeout = 1
255
-
256
- # initialise_socket will retry 5 times before failing,
257
- # these combined with the multiple server failover should result in 15
258
- # calls to TCPSocket.new
259
- TCPSocket.should_receive(:new).with(
260
- an_instance_of(String), 3314
261
- ).exactly(3 * 5).and_raise Errno::ECONNREFUSED
262
-
263
- lambda {
264
- client.send(:connect) { |socket| }
265
- }.should raise_error(Riddle::ConnectionError)
266
- end unless RUBY_PLATFORM == 'java' # JRuby doesn't like Timeout
267
- end
268
-
269
- it "should fail if the server has the wrong version" do
270
- client = Riddle::Client.new
271
- client.port = 9314
272
- client.timeout = 1
273
-
274
- server = TCPServer.new "localhost", 9314
275
-
276
- thread = Thread.new do
277
- client = server.accept
278
- client.send [0].pack("N"), 0
279
- client.close
280
- end
281
-
282
- lambda {
283
- client.send(:connect) { |socket| }
284
- }.should raise_error(Riddle::VersionError)
285
-
286
- thread.exit
287
- server.close
288
- end
289
-
290
- end