riddle 1.0.11 → 1.0.12
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/riddle.rb +2 -0
- data/lib/riddle/1.10.rb +5 -0
- data/lib/riddle/1.10/client.rb +28 -0
- data/lib/riddle/auto_version.rb +2 -0
- data/lib/riddle/client.rb +59 -29
- data/lib/riddle/controller.rb +3 -3
- data/spec/functional/excerpt_spec.rb +8 -2
- data/spec/functional/status_spec.rb +1 -1
- data/spec/riddle/auto_version_spec.rb +7 -0
- data/spec/riddle/controller_spec.rb +5 -0
- data/spec/unit/client_spec.rb +1 -1
- data/spec/unit/configuration/searchd_spec.rb +2 -2
- metadata +6 -4
data/lib/riddle.rb
CHANGED
data/lib/riddle/1.10.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Riddle::Client::Versions[:search] = 0x117
|
2
|
+
Riddle::Client::Versions[:excerpt] = 0x102
|
3
|
+
|
4
|
+
class Riddle::Client
|
5
|
+
private
|
6
|
+
|
7
|
+
# Generation of the message to send to Sphinx for an excerpts request.
|
8
|
+
def excerpts_message(options)
|
9
|
+
message = Message.new
|
10
|
+
|
11
|
+
message.append [0, excerpt_flags(options)].pack('N2') # 0 = mode
|
12
|
+
message.append_string options[:index]
|
13
|
+
message.append_string options[:words]
|
14
|
+
|
15
|
+
# options
|
16
|
+
message.append_string options[:before_match]
|
17
|
+
message.append_string options[:after_match]
|
18
|
+
message.append_string options[:chunk_separator]
|
19
|
+
message.append_ints options[:limit], options[:around]
|
20
|
+
message.append_ints options[:limit_passages], options[:limit_words]
|
21
|
+
message.append_ints options[:start_passage_id]
|
22
|
+
message.append_string options[:html_strip_mode]
|
23
|
+
|
24
|
+
message.append_array options[:docs]
|
25
|
+
|
26
|
+
message.to_s
|
27
|
+
end
|
28
|
+
end
|
data/lib/riddle/auto_version.rb
CHANGED
data/lib/riddle/client.rb
CHANGED
@@ -30,22 +30,24 @@ module Riddle
|
|
30
30
|
#
|
31
31
|
class Client
|
32
32
|
Commands = {
|
33
|
-
:search
|
34
|
-
:excerpt
|
35
|
-
:update
|
36
|
-
:keywords
|
37
|
-
:persist
|
38
|
-
:status
|
39
|
-
:query
|
33
|
+
:search => 0, # SEARCHD_COMMAND_SEARCH
|
34
|
+
:excerpt => 1, # SEARCHD_COMMAND_EXCERPT
|
35
|
+
:update => 2, # SEARCHD_COMMAND_UPDATE
|
36
|
+
:keywords => 3, # SEARCHD_COMMAND_KEYWORDS
|
37
|
+
:persist => 4, # SEARCHD_COMMAND_PERSIST
|
38
|
+
:status => 5, # SEARCHD_COMMAND_STATUS
|
39
|
+
:query => 6, # SEARCHD_COMMAND_QUERY
|
40
|
+
:flushattrs => 7 # SEARCHD_COMMAND_FLUSHATTRS
|
40
41
|
}
|
41
42
|
|
42
43
|
Versions = {
|
43
|
-
:search
|
44
|
-
:excerpt
|
45
|
-
:update
|
46
|
-
:keywords
|
47
|
-
:status
|
48
|
-
:query
|
44
|
+
:search => 0x113, # VER_COMMAND_SEARCH
|
45
|
+
:excerpt => 0x100, # VER_COMMAND_EXCERPT
|
46
|
+
:update => 0x101, # VER_COMMAND_UPDATE
|
47
|
+
:keywords => 0x100, # VER_COMMAND_KEYWORDS
|
48
|
+
:status => 0x100, # VER_COMMAND_STATUS
|
49
|
+
:query => 0x100, # VER_COMMAND_QUERY
|
50
|
+
:flushattrs => 0x100 # VER_COMMAND_FLUSHATTRS
|
49
51
|
}
|
50
52
|
|
51
53
|
Statuses = {
|
@@ -72,7 +74,9 @@ module Riddle
|
|
72
74
|
:wordcount => 3, # SPH_RANK_WORDCOUNT
|
73
75
|
:proximity => 4, # SPH_RANK_PROXIMITY
|
74
76
|
:match_any => 5, # SPH_RANK_MATCHANY
|
75
|
-
:fieldmask => 6
|
77
|
+
:fieldmask => 6, # SPH_RANK_FIELDMASK
|
78
|
+
:sph04 => 7, # SPH_RANK_SPH04
|
79
|
+
:total => 8 # SPH_RANK_TOTAL
|
76
80
|
}
|
77
81
|
|
78
82
|
SortModes = {
|
@@ -91,6 +95,7 @@ module Riddle
|
|
91
95
|
:bool => 4, # SPH_ATTR_BOOL
|
92
96
|
:float => 5, # SPH_ATTR_FLOAT
|
93
97
|
:bigint => 6, # SPH_ATTR_BIGINT
|
98
|
+
:string => 7, # SPH_ATTR_STRING
|
94
99
|
:multi => 0x40000000 # SPH_ATTR_MULTI
|
95
100
|
}
|
96
101
|
|
@@ -356,14 +361,22 @@ module Riddle
|
|
356
361
|
# 3. Pass the documents' text to +excerpts+ for marking up of matched terms.
|
357
362
|
#
|
358
363
|
def excerpts(options = {})
|
359
|
-
options[:index]
|
360
|
-
options[:before_match]
|
361
|
-
options[:after_match]
|
362
|
-
options[:chunk_separator]
|
363
|
-
options[:limit]
|
364
|
-
options[:
|
365
|
-
options[:
|
366
|
-
options[:
|
364
|
+
options[:index] ||= '*'
|
365
|
+
options[:before_match] ||= '<span class="match">'
|
366
|
+
options[:after_match] ||= '</span>'
|
367
|
+
options[:chunk_separator] ||= ' … ' # ellipsis
|
368
|
+
options[:limit] ||= 256
|
369
|
+
options[:limit_passages] ||= 0
|
370
|
+
options[:limit_words] ||= 0
|
371
|
+
options[:around] ||= 5
|
372
|
+
options[:exact_phrase] ||= false
|
373
|
+
options[:single_passage] ||= false
|
374
|
+
options[:query_mode] ||= false
|
375
|
+
options[:force_all_words] ||= false
|
376
|
+
options[:start_passage_id] ||= 1
|
377
|
+
options[:load_files] ||= false
|
378
|
+
options[:html_strip_mode] ||= 'index'
|
379
|
+
options[:allow_empty] ||= false
|
367
380
|
|
368
381
|
response = Response.new request(:excerpt, excerpts_message(options))
|
369
382
|
|
@@ -425,6 +438,14 @@ module Riddle
|
|
425
438
|
end
|
426
439
|
end
|
427
440
|
|
441
|
+
def flush_attributes
|
442
|
+
response = Response.new request(
|
443
|
+
:flushattrs, Message.new
|
444
|
+
)
|
445
|
+
|
446
|
+
response.next_int
|
447
|
+
end
|
448
|
+
|
428
449
|
def add_override(attribute, type, values)
|
429
450
|
@overrides[attribute] = {:type => type, :values => values}
|
430
451
|
end
|
@@ -678,13 +699,7 @@ module Riddle
|
|
678
699
|
def excerpts_message(options)
|
679
700
|
message = Message.new
|
680
701
|
|
681
|
-
|
682
|
-
flags |= 2 if options[:exact_phrase]
|
683
|
-
flags |= 4 if options[:single_passage]
|
684
|
-
flags |= 8 if options[:use_boundaries]
|
685
|
-
flags |= 16 if options[:weight_order]
|
686
|
-
|
687
|
-
message.append [0, flags].pack('N2') # 0 = mode
|
702
|
+
message.append [0, excerpt_flags(options)].pack('N2') # 0 = mode
|
688
703
|
message.append_string options[:index]
|
689
704
|
message.append_string options[:words]
|
690
705
|
|
@@ -735,9 +750,24 @@ module Riddle
|
|
735
750
|
is_multi ? response.next_float_array : response.next_float
|
736
751
|
when AttributeTypes[:bigint]
|
737
752
|
is_multi ? response.next_64bit_int_arry : response.next_64bit_int
|
753
|
+
when AttributeTypes[:string]
|
754
|
+
is_multi ? response.next_array : response.next
|
738
755
|
else
|
739
756
|
is_multi ? response.next_int_array : response.next_int
|
740
757
|
end
|
741
758
|
end
|
759
|
+
|
760
|
+
def excerpt_flags(options)
|
761
|
+
flags = 1
|
762
|
+
flags |= 2 if options[:exact_phrase]
|
763
|
+
flags |= 4 if options[:single_passage]
|
764
|
+
flags |= 8 if options[:use_boundaries]
|
765
|
+
flags |= 16 if options[:weight_order]
|
766
|
+
flags |= 32 if options[:query_mode]
|
767
|
+
flags |= 64 if options[:force_all_words]
|
768
|
+
flags |= 128 if options[:load_files]
|
769
|
+
flags |= 256 if options[:allow_empty]
|
770
|
+
flags
|
771
|
+
end
|
742
772
|
end
|
743
773
|
end
|
data/lib/riddle/controller.rb
CHANGED
@@ -12,7 +12,7 @@ module Riddle
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def sphinx_version
|
15
|
-
`#{indexer} 2>&1`[/^Sphinx (\d
|
15
|
+
`#{indexer} 2>&1`[/^Sphinx (\d+\.\d+(\.\d+|\-beta))/, 1]
|
16
16
|
rescue
|
17
17
|
nil
|
18
18
|
end
|
@@ -21,7 +21,7 @@ module Riddle
|
|
21
21
|
options = indexes.last.is_a?(Hash) ? indexes.pop : {}
|
22
22
|
indexes << '--all' if indexes.empty?
|
23
23
|
|
24
|
-
cmd = "#{indexer} --config
|
24
|
+
cmd = "#{indexer} --config \"#{@path}\" #{indexes.join(' ')}"
|
25
25
|
cmd << " --rotate" if running?
|
26
26
|
options[:verbose] ? system(cmd) : `#{cmd}`
|
27
27
|
end
|
@@ -29,7 +29,7 @@ module Riddle
|
|
29
29
|
def start
|
30
30
|
return if running?
|
31
31
|
|
32
|
-
cmd = "#{searchd} --pidfile --config
|
32
|
+
cmd = "#{searchd} --pidfile --config \"#{@path}\""
|
33
33
|
|
34
34
|
if RUBY_PLATFORM =~ /mswin/
|
35
35
|
system("start /B #{cmd} 1> NUL 2>&1")
|
@@ -48,7 +48,8 @@ not. It's just my name: Pat.
|
|
48
48
|
)
|
49
49
|
|
50
50
|
|
51
|
-
|
51
|
+
case Riddle.loaded_version
|
52
|
+
when '0.9.9'
|
52
53
|
excerpts.should == [
|
53
54
|
<<-SENTENCE
|
54
55
|
This is a really long sentence written by <em>Pat</em>. It has to be over 256
|
@@ -57,6 +58,8 @@ yeah? Excerpts are particularly riveting. This keyword, however, is
|
|
57
58
|
not. It's just my name: <em>Pat</em>.
|
58
59
|
SENTENCE
|
59
60
|
]
|
61
|
+
when '1.10'
|
62
|
+
excerpts.should == [" … really long sentence written by <em>Pat</em>. It has to be over … . This keyword, however, is\nnot. It's just my name: <em>Pat</em> … "]
|
60
63
|
else
|
61
64
|
excerpts.should == [
|
62
65
|
<<-SENTENCE
|
@@ -90,7 +93,8 @@ not. It's just my name: Pat.
|
|
90
93
|
:chunk_separator => " --- "
|
91
94
|
)
|
92
95
|
|
93
|
-
|
96
|
+
case Riddle.loaded_version
|
97
|
+
when '0.9.9'
|
94
98
|
excerpts.should == [
|
95
99
|
<<-SENTENCE
|
96
100
|
This is a really long sentence written by <em>Pat</em>. It has to be over 256
|
@@ -99,6 +103,8 @@ yeah? Excerpts are particularly riveting. This keyword, however, is
|
|
99
103
|
not. It's just my name: <em>Pat</em>.
|
100
104
|
SENTENCE
|
101
105
|
]
|
106
|
+
when '1.10'
|
107
|
+
excerpts.should == [" --- really long sentence written by <em>Pat</em>. It has to be over --- . This keyword, however, is\nnot. It's just my name: <em>Pat</em> --- "]
|
102
108
|
else
|
103
109
|
excerpts.should == [
|
104
110
|
<<-SENTENCE
|
@@ -20,5 +20,12 @@ describe Riddle::AutoVersion do
|
|
20
20
|
@controller.stub!(:sphinx_version => '0.9.9')
|
21
21
|
Riddle::AutoVersion.configure
|
22
22
|
end
|
23
|
+
|
24
|
+
it "should require 1.10 if that is the known version" do
|
25
|
+
Riddle::AutoVersion.should_receive(:require).with('riddle/1.10')
|
26
|
+
|
27
|
+
@controller.stub!(:sphinx_version => '1.10-beta')
|
28
|
+
Riddle::AutoVersion.configure
|
29
|
+
end
|
23
30
|
end
|
24
31
|
end
|
@@ -6,6 +6,11 @@ describe Riddle::Controller do
|
|
6
6
|
@controller = Riddle::Controller.new stub('controller'), 'sphinx.conf'
|
7
7
|
end
|
8
8
|
|
9
|
+
it "should return 1.10 if using 1.10-beta" do
|
10
|
+
@controller.stub!(:` => 'Sphinx 1.10-beta (r2420)')
|
11
|
+
@controller.sphinx_version.should == '1.10-beta'
|
12
|
+
end
|
13
|
+
|
9
14
|
it "should return 0.9.9 if using 0.9.9" do
|
10
15
|
@controller.stub!(:` => 'Sphinx 0.9.9-release (r2117)')
|
11
16
|
@controller.sphinx_version.should == '0.9.9'
|
data/spec/unit/client_spec.rb
CHANGED
@@ -130,7 +130,7 @@ describe Riddle::Client do
|
|
130
130
|
client.queue.first.should == query_contents(:comment)
|
131
131
|
end
|
132
132
|
|
133
|
-
if Riddle.loaded_version == '0.9.9'
|
133
|
+
if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
|
134
134
|
it "should build a message with overrides correctly" do
|
135
135
|
client = Riddle::Client.new
|
136
136
|
client.add_override("rating", :float, {1 => 10.0})
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec/spec_helper'
|
2
2
|
|
3
3
|
describe Riddle::Configuration::Searchd do
|
4
|
-
if Riddle.loaded_version == '0.9.9'
|
4
|
+
if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
|
5
5
|
it "should be invalid without a listen or pid_file" do
|
6
6
|
searchd = Riddle::Configuration::Searchd.new
|
7
7
|
searchd.should_not be_valid
|
@@ -60,7 +60,7 @@ describe Riddle::Configuration::Searchd do
|
|
60
60
|
searchd.port = 3312
|
61
61
|
searchd.pid_file = "file.pid"
|
62
62
|
|
63
|
-
if Riddle.loaded_version == '0.9.9'
|
63
|
+
if Riddle.loaded_version == '0.9.9' || Riddle.loaded_version == '1.10'
|
64
64
|
searchd.render.should == <<-SEARCHD
|
65
65
|
searchd
|
66
66
|
{
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: riddle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 12
|
10
|
+
version: 1.0.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Allan
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-07-27 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -64,6 +64,8 @@ files:
|
|
64
64
|
- lib/riddle/0.9.9/client.rb
|
65
65
|
- lib/riddle/0.9.9/client/filter.rb
|
66
66
|
- lib/riddle/0.9.9/configuration/searchd.rb
|
67
|
+
- lib/riddle/1.10.rb
|
68
|
+
- lib/riddle/1.10/client.rb
|
67
69
|
- lib/riddle/auto_version.rb
|
68
70
|
- lib/riddle/client.rb
|
69
71
|
- lib/riddle/client/filter.rb
|