riddle 1.2.2 → 1.3.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.
- data/README.textile +1 -0
- data/lib/riddle/1.10/client.rb +4 -0
- data/lib/riddle/2.0.1.rb +6 -0
- data/lib/riddle/2.0.1/client.rb +2 -0
- data/lib/riddle/auto_version.rb +6 -1
- data/lib/riddle/client.rb +27 -8
- data/lib/riddle/configuration/searchd.rb +1 -1
- data/lib/riddle/controller.rb +1 -1
- data/spec/functional/connection_spec.rb +4 -4
- data/spec/functional/excerpt_spec.rb +1 -1
- data/spec/functional/keywords_spec.rb +1 -1
- data/spec/functional/persistance_spec.rb +1 -1
- data/spec/functional/search_spec.rb +1 -1
- data/spec/functional/status_spec.rb +1 -1
- data/spec/functional/update_spec.rb +1 -1
- data/spec/riddle/auto_version_spec.rb +8 -1
- data/spec/riddle/client_spec.rb +1 -1
- data/spec/riddle/configuration_spec.rb +1 -1
- data/spec/riddle/controller_spec.rb +1 -1
- data/spec/riddle_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -3
- data/spec/sphinx_helper.rb +13 -11
- data/spec/unit/client_spec.rb +1 -1
- data/spec/unit/configuration/distributed_index_spec.rb +1 -1
- data/spec/unit/configuration/index_spec.rb +1 -1
- data/spec/unit/configuration/indexer_spec.rb +1 -1
- data/spec/unit/configuration/realtime_index_spec.rb +1 -1
- data/spec/unit/configuration/searchd_spec.rb +29 -2
- data/spec/unit/configuration/source_spec.rb +1 -1
- data/spec/unit/configuration/sql_source_spec.rb +1 -1
- data/spec/unit/configuration/xml_source_spec.rb +1 -1
- data/spec/unit/configuration_spec.rb +1 -1
- data/spec/unit/filter_spec.rb +1 -1
- data/spec/unit/message_spec.rb +1 -1
- data/spec/unit/response_spec.rb +1 -1
- data/spec/unit/riddle_spec.rb +1 -1
- metadata +38 -30
data/README.textile
CHANGED
data/lib/riddle/1.10/client.rb
CHANGED
@@ -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
|
data/lib/riddle/2.0.1.rb
ADDED
data/lib/riddle/auto_version.rb
CHANGED
@@ -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
|
data/lib/riddle/client.rb
CHANGED
@@ -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
|
-
#
|
518
|
-
#
|
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
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
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
|
|
data/lib/riddle/controller.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
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
|
-
|
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
|
-
|
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 '
|
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
|
data/spec/riddle/client_spec.rb
CHANGED
data/spec/riddle_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -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 '
|
7
|
-
require 'spec/sphinx_helper'
|
10
|
+
require 'sphinx_helper'
|
8
11
|
|
9
|
-
|
12
|
+
RSpec.configure do |config|
|
10
13
|
sphinx = SphinxHelper.new
|
11
14
|
sphinx.setup_mysql
|
12
15
|
sphinx.generate_configuration
|
data/spec/sphinx_helper.rb
CHANGED
@@ -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
|
-
|
26
|
-
|
24
|
+
client = Mysql2::Client.new(
|
25
|
+
:host => @host,
|
26
|
+
:username => @username,
|
27
|
+
:password => @password
|
28
|
+
)
|
27
29
|
|
28
|
-
|
29
|
-
|
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
|
-
|
35
|
+
client.query "USE riddle"
|
33
36
|
|
34
37
|
structure = File.open("spec/fixtures/sql/structure.sql") { |f| f.read }
|
35
|
-
|
36
|
-
|
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
|
-
|
44
|
+
SQL
|
43
45
|
|
44
|
-
|
46
|
+
client.close
|
45
47
|
end
|
46
48
|
|
47
49
|
def reset
|
data/spec/unit/client_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
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
|
data/spec/unit/filter_spec.rb
CHANGED
data/spec/unit/message_spec.rb
CHANGED
data/spec/unit/response_spec.rb
CHANGED
data/spec/unit/riddle_spec.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
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:
|
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:
|
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
|
-
|
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:
|
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
|
-
|
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://
|
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:
|
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.
|
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.
|