riddle 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README.textile +1 -0
  2. data/lib/riddle/1.10/client.rb +4 -0
  3. data/lib/riddle/2.0.1.rb +6 -0
  4. data/lib/riddle/2.0.1/client.rb +2 -0
  5. data/lib/riddle/auto_version.rb +6 -1
  6. data/lib/riddle/client.rb +27 -8
  7. data/lib/riddle/configuration/searchd.rb +1 -1
  8. data/lib/riddle/controller.rb +1 -1
  9. data/spec/functional/connection_spec.rb +4 -4
  10. data/spec/functional/excerpt_spec.rb +1 -1
  11. data/spec/functional/keywords_spec.rb +1 -1
  12. data/spec/functional/persistance_spec.rb +1 -1
  13. data/spec/functional/search_spec.rb +1 -1
  14. data/spec/functional/status_spec.rb +1 -1
  15. data/spec/functional/update_spec.rb +1 -1
  16. data/spec/riddle/auto_version_spec.rb +8 -1
  17. data/spec/riddle/client_spec.rb +1 -1
  18. data/spec/riddle/configuration_spec.rb +1 -1
  19. data/spec/riddle/controller_spec.rb +1 -1
  20. data/spec/riddle_spec.rb +1 -1
  21. data/spec/spec_helper.rb +6 -3
  22. data/spec/sphinx_helper.rb +13 -11
  23. data/spec/unit/client_spec.rb +1 -1
  24. data/spec/unit/configuration/distributed_index_spec.rb +1 -1
  25. data/spec/unit/configuration/index_spec.rb +1 -1
  26. data/spec/unit/configuration/indexer_spec.rb +1 -1
  27. data/spec/unit/configuration/realtime_index_spec.rb +1 -1
  28. data/spec/unit/configuration/searchd_spec.rb +29 -2
  29. data/spec/unit/configuration/source_spec.rb +1 -1
  30. data/spec/unit/configuration/sql_source_spec.rb +1 -1
  31. data/spec/unit/configuration/xml_source_spec.rb +1 -1
  32. data/spec/unit/configuration_spec.rb +1 -1
  33. data/spec/unit/filter_spec.rb +1 -1
  34. data/spec/unit/message_spec.rb +1 -1
  35. data/spec/unit/response_spec.rb +1 -1
  36. data/spec/unit/riddle_spec.rb +1 -1
  37. metadata +38 -30
@@ -84,3 +84,4 @@ Thanks to the following people who have contributed to Riddle in some shape or f
84
84
  * Sam Goldstein
85
85
  * Matt Todd
86
86
  * Paco Guzmán
87
+ * Greg Weber
@@ -21,6 +21,10 @@ class Riddle::Client
21
21
  message.append_ints options[:start_passage_id]
22
22
  message.append_string options[:html_strip_mode]
23
23
 
24
+ if Versions[:excerpt] >= 0x103
25
+ message.append_string options[:passage_boundary]
26
+ end
27
+
24
28
  message.append_array options[:docs]
25
29
 
26
30
  message.to_s
@@ -0,0 +1,6 @@
1
+ require 'riddle/0.9.9'
2
+ require 'riddle/1.10'
3
+
4
+ Riddle.loaded_version = '2.0.1'
5
+
6
+ require 'riddle/2.0.1/client'
@@ -0,0 +1,2 @@
1
+ Riddle::Client::Versions[:search] = 0x118
2
+ Riddle::Client::Versions[:excerpt] = 0x103
@@ -6,8 +6,13 @@ class Riddle::AutoVersion
6
6
  case version
7
7
  when '0.9.8', '0.9.9'
8
8
  require "riddle/#{version}"
9
- when '1.10-beta', '1.10-id64-beta'
9
+ when '1.10-beta', '1.10-id64-beta', '1.10-dev'
10
10
  require 'riddle/1.10'
11
+ when /2.0.1/
12
+ require 'riddle/2.0.1'
13
+ else
14
+ puts "found version: #{version}"
15
+ exit
11
16
  end
12
17
  end
13
18
  end
@@ -120,7 +120,7 @@ module Riddle
120
120
  :group_by, :group_function, :group_clause, :group_distinct, :cut_off,
121
121
  :retry_count, :retry_delay, :anchor, :index_weights, :rank_mode,
122
122
  :max_query_time, :field_weights, :timeout, :overrides, :select,
123
- :connection
123
+ :connection, :key
124
124
  attr_reader :queue
125
125
 
126
126
  def self.connection=(value)
@@ -134,13 +134,14 @@ module Riddle
134
134
  # Can instantiate with a specific server and port - otherwise it assumes
135
135
  # defaults of localhost and 3312 respectively. All other settings can be
136
136
  # accessed and changed via the attribute accessors.
137
- def initialize(servers=nil, port=nil)
137
+ def initialize(servers = nil, port = nil, key = nil)
138
138
  Riddle.version_warning
139
139
 
140
140
  servers = Array(servers || "localhost")
141
141
  @servers = servers.respond_to?(:shuffle) ? servers.shuffle : servers.sort_by{ rand }
142
142
  @port = port || 9312
143
143
  @socket = nil
144
+ @key = key
144
145
 
145
146
  reset
146
147
 
@@ -390,6 +391,8 @@ module Riddle
390
391
  options[:load_files] ||= false
391
392
  options[:html_strip_mode] ||= 'index'
392
393
  options[:allow_empty] ||= false
394
+ options[:passage_boundary] ||= 'none'
395
+ options[:emit_zones] ||= false
393
396
 
394
397
  response = Response.new request(:excerpt, excerpts_message(options))
395
398
 
@@ -514,8 +517,9 @@ module Riddle
514
517
  true
515
518
  end
516
519
 
517
- # Connects to the Sphinx daemon, and yields a socket to use. The socket is
518
- # closed at the end of the block.
520
+ # If there's an active connection to the Sphinx daemon, this will yield the
521
+ # socket. If there's no active connection, then it will connect, yield the
522
+ # new socket, then close it.
519
523
  def connect(&block)
520
524
  if @socket.nil? || @socket.closed?
521
525
  @socket = nil
@@ -575,19 +579,33 @@ module Riddle
575
579
  version = 0
576
580
  length = 0
577
581
  message = Array(messages).join("")
582
+
578
583
  if message.respond_to?(:force_encoding)
579
584
  message = message.force_encoding('ASCII-8BIT')
580
585
  end
581
586
 
587
+ if key
588
+ prefix = Message.new
589
+ prefix.append_string key
590
+ message = prefix.to_s + message
591
+ end
592
+
582
593
  connect do |socket|
583
594
  case command
584
595
  when :search
585
596
  # Message length is +4 to account for the following count value for
586
597
  # the number of messages (well, that's what I'm assuming).
587
- socket.send [
588
- Commands[command], Versions[command],
589
- 4+message.length, messages.length
590
- ].pack("nnNN") + message, 0
598
+ if Versions[command] >= 0x118
599
+ socket.send [
600
+ Commands[command], Versions[command],
601
+ 8+message.length, messages.length, 0
602
+ ].pack("nnNNN") + message, 0
603
+ else
604
+ socket.send [
605
+ Commands[command], Versions[command],
606
+ 4+message.length, messages.length
607
+ ].pack("nnNN") + message, 0
608
+ end
591
609
  when :status
592
610
  socket.send [
593
611
  Commands[command], Versions[command], 4, 1
@@ -795,6 +813,7 @@ module Riddle
795
813
  flags |= 64 if options[:force_all_words]
796
814
  flags |= 128 if options[:load_files]
797
815
  flags |= 256 if options[:allow_empty]
816
+ flags |= 512 if options[:emit_zones]
798
817
  flags
799
818
  end
800
819
  end
@@ -8,7 +8,7 @@ module Riddle
8
8
  :crash_log_path, :max_filters, :max_filter_values, :listen_backlog,
9
9
  :read_buffer, :read_unhinted, :max_batch_queries, :subtree_docs_cache,
10
10
  :subtree_hits_cache, :workers, :dist_threads, :binlog_path,
11
- :binlog_flush, :binlog_max_log_size]
11
+ :binlog_flush, :binlog_max_log_size, :client_key]
12
12
 
13
13
  attr_accessor *self.settings
14
14
 
@@ -12,7 +12,7 @@ module Riddle
12
12
  end
13
13
 
14
14
  def sphinx_version
15
- `#{indexer} 2>&1`[/^Sphinx (\d+\.\d+(\.\d+|(\-id64)?\-beta))/, 1]
15
+ `#{indexer} 2>&1`[/^Sphinx (\d+\.\d+(\.\d+|(?:-dev|(\-id64)?\-beta)))/, 1]
16
16
  rescue
17
17
  nil
18
18
  end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  class RiddleSpecConnectionProcError < StandardError; end
4
4
 
@@ -14,7 +14,7 @@ describe "Sphinx Client" do
14
14
  describe '.connection' do
15
15
  it "should use the given block" do
16
16
  Riddle::Client.connection = lambda { |client|
17
- TCPsocket.new(client.server, client.port)
17
+ TCPSocket.new(client.server, client.port)
18
18
  }
19
19
  @client.query("smith").should be_kind_of(Hash)
20
20
  end
@@ -31,7 +31,7 @@ describe "Sphinx Client" do
31
31
  describe '#connection' do
32
32
  it "use the given block" do
33
33
  @client.connection = lambda { |client|
34
- TCPsocket.new(client.server, client.port)
34
+ TCPSocket.new(client.server, client.port)
35
35
  }
36
36
  @client.query("smith").should be_kind_of(Hash)
37
37
  end
@@ -49,7 +49,7 @@ describe "Sphinx Client" do
49
49
  raise RiddleSpecConnectionProcError
50
50
  }
51
51
  @client.connection = lambda { |client|
52
- TCPsocket.new(client.server, client.port)
52
+ TCPSocket.new(client.server, client.port)
53
53
  }
54
54
 
55
55
  lambda { @client.query("smith") }.should_not raise_error
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Sphinx Excepts" do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Sphinx Keywords" do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Sphinx Persistance Connection" do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Sphinx Searches" do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
4
4
  describe "Sphinx Status" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Sphinx Updates" do
4
4
  before :each do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::AutoVersion do
4
4
  describe '.configure' do
@@ -34,5 +34,12 @@ describe Riddle::AutoVersion do
34
34
  @controller.stub!(:sphinx_version => '1.10-id64-beta')
35
35
  Riddle::AutoVersion.configure
36
36
  end
37
+
38
+ it "should require 2.0.1 if that is the known version" do
39
+ Riddle::AutoVersion.should_receive(:require).with('riddle/2.0.1')
40
+
41
+ @controller.stub!(:sphinx_version => '2.0.1-beta')
42
+ Riddle::AutoVersion.configure
43
+ end
37
44
  end
38
45
  end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Client do
4
4
  describe '#initialize' do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration do
4
4
  #
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Controller do
4
4
  describe '#sphinx_version' do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle do
4
4
  describe '.version_warning' do
@@ -1,12 +1,15 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
2
3
 
3
4
  $:.unshift File.dirname(__FILE__) + '/../lib'
5
+ $:.unshift File.dirname(__FILE__) + '/..'
6
+
7
+ Bundler.require :default, :development
4
8
 
5
9
  require 'riddle'
6
- require 'spec'
7
- require 'spec/sphinx_helper'
10
+ require 'sphinx_helper'
8
11
 
9
- Spec::Runner.configure do |config|
12
+ RSpec.configure do |config|
10
13
  sphinx = SphinxHelper.new
11
14
  sphinx.setup_mysql
12
15
  sphinx.generate_configuration
@@ -1,4 +1,3 @@
1
- require 'mysql'
2
1
  require 'erb'
3
2
  require 'yaml'
4
3
 
@@ -22,26 +21,29 @@ class SphinxHelper
22
21
  end
23
22
 
24
23
  def setup_mysql
25
- server = Mysql.new @host, @username, @password
26
- server.set_server_option(Mysql::OPTION_MULTI_STATEMENTS_ON)
24
+ client = Mysql2::Client.new(
25
+ :host => @host,
26
+ :username => @username,
27
+ :password => @password
28
+ )
27
29
 
28
- unless server.list_dbs.include?("riddle")
29
- server.query "CREATE DATABASE riddle;"
30
+ databases = client.query('SHOW DATABASES', :as => :array).to_a.flatten
31
+ unless databases.include?('riddle')
32
+ client.query 'CREATE DATABASE riddle'
30
33
  end
31
34
 
32
- server.query "USE riddle;"
35
+ client.query "USE riddle"
33
36
 
34
37
  structure = File.open("spec/fixtures/sql/structure.sql") { |f| f.read }
35
- # Block ensures multiple statement transaction is closed.
36
- server.query(structure) { |response| }
37
- server.query <<-QUERY
38
+ structure.split(/;/).each { |sql| client.query sql }
39
+ client.query <<-SQL
38
40
  LOAD DATA LOCAL INFILE '#{@path}/fixtures/sql/data.tsv' INTO TABLE
39
41
  `riddle`.`people` FIELDS TERMINATED BY ',' ENCLOSED BY "'" (gender,
40
42
  first_name, middle_initial, last_name, street_address, city, state,
41
43
  postcode, email, birthday)
42
- QUERY
44
+ SQL
43
45
 
44
- server.close
46
+ client.close
45
47
  end
46
48
 
47
49
  def reset
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Client do
4
4
  it "should have the same keys for both commands and versions, except persist" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::DistributedIndex do
4
4
  it "should not be valid without any indexes" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::DistributedIndex do
4
4
  it "should be invalid without a name, sources or path if there's no parent" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::Indexer do
4
4
  it "should always be valid" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::RealtimeIndex do
4
4
  let(:index) { Riddle::Configuration::RealtimeIndex.new('rt1') }
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::Searchd do
4
4
  if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
@@ -78,4 +78,31 @@ searchd
78
78
  SEARCHD
79
79
  end
80
80
  end
81
- end
81
+
82
+ it "should render with a client key if one is provided" do
83
+ searchd = Riddle::Configuration::Searchd.new
84
+ searchd.port = 3312
85
+ searchd.pid_file = 'file.pid'
86
+ searchd.client_key = 'secret'
87
+
88
+ if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
89
+ searchd.render.should == <<-SEARCHD
90
+ searchd
91
+ {
92
+ listen = 3312
93
+ pid_file = file.pid
94
+ client_key = secret
95
+ }
96
+ SEARCHD
97
+ else
98
+ searchd.render.should == <<-SEARCHD
99
+ searchd
100
+ {
101
+ port = 3312
102
+ pid_file = file.pid
103
+ client_key = secret
104
+ }
105
+ SEARCHD
106
+ end
107
+ end
108
+ end
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::Source do
4
4
  #
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::SQLSource do
4
4
  it "should be invalid without a host, user, database, and query if there's no parent" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration::XMLSource do
4
4
  it "should be invalid without an xmlpipe command, name and type if there's no parent" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Configuration do
4
4
  it "should render all given indexes and sources, plus the indexer and search sections" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Client::Filter do
4
4
  it "should render a filter that uses an array of ints correctly" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Client::Message do
4
4
  it "should start with an empty string" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe Riddle::Client::Response do
4
4
  it "should interpret an integer correctly" do
@@ -1,4 +1,4 @@
1
- require 'spec/spec_helper'
1
+ require 'spec_helper'
2
2
 
3
3
  describe "Riddle" do
4
4
  it "should escape characters correctly" do
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riddle
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 2
9
- - 2
10
- version: 1.2.2
4
+ prerelease:
5
+ version: 1.3.0
11
6
  platform: ruby
12
7
  authors:
13
8
  - Pat Allan
@@ -15,39 +10,53 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-12-22 00:00:00 +11:00
13
+ date: 2011-05-07 00:00:00 +10:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
22
- name: rspec
23
- prerelease: false
17
+ name: mysql2
24
18
  requirement: &id001 !ruby/object:Gem::Requirement
25
19
  none: false
26
20
  requirements:
27
- - - ">="
21
+ - - "="
28
22
  - !ruby/object:Gem::Version
29
- hash: 13
30
- segments:
31
- - 1
32
- - 2
33
- - 9
34
- version: 1.2.9
23
+ version: 0.3.2
35
24
  type: :development
25
+ prerelease: false
36
26
  version_requirements: *id001
37
27
  - !ruby/object:Gem::Dependency
38
- name: yard
39
- prerelease: false
28
+ name: jeweler
40
29
  requirement: &id002 !ruby/object:Gem::Requirement
41
30
  none: false
42
31
  requirements:
43
- - - ">="
32
+ - - "="
44
33
  - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
34
+ version: 1.5.1
49
35
  type: :development
36
+ prerelease: false
50
37
  version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: rspec
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 2.5.0
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: yard
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: 0.6.8
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
51
60
  description: A Ruby API and configuration helper for the Sphinx search service.
52
61
  email: pat@freelancing-gods.com
53
62
  executables: []
@@ -66,6 +75,8 @@ files:
66
75
  - lib/riddle/0.9.9/configuration/searchd.rb
67
76
  - lib/riddle/1.10.rb
68
77
  - lib/riddle/1.10/client.rb
78
+ - lib/riddle/2.0.1.rb
79
+ - lib/riddle/2.0.1/client.rb
69
80
  - lib/riddle/auto_version.rb
70
81
  - lib/riddle/client.rb
71
82
  - lib/riddle/client/filter.rb
@@ -112,7 +123,7 @@ files:
112
123
  - spec/unit/response_spec.rb
113
124
  - spec/unit/riddle_spec.rb
114
125
  has_rdoc: true
115
- homepage: http://riddle.freelancing-gods.com
126
+ homepage: http://freelancing-god.github.com/riddle/
116
127
  licenses: []
117
128
 
118
129
  post_install_message:
@@ -125,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
136
  requirements:
126
137
  - - ">="
127
138
  - !ruby/object:Gem::Version
128
- hash: 3
139
+ hash: 2692990953322091417
129
140
  segments:
130
141
  - 0
131
142
  version: "0"
@@ -134,14 +145,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
145
  requirements:
135
146
  - - ">="
136
147
  - !ruby/object:Gem::Version
137
- hash: 3
138
- segments:
139
- - 0
140
148
  version: "0"
141
149
  requirements: []
142
150
 
143
151
  rubyforge_project:
144
- rubygems_version: 1.3.7
152
+ rubygems_version: 1.6.2
145
153
  signing_key:
146
154
  specification_version: 3
147
155
  summary: An API for Sphinx, written in and for Ruby.