freelancing-god-thinking-sphinx 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENCE +20 -0
- data/README +25 -0
- data/lib/riddle.rb +22 -0
- data/lib/riddle/client.rb +593 -0
- data/lib/riddle/client/filter.rb +44 -0
- data/lib/riddle/client/message.rb +65 -0
- data/lib/riddle/client/response.rb +84 -0
- data/lib/test.rb +46 -0
- data/lib/thinking_sphinx.rb +79 -0
- data/lib/thinking_sphinx/active_record.rb +115 -0
- data/lib/thinking_sphinx/active_record/delta.rb +86 -0
- data/lib/thinking_sphinx/active_record/has_many_association.rb +29 -0
- data/lib/thinking_sphinx/active_record/search.rb +36 -0
- data/lib/thinking_sphinx/association.rb +140 -0
- data/lib/thinking_sphinx/attribute.rb +279 -0
- data/lib/thinking_sphinx/configuration.rb +275 -0
- data/lib/thinking_sphinx/field.rb +186 -0
- data/lib/thinking_sphinx/index.rb +234 -0
- data/lib/thinking_sphinx/index/builder.rb +197 -0
- data/lib/thinking_sphinx/index/faux_column.rb +97 -0
- data/lib/thinking_sphinx/rails_additions.rb +56 -0
- data/lib/thinking_sphinx/search.rb +413 -0
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +184 -0
- data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +53 -0
- data/spec/unit/thinking_sphinx/active_record/search_spec.rb +0 -0
- data/spec/unit/thinking_sphinx/active_record_spec.rb +85 -0
- data/spec/unit/thinking_sphinx/association_spec.rb +0 -0
- data/spec/unit/thinking_sphinx/attribute_spec.rb +73 -0
- data/spec/unit/thinking_sphinx/configuration_spec.rb +7 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +51 -0
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +33 -0
- data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +41 -0
- data/spec/unit/thinking_sphinx/index_spec.rb +5 -0
- data/spec/unit/thinking_sphinx/search_spec.rb +121 -0
- data/spec/unit/thinking_sphinx_spec.rb +82 -0
- data/tasks/thinking_sphinx_tasks.rake +1 -0
- data/tasks/thinking_sphinx_tasks.rb +86 -0
- metadata +90 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Index::Builder do
|
4
|
+
before :each do
|
5
|
+
@builder = Class.new(ThinkingSphinx::Index::Builder)
|
6
|
+
@builder.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "setup method" do
|
10
|
+
it "should set up the information arrays and properties hash" do
|
11
|
+
@builder.fields.should == []
|
12
|
+
@builder.attributes.should == []
|
13
|
+
@builder.conditions.should == []
|
14
|
+
@builder.properties.should == {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "indexes method" do
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "has method" do
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "where method" do
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "set_property method" do
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Index::FauxColumn do
|
4
|
+
it "should use the last argument as the name, with preceeding ones going into the stack" do
|
5
|
+
#
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should access the name through __name" do
|
9
|
+
#
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should access the stack through __stack" do
|
13
|
+
#
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return true from is_string? if the name is a string and the stack is empty" do
|
17
|
+
#
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "method_missing calls with no arguments" do
|
21
|
+
it "should push any further method calls into name, and the old name goes into the stack" do
|
22
|
+
#
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should return itself" do
|
26
|
+
#
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "method_missing calls with one argument" do
|
31
|
+
it "should act as if calling method missing with method, then argument" do
|
32
|
+
#
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "method_missing calls with more than one argument" do
|
37
|
+
it "should return a collection of Faux Columns sharing the same stack, but with each argument as the name" do
|
38
|
+
#
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx::Search do
|
4
|
+
describe "instance_from_result method" do
|
5
|
+
before :each do
|
6
|
+
Person.stub_method(:find => true)
|
7
|
+
ThinkingSphinx::Search.stub_method(:class_from_crc => Person)
|
8
|
+
end
|
9
|
+
|
10
|
+
after :each do
|
11
|
+
Person.unstub_method(:find)
|
12
|
+
ThinkingSphinx::Search.unstub_method(:class_from_crc)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should honour the :include option" do
|
16
|
+
ThinkingSphinx::Search.send(
|
17
|
+
:instance_from_result,
|
18
|
+
{:doc => 1, :attributes => {"class_crc" => 123}},
|
19
|
+
{:include => :assoc}
|
20
|
+
)
|
21
|
+
|
22
|
+
Person.should have_received(:find).with(1, :include => :assoc, :select => nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should honour the :select option" do
|
26
|
+
ThinkingSphinx::Search.send(
|
27
|
+
:instance_from_result,
|
28
|
+
{:doc => 1, :attributes => {"class_crc" => 123}},
|
29
|
+
{:select => :columns}
|
30
|
+
)
|
31
|
+
|
32
|
+
Person.should have_received(:find).with(1, :include => nil, :select => :columns)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "instances_from_results method" do
|
38
|
+
before :each do
|
39
|
+
@person_a = Person.stub_instance
|
40
|
+
@person_b = Person.stub_instance
|
41
|
+
@person_c = Person.stub_instance
|
42
|
+
|
43
|
+
@results = [
|
44
|
+
{:doc => @person_a.id},
|
45
|
+
{:doc => @person_b.id},
|
46
|
+
{:doc => @person_c.id}
|
47
|
+
]
|
48
|
+
|
49
|
+
Person.stub_method(
|
50
|
+
:find => [@person_c, @person_a, @person_b]
|
51
|
+
)
|
52
|
+
ThinkingSphinx::Search.stub_method(:instance_from_result => true)
|
53
|
+
end
|
54
|
+
|
55
|
+
after :each do
|
56
|
+
Person.unstub_method(:find)
|
57
|
+
ThinkingSphinx::Search.unstub_method(:instance_from_result)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should pass calls to instance_from_result if no class given" do
|
61
|
+
ThinkingSphinx::Search.send(
|
62
|
+
:instances_from_results, @results
|
63
|
+
)
|
64
|
+
|
65
|
+
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
66
|
+
{:doc => @person_a.id}, {}
|
67
|
+
)
|
68
|
+
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
69
|
+
{:doc => @person_b.id}, {}
|
70
|
+
)
|
71
|
+
ThinkingSphinx::Search.should have_received(:instance_from_result).with(
|
72
|
+
{:doc => @person_c.id}, {}
|
73
|
+
)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should call a find on all ids for the class" do
|
77
|
+
ThinkingSphinx::Search.send(
|
78
|
+
:instances_from_results, @results, {}, Person
|
79
|
+
)
|
80
|
+
|
81
|
+
Person.should have_received(:find).with(
|
82
|
+
:all,
|
83
|
+
:conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
|
84
|
+
:include => nil,
|
85
|
+
:select => nil
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should honour the :include option" do
|
90
|
+
ThinkingSphinx::Search.send(
|
91
|
+
:instances_from_results, @results, {:include => :something}, Person
|
92
|
+
)
|
93
|
+
|
94
|
+
Person.should have_received(:find).with(
|
95
|
+
:all,
|
96
|
+
:conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
|
97
|
+
:include => :something,
|
98
|
+
:select => nil
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should honour the :select option" do
|
103
|
+
ThinkingSphinx::Search.send(
|
104
|
+
:instances_from_results, @results, {:select => :fields}, Person
|
105
|
+
)
|
106
|
+
|
107
|
+
Person.should have_received(:find).with(
|
108
|
+
:all,
|
109
|
+
:conditions => {:id => [@person_a.id, @person_b.id, @person_c.id]},
|
110
|
+
:include => nil,
|
111
|
+
:select => :fields
|
112
|
+
)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should sort the objects the same as the result set" do
|
116
|
+
ThinkingSphinx::Search.send(
|
117
|
+
:instances_from_results, @results, {:select => :fields}, Person
|
118
|
+
).should == [@person_a, @person_b, @person_c]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec/spec_helper'
|
2
|
+
|
3
|
+
describe ThinkingSphinx do
|
4
|
+
describe "indexed_models methods" do
|
5
|
+
it "should contain all the names of models that have indexes" do
|
6
|
+
ThinkingSphinx.indexed_models.should include("Person")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should define indexes by default" do
|
11
|
+
ThinkingSphinx.define_indexes?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should disable index definition" do
|
15
|
+
ThinkingSphinx.define_indexes = false
|
16
|
+
ThinkingSphinx.define_indexes?.should be_false
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should enable index definition" do
|
20
|
+
ThinkingSphinx.define_indexes = false
|
21
|
+
ThinkingSphinx.define_indexes?.should be_false
|
22
|
+
ThinkingSphinx.define_indexes = true
|
23
|
+
ThinkingSphinx.define_indexes?.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should index deltas by default" do
|
27
|
+
ThinkingSphinx.deltas_enabled?.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should disable delta indexing" do
|
31
|
+
ThinkingSphinx.deltas_enabled = false
|
32
|
+
ThinkingSphinx.deltas_enabled?.should be_false
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should enable delta indexing" do
|
36
|
+
ThinkingSphinx.deltas_enabled = false
|
37
|
+
ThinkingSphinx.deltas_enabled?.should be_false
|
38
|
+
ThinkingSphinx.deltas_enabled = true
|
39
|
+
ThinkingSphinx.deltas_enabled?.should be_true
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "use_group_by_shortcut? method" do
|
43
|
+
after :each do
|
44
|
+
::ActiveRecord::Base.connection.unstub_method(:select_all)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should return true if no ONLY_FULL_GROUP_BY" do
|
48
|
+
::ActiveRecord::Base.connection.stub_method(
|
49
|
+
:select_all => {:a => "OTHER SETTINGS"}
|
50
|
+
)
|
51
|
+
|
52
|
+
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should return true if NULL value" do
|
56
|
+
::ActiveRecord::Base.connection.stub_method(
|
57
|
+
:select_all => {:a => nil}
|
58
|
+
)
|
59
|
+
|
60
|
+
ThinkingSphinx.use_group_by_shortcut?.should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return false if ONLY_FULL_GROUP_BY is set" do
|
64
|
+
::ActiveRecord::Base.connection.stub_method(
|
65
|
+
:select_all => {:a => "OTHER SETTINGS,ONLY_FULL_GROUP_BY,blah"}
|
66
|
+
)
|
67
|
+
|
68
|
+
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should return false if ONLY_FULL_GROUP_BY is set in any of the values" do
|
72
|
+
::ActiveRecord::Base.connection.stub_method(
|
73
|
+
:select_all => {
|
74
|
+
:a => "OTHER SETTINGS",
|
75
|
+
:b => "ONLY_FULL_GROUP_BY"
|
76
|
+
}
|
77
|
+
)
|
78
|
+
|
79
|
+
ThinkingSphinx.use_group_by_shortcut?.should be_false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'thinking_sphinx_tasks')
|
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
namespace :thinking_sphinx do
|
4
|
+
task :app_env do
|
5
|
+
Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
|
6
|
+
Rake::Task[:merb_env].invoke if defined?(Merb)
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
10
|
+
task :start => :app_env do
|
11
|
+
config = ThinkingSphinx::Configuration.new
|
12
|
+
|
13
|
+
FileUtils.mkdir_p config.searchd_file_path
|
14
|
+
raise RuntimeError, "searchd is already running." if sphinx_running?
|
15
|
+
|
16
|
+
Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
|
17
|
+
|
18
|
+
cmd = "searchd --config #{config.config_file}"
|
19
|
+
puts cmd
|
20
|
+
system cmd
|
21
|
+
|
22
|
+
sleep(2)
|
23
|
+
|
24
|
+
if sphinx_running?
|
25
|
+
puts "Started successfully (pid #{sphinx_pid})."
|
26
|
+
else
|
27
|
+
puts "Failed to start searchd daemon. Check #{config.searchd_log_file}."
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Stop Sphinx using Thinking Sphinx's settings"
|
32
|
+
task :stop => :app_env do
|
33
|
+
raise RuntimeError, "searchd is not running." unless sphinx_running?
|
34
|
+
pid = sphinx_pid
|
35
|
+
system "kill #{pid}"
|
36
|
+
puts "Stopped search daemon (pid #{pid})."
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Restart Sphinx"
|
40
|
+
task :restart => [:app_env, :stop, :start]
|
41
|
+
|
42
|
+
desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
|
43
|
+
task :configure => :app_env do
|
44
|
+
ThinkingSphinx::Configuration.new.build
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Index data for Sphinx using Thinking Sphinx's settings"
|
48
|
+
task :index => [:app_env, :configure] do
|
49
|
+
config = ThinkingSphinx::Configuration.new
|
50
|
+
|
51
|
+
FileUtils.mkdir_p config.searchd_file_path
|
52
|
+
cmd = "indexer --config #{config.config_file} --all"
|
53
|
+
cmd << " --rotate" if sphinx_running?
|
54
|
+
puts cmd
|
55
|
+
system cmd
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
namespace :ts do
|
60
|
+
desc "Start a Sphinx searchd daemon using Thinking Sphinx's settings"
|
61
|
+
task :start => "thinking_sphinx:start"
|
62
|
+
desc "Stop Sphinx using Thinking Sphinx's settings"
|
63
|
+
task :stop => "thinking_sphinx:stop"
|
64
|
+
desc "Index data for Sphinx using Thinking Sphinx's settings"
|
65
|
+
task :in => "thinking_sphinx:index"
|
66
|
+
desc "Index data for Sphinx using Thinking Sphinx's settings"
|
67
|
+
task :index => "thinking_sphinx:index"
|
68
|
+
desc "Restart Sphinx"
|
69
|
+
task :restart => "thinking_sphinx:restart"
|
70
|
+
desc "Generate the Sphinx configuration file using Thinking Sphinx's settings"
|
71
|
+
task :config => "thinking_sphinx:configure"
|
72
|
+
end
|
73
|
+
|
74
|
+
def sphinx_pid
|
75
|
+
config = ThinkingSphinx::Configuration.new
|
76
|
+
|
77
|
+
if File.exists?(config.pid_file)
|
78
|
+
`cat #{config.pid_file}`[/\d+/]
|
79
|
+
else
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def sphinx_running?
|
85
|
+
sphinx_pid && `ps -p #{sphinx_pid} | wc -l`.to_i > 1
|
86
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: freelancing-god-thinking-sphinx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pat Allan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-14 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
|
17
|
+
email: pat@freelancing-gods.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/riddle/client/filter.rb
|
26
|
+
- lib/riddle/client/message.rb
|
27
|
+
- lib/riddle/client/response.rb
|
28
|
+
- lib/riddle/client.rb
|
29
|
+
- lib/riddle.rb
|
30
|
+
- lib/test.rb
|
31
|
+
- lib/thinking_sphinx/active_record/delta.rb
|
32
|
+
- lib/thinking_sphinx/active_record/has_many_association.rb
|
33
|
+
- lib/thinking_sphinx/active_record/search.rb
|
34
|
+
- lib/thinking_sphinx/active_record.rb
|
35
|
+
- lib/thinking_sphinx/association.rb
|
36
|
+
- lib/thinking_sphinx/attribute.rb
|
37
|
+
- lib/thinking_sphinx/configuration.rb
|
38
|
+
- lib/thinking_sphinx/field.rb
|
39
|
+
- lib/thinking_sphinx/index/builder.rb
|
40
|
+
- lib/thinking_sphinx/index/faux_column.rb
|
41
|
+
- lib/thinking_sphinx/index.rb
|
42
|
+
- lib/thinking_sphinx/rails_additions.rb
|
43
|
+
- lib/thinking_sphinx/search.rb
|
44
|
+
- lib/thinking_sphinx.rb
|
45
|
+
- LICENCE
|
46
|
+
- README
|
47
|
+
- tasks/thinking_sphinx_tasks.rb
|
48
|
+
- tasks/thinking_sphinx_tasks.rake
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://ts.freelancing-gods.com
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --title
|
54
|
+
- Thinking Sphinx -- Rails/Merb Sphinx Plugin
|
55
|
+
- --line-numbers
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0"
|
63
|
+
version:
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
version:
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: thinking-sphinx
|
73
|
+
rubygems_version: 1.0.1
|
74
|
+
signing_key:
|
75
|
+
specification_version: 2
|
76
|
+
summary: A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.
|
77
|
+
test_files:
|
78
|
+
- spec/unit/thinking_sphinx/active_record/delta_spec.rb
|
79
|
+
- spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
|
80
|
+
- spec/unit/thinking_sphinx/active_record/search_spec.rb
|
81
|
+
- spec/unit/thinking_sphinx/active_record_spec.rb
|
82
|
+
- spec/unit/thinking_sphinx/association_spec.rb
|
83
|
+
- spec/unit/thinking_sphinx/attribute_spec.rb
|
84
|
+
- spec/unit/thinking_sphinx/configuration_spec.rb
|
85
|
+
- spec/unit/thinking_sphinx/field_spec.rb
|
86
|
+
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
87
|
+
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
88
|
+
- spec/unit/thinking_sphinx/index_spec.rb
|
89
|
+
- spec/unit/thinking_sphinx/search_spec.rb
|
90
|
+
- spec/unit/thinking_sphinx_spec.rb
|