DrMark-thinking-sphinx 0.9.9 → 1.1.6
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 +64 -2
- data/lib/thinking_sphinx.rb +88 -11
- data/lib/thinking_sphinx/active_record.rb +136 -21
- data/lib/thinking_sphinx/active_record/delta.rb +43 -62
- data/lib/thinking_sphinx/active_record/has_many_association.rb +1 -1
- data/lib/thinking_sphinx/active_record/search.rb +7 -0
- data/lib/thinking_sphinx/adapters/abstract_adapter.rb +42 -0
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +54 -0
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +130 -0
- data/lib/thinking_sphinx/association.rb +17 -0
- data/lib/thinking_sphinx/attribute.rb +171 -97
- data/lib/thinking_sphinx/collection.rb +126 -2
- data/lib/thinking_sphinx/configuration.rb +120 -171
- data/lib/thinking_sphinx/core/string.rb +15 -0
- data/lib/thinking_sphinx/deltas.rb +27 -0
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +50 -0
- data/lib/thinking_sphinx/deltas/default_delta.rb +67 -0
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +25 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +24 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +27 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +26 -0
- data/lib/thinking_sphinx/facet.rb +58 -0
- data/lib/thinking_sphinx/facet_collection.rb +60 -0
- data/lib/thinking_sphinx/field.rb +18 -52
- data/lib/thinking_sphinx/index.rb +246 -199
- data/lib/thinking_sphinx/index/builder.rb +85 -16
- data/lib/thinking_sphinx/rails_additions.rb +85 -5
- data/lib/thinking_sphinx/search.rb +459 -190
- data/lib/thinking_sphinx/tasks.rb +128 -0
- data/spec/unit/thinking_sphinx/active_record/delta_spec.rb +53 -124
- data/spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb +2 -2
- data/spec/unit/thinking_sphinx/active_record_spec.rb +110 -30
- data/spec/unit/thinking_sphinx/attribute_spec.rb +16 -149
- data/spec/unit/thinking_sphinx/collection_spec.rb +14 -0
- data/spec/unit/thinking_sphinx/configuration_spec.rb +54 -412
- data/spec/unit/thinking_sphinx/core/string_spec.rb +9 -0
- data/spec/unit/thinking_sphinx/field_spec.rb +0 -79
- data/spec/unit/thinking_sphinx/index/builder_spec.rb +1 -29
- data/spec/unit/thinking_sphinx/index/faux_column_spec.rb +1 -39
- data/spec/unit/thinking_sphinx/index_spec.rb +78 -226
- data/spec/unit/thinking_sphinx/search_spec.rb +29 -228
- data/spec/unit/thinking_sphinx_spec.rb +23 -19
- data/tasks/distribution.rb +48 -0
- data/tasks/rails.rake +1 -0
- data/tasks/testing.rb +86 -0
- data/vendor/after_commit/LICENSE +20 -0
- data/vendor/after_commit/README +16 -0
- data/vendor/after_commit/Rakefile +22 -0
- data/vendor/after_commit/init.rb +8 -0
- data/vendor/after_commit/lib/after_commit.rb +45 -0
- data/vendor/after_commit/lib/after_commit/active_record.rb +114 -0
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +103 -0
- data/vendor/after_commit/test/after_commit_test.rb +53 -0
- data/vendor/delayed_job/lib/delayed/job.rb +251 -0
- data/vendor/delayed_job/lib/delayed/message_sending.rb +7 -0
- data/vendor/delayed_job/lib/delayed/performable_method.rb +55 -0
- data/vendor/delayed_job/lib/delayed/worker.rb +54 -0
- data/{lib → vendor/riddle/lib}/riddle.rb +9 -5
- data/{lib → vendor/riddle/lib}/riddle/client.rb +6 -26
- data/{lib → vendor/riddle/lib}/riddle/client/filter.rb +10 -1
- data/{lib → vendor/riddle/lib}/riddle/client/message.rb +0 -0
- data/{lib → vendor/riddle/lib}/riddle/client/response.rb +0 -0
- data/vendor/riddle/lib/riddle/configuration.rb +33 -0
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +48 -0
- data/vendor/riddle/lib/riddle/configuration/index.rb +142 -0
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +19 -0
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +17 -0
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +25 -0
- data/vendor/riddle/lib/riddle/configuration/section.rb +37 -0
- data/vendor/riddle/lib/riddle/configuration/source.rb +23 -0
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +34 -0
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +28 -0
- data/vendor/riddle/lib/riddle/controller.rb +44 -0
- metadata +63 -10
- data/lib/test.rb +0 -46
- data/tasks/thinking_sphinx_tasks.rake +0 -1
- data/tasks/thinking_sphinx_tasks.rb +0 -86
@@ -0,0 +1,19 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class Indexer < Riddle::Configuration::Section
|
4
|
+
self.settings = [:mem_limit, :max_iops, :max_iosize]
|
5
|
+
|
6
|
+
attr_accessor *self.settings
|
7
|
+
|
8
|
+
def render
|
9
|
+
raise ConfigurationError unless valid?
|
10
|
+
|
11
|
+
(
|
12
|
+
["indexer", "{"] +
|
13
|
+
settings_body +
|
14
|
+
["}", ""]
|
15
|
+
).join("\n")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class RemoteIndex
|
4
|
+
attr_accessor :address, :port, :name
|
5
|
+
|
6
|
+
def initialize(address, port, name)
|
7
|
+
@address = address
|
8
|
+
@port = port
|
9
|
+
@name = name
|
10
|
+
end
|
11
|
+
|
12
|
+
def remote
|
13
|
+
"#{address}:#{port}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class Searchd < Riddle::Configuration::Section
|
4
|
+
self.settings = [:address, :port, :log, :query_log, :read_timeout,
|
5
|
+
:max_children, :pid_file, :max_matches, :seamless_rotate,
|
6
|
+
:preopen_indexes, :unlink_old]
|
7
|
+
|
8
|
+
attr_accessor *self.settings
|
9
|
+
|
10
|
+
def render
|
11
|
+
raise ConfigurationError unless valid?
|
12
|
+
|
13
|
+
(
|
14
|
+
["searchd", "{"] +
|
15
|
+
settings_body +
|
16
|
+
["}", ""]
|
17
|
+
).join("\n")
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid?
|
21
|
+
!( @port.nil? || @pid_file.nil? )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class Section
|
4
|
+
class << self
|
5
|
+
attr_accessor :settings
|
6
|
+
end
|
7
|
+
|
8
|
+
settings = []
|
9
|
+
|
10
|
+
def valid?
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def settings_body
|
17
|
+
self.class.settings.select { |setting|
|
18
|
+
!send(setting).nil?
|
19
|
+
}.collect { |setting|
|
20
|
+
if send(setting) == ""
|
21
|
+
conf = " #{setting} = "
|
22
|
+
else
|
23
|
+
conf = setting_to_array(setting).collect { |set|
|
24
|
+
" #{setting} = #{set}"
|
25
|
+
}
|
26
|
+
end
|
27
|
+
conf.length == 0 ? nil : conf
|
28
|
+
}.flatten.compact
|
29
|
+
end
|
30
|
+
|
31
|
+
def setting_to_array(setting)
|
32
|
+
value = send(setting)
|
33
|
+
value.is_a?(Array) ? value : [value]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class Source < Riddle::Configuration::Section
|
4
|
+
attr_accessor :name, :parent, :type
|
5
|
+
|
6
|
+
def render
|
7
|
+
raise ConfigurationError unless valid?
|
8
|
+
|
9
|
+
inherited_name = "#{name}"
|
10
|
+
inherited_name << " : #{parent}" if parent
|
11
|
+
(
|
12
|
+
["source #{inherited_name}", "{"] +
|
13
|
+
settings_body +
|
14
|
+
["}", ""]
|
15
|
+
).join("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid?
|
19
|
+
!( @name.nil? || @type.nil? )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class SQLSource < Riddle::Configuration::Source
|
4
|
+
self.settings = [:type, :sql_host, :sql_user, :sql_pass, :sql_db,
|
5
|
+
:sql_port, :sql_sock, :mysql_connect_flags, :sql_query_pre, :sql_query,
|
6
|
+
:sql_query_range, :sql_range_step, :sql_attr_uint, :sql_attr_bool,
|
7
|
+
:sql_attr_timestamp, :sql_attr_str2ordinal, :sql_attr_float,
|
8
|
+
:sql_attr_multi, :sql_query_post, :sql_query_post_index,
|
9
|
+
:sql_ranged_throttle, :sql_query_info]
|
10
|
+
|
11
|
+
attr_accessor *self.settings
|
12
|
+
|
13
|
+
def initialize(name, type)
|
14
|
+
@name = name
|
15
|
+
@type = type
|
16
|
+
|
17
|
+
@sql_query_pre = []
|
18
|
+
@sql_attr_uint = []
|
19
|
+
@sql_attr_bool = []
|
20
|
+
@sql_attr_timestamp = []
|
21
|
+
@sql_attr_str2ordinal = []
|
22
|
+
@sql_attr_float = []
|
23
|
+
@sql_attr_multi = []
|
24
|
+
@sql_query_post = []
|
25
|
+
@sql_query_post_index = []
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid?
|
29
|
+
super && (!( @sql_host.nil? || @sql_user.nil? || @sql_db.nil? ||
|
30
|
+
@sql_query.nil? ) || !@parent.nil?)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Configuration
|
3
|
+
class XMLSource < Riddle::Configuration::Source
|
4
|
+
self.settings = [:type, :xmlpipe_command, :xmlpipe_field,
|
5
|
+
:xmlpipe_attr_uint, :xmlpipe_attr_bool, :xmlpipe_attr_timestamp,
|
6
|
+
:xmlpipe_attr_str2ordinal, :xmlpipe_attr_float, :xmlpipe_attr_multi]
|
7
|
+
|
8
|
+
attr_accessor *self.settings
|
9
|
+
|
10
|
+
def initialize(name, type)
|
11
|
+
@name = name
|
12
|
+
@type = type
|
13
|
+
|
14
|
+
@xmlpipe_field = []
|
15
|
+
@xmlpipe_attr_uint = []
|
16
|
+
@xmlpipe_attr_bool = []
|
17
|
+
@xmlpipe_attr_timestamp = []
|
18
|
+
@xmlpipe_attr_str2ordinal = []
|
19
|
+
@xmlpipe_attr_float = []
|
20
|
+
@xmlpipe_attr_multi = []
|
21
|
+
end
|
22
|
+
|
23
|
+
def valid?
|
24
|
+
super && ( !@xmlpipe_command.nil? || !parent.nil? )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Riddle
|
2
|
+
class Controller
|
3
|
+
def initialize(configuration, path)
|
4
|
+
@configuration = configuration
|
5
|
+
@path = path
|
6
|
+
end
|
7
|
+
|
8
|
+
def index
|
9
|
+
cmd = "indexer --config #{@path} --all"
|
10
|
+
cmd << " --rotate" if running?
|
11
|
+
`#{cmd}`
|
12
|
+
end
|
13
|
+
|
14
|
+
def start
|
15
|
+
return if running?
|
16
|
+
|
17
|
+
cmd = "searchd --pidfile --config #{@path}"
|
18
|
+
`#{cmd}`
|
19
|
+
|
20
|
+
sleep(1)
|
21
|
+
|
22
|
+
unless running?
|
23
|
+
puts "Failed to start searchd daemon. Check #{@configuration.searchd.log}."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
return unless running?
|
29
|
+
`kill #{pid}`
|
30
|
+
end
|
31
|
+
|
32
|
+
def pid
|
33
|
+
if File.exists?("#{@configuration.searchd.pid_file}")
|
34
|
+
`cat #{@configuration.searchd.pid_file}`[/\d+/]
|
35
|
+
else
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def running?
|
41
|
+
pid && `ps #{pid} | wc -l`.to_i > 1
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: DrMark-thinking-sphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pat Allan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-03-11 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,38 +22,89 @@ extensions: []
|
|
22
22
|
extra_rdoc_files: []
|
23
23
|
|
24
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
25
|
- lib/thinking_sphinx/active_record/delta.rb
|
32
26
|
- lib/thinking_sphinx/active_record/has_many_association.rb
|
33
27
|
- lib/thinking_sphinx/active_record/search.rb
|
34
28
|
- lib/thinking_sphinx/active_record.rb
|
29
|
+
- lib/thinking_sphinx/adapters/abstract_adapter.rb
|
30
|
+
- lib/thinking_sphinx/adapters/mysql_adapter.rb
|
31
|
+
- lib/thinking_sphinx/adapters/postgresql_adapter.rb
|
35
32
|
- lib/thinking_sphinx/association.rb
|
36
33
|
- lib/thinking_sphinx/attribute.rb
|
37
34
|
- lib/thinking_sphinx/collection.rb
|
38
35
|
- lib/thinking_sphinx/configuration.rb
|
36
|
+
- lib/thinking_sphinx/core/string.rb
|
37
|
+
- lib/thinking_sphinx/deltas/datetime_delta.rb
|
38
|
+
- lib/thinking_sphinx/deltas/default_delta.rb
|
39
|
+
- lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb
|
40
|
+
- lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb
|
41
|
+
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
|
42
|
+
- lib/thinking_sphinx/deltas/delayed_delta.rb
|
43
|
+
- lib/thinking_sphinx/deltas.rb
|
44
|
+
- lib/thinking_sphinx/facet.rb
|
45
|
+
- lib/thinking_sphinx/facet_collection.rb
|
39
46
|
- lib/thinking_sphinx/field.rb
|
40
47
|
- lib/thinking_sphinx/index/builder.rb
|
41
48
|
- lib/thinking_sphinx/index/faux_column.rb
|
42
49
|
- lib/thinking_sphinx/index.rb
|
43
50
|
- lib/thinking_sphinx/rails_additions.rb
|
44
51
|
- lib/thinking_sphinx/search.rb
|
52
|
+
- lib/thinking_sphinx/tasks.rb
|
45
53
|
- lib/thinking_sphinx.rb
|
46
54
|
- LICENCE
|
47
55
|
- README
|
48
|
-
- tasks/
|
49
|
-
- tasks/
|
56
|
+
- tasks/distribution.rb
|
57
|
+
- tasks/testing.rb
|
58
|
+
- tasks/rails.rake
|
59
|
+
- vendor/after_commit
|
60
|
+
- vendor/after_commit/init.rb
|
61
|
+
- vendor/after_commit/lib
|
62
|
+
- vendor/after_commit/lib/after_commit
|
63
|
+
- vendor/after_commit/lib/after_commit/active_record.rb
|
64
|
+
- vendor/after_commit/lib/after_commit/connection_adapters.rb
|
65
|
+
- vendor/after_commit/lib/after_commit.rb
|
66
|
+
- vendor/after_commit/LICENSE
|
67
|
+
- vendor/after_commit/Rakefile
|
68
|
+
- vendor/after_commit/README
|
69
|
+
- vendor/after_commit/test
|
70
|
+
- vendor/after_commit/test/after_commit_test.rb
|
71
|
+
- vendor/delayed_job
|
72
|
+
- vendor/delayed_job/lib
|
73
|
+
- vendor/delayed_job/lib/delayed
|
74
|
+
- vendor/delayed_job/lib/delayed/job.rb
|
75
|
+
- vendor/delayed_job/lib/delayed/message_sending.rb
|
76
|
+
- vendor/delayed_job/lib/delayed/performable_method.rb
|
77
|
+
- vendor/delayed_job/lib/delayed/worker.rb
|
78
|
+
- vendor/riddle
|
79
|
+
- vendor/riddle/lib
|
80
|
+
- vendor/riddle/lib/riddle
|
81
|
+
- vendor/riddle/lib/riddle/client
|
82
|
+
- vendor/riddle/lib/riddle/client/filter.rb
|
83
|
+
- vendor/riddle/lib/riddle/client/message.rb
|
84
|
+
- vendor/riddle/lib/riddle/client/response.rb
|
85
|
+
- vendor/riddle/lib/riddle/client.rb
|
86
|
+
- vendor/riddle/lib/riddle/configuration
|
87
|
+
- vendor/riddle/lib/riddle/configuration/distributed_index.rb
|
88
|
+
- vendor/riddle/lib/riddle/configuration/index.rb
|
89
|
+
- vendor/riddle/lib/riddle/configuration/indexer.rb
|
90
|
+
- vendor/riddle/lib/riddle/configuration/remote_index.rb
|
91
|
+
- vendor/riddle/lib/riddle/configuration/searchd.rb
|
92
|
+
- vendor/riddle/lib/riddle/configuration/section.rb
|
93
|
+
- vendor/riddle/lib/riddle/configuration/source.rb
|
94
|
+
- vendor/riddle/lib/riddle/configuration/sql_source.rb
|
95
|
+
- vendor/riddle/lib/riddle/configuration/xml_source.rb
|
96
|
+
- vendor/riddle/lib/riddle/configuration.rb
|
97
|
+
- vendor/riddle/lib/riddle/controller.rb
|
98
|
+
- vendor/riddle/lib/riddle.rb
|
50
99
|
- spec/unit/thinking_sphinx/active_record/delta_spec.rb
|
51
100
|
- spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb
|
52
101
|
- spec/unit/thinking_sphinx/active_record/search_spec.rb
|
53
102
|
- spec/unit/thinking_sphinx/active_record_spec.rb
|
54
103
|
- spec/unit/thinking_sphinx/association_spec.rb
|
55
104
|
- spec/unit/thinking_sphinx/attribute_spec.rb
|
105
|
+
- spec/unit/thinking_sphinx/collection_spec.rb
|
56
106
|
- spec/unit/thinking_sphinx/configuration_spec.rb
|
107
|
+
- spec/unit/thinking_sphinx/core/string_spec.rb
|
57
108
|
- spec/unit/thinking_sphinx/field_spec.rb
|
58
109
|
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
59
110
|
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
@@ -95,7 +146,9 @@ test_files:
|
|
95
146
|
- spec/unit/thinking_sphinx/active_record_spec.rb
|
96
147
|
- spec/unit/thinking_sphinx/association_spec.rb
|
97
148
|
- spec/unit/thinking_sphinx/attribute_spec.rb
|
149
|
+
- spec/unit/thinking_sphinx/collection_spec.rb
|
98
150
|
- spec/unit/thinking_sphinx/configuration_spec.rb
|
151
|
+
- spec/unit/thinking_sphinx/core/string_spec.rb
|
99
152
|
- spec/unit/thinking_sphinx/field_spec.rb
|
100
153
|
- spec/unit/thinking_sphinx/index/builder_spec.rb
|
101
154
|
- spec/unit/thinking_sphinx/index/faux_column_spec.rb
|
data/lib/test.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'thinking_sphinx'
|
2
|
-
|
3
|
-
ActiveRecord::Base.establish_connection(
|
4
|
-
:adapter => 'mysql',
|
5
|
-
:database => 'nullus_development',
|
6
|
-
:username => 'nullus',
|
7
|
-
:password => 'wossname',
|
8
|
-
:host => 'localhost'
|
9
|
-
)
|
10
|
-
ActiveRecord::Base.logger = Logger.new(STDERR)
|
11
|
-
|
12
|
-
class User < ActiveRecord::Base
|
13
|
-
has_many :posts, :foreign_key => "created_by"
|
14
|
-
end
|
15
|
-
|
16
|
-
class Post < ActiveRecord::Base
|
17
|
-
belongs_to :creator, :foreign_key => "created_by", :class_name => "User"
|
18
|
-
belongs_to :updater, :foreign_key => "updated_by", :class_name => "User"
|
19
|
-
belongs_to :topic
|
20
|
-
end
|
21
|
-
|
22
|
-
class Topic < ActiveRecord::Base
|
23
|
-
belongs_to :creator, :foreign_key => "created_by", :class_name => "User"
|
24
|
-
belongs_to :forum
|
25
|
-
has_many :posts
|
26
|
-
end
|
27
|
-
|
28
|
-
class Forum < ActiveRecord::Base
|
29
|
-
belongs_to :creator, :foreign_key => "created_by", :class_name => "User"
|
30
|
-
has_many :topics
|
31
|
-
end
|
32
|
-
|
33
|
-
def index
|
34
|
-
@index ||= ThinkingSphinx::Index.new(Topic) do
|
35
|
-
indexes posts.content, :as => :posts
|
36
|
-
indexes posts.creator.login, :as => :authors
|
37
|
-
|
38
|
-
has :created_at
|
39
|
-
has :id, :as => :topic_id
|
40
|
-
has :forum_id
|
41
|
-
has posts(:id), :as => :post_ids
|
42
|
-
has posts.creator(:id), :as => :user_ids
|
43
|
-
|
44
|
-
where "posts.created_at < NOW()"
|
45
|
-
end
|
46
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'thinking_sphinx_tasks')
|
@@ -1,86 +0,0 @@
|
|
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_init].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
|