yoomee-mongosphinx 0.1.5 → 0.1.8
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/lib/.DS_Store +0 -0
- data/{mongosphinx.rb → lib/mongo_sphinx.rb} +31 -5
- data/lib/mongo_sphinx/.DS_Store +0 -0
- data/lib/mongo_sphinx/configuration.rb +197 -0
- data/lib/{indexer.rb → mongo_sphinx/indexer.rb} +0 -0
- data/lib/mongo_sphinx/mixins/.DS_Store +0 -0
- data/lib/{mixins → mongo_sphinx/mixins}/indexer.rb +7 -3
- data/lib/{mixins → mongo_sphinx/mixins}/properties.rb +0 -0
- data/lib/{multi_attribute.rb → mongo_sphinx/multi_attribute.rb} +0 -0
- data/lib/mongo_sphinx/tasks.rb +126 -0
- metadata +14 -9
data/lib/.DS_Store
ADDED
Binary file
|
@@ -11,17 +11,43 @@ require 'mongo_mapper'
|
|
11
11
|
require 'riddle'
|
12
12
|
|
13
13
|
module MongoSphinx
|
14
|
-
if (match = __FILE__.match(
|
14
|
+
if (match = __FILE__.match(/.*mongo_sphinx-([0-9.-]*)/))
|
15
15
|
VERSION = match[1]
|
16
16
|
else
|
17
17
|
VERSION = 'unknown'
|
18
18
|
end
|
19
|
+
|
20
|
+
# Check if Sphinx is running.
|
21
|
+
|
22
|
+
def self.sphinx_running?
|
23
|
+
!!sphinx_pid && pid_active?(sphinx_pid)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get the Sphinx pid if the pid file exists.
|
27
|
+
|
28
|
+
def self.sphinx_pid
|
29
|
+
if File.exists?(MongoSphinx::Configuration.instance.pid_file)
|
30
|
+
File.read(MongoSphinx::Configuration.instance.pid_file)[/\d+/]
|
31
|
+
else
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.pid_active?(pid)
|
37
|
+
!!Process.kill(0, pid.to_i)
|
38
|
+
rescue Errno::EPERM => e
|
39
|
+
true
|
40
|
+
rescue Exception => e
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
19
44
|
end
|
20
45
|
|
21
|
-
require '
|
22
|
-
require '
|
23
|
-
require '
|
24
|
-
require '
|
46
|
+
require 'mongo_sphinx/multi_attribute'
|
47
|
+
require 'mongo_sphinx/configuration'
|
48
|
+
require 'mongo_sphinx/indexer'
|
49
|
+
require 'mongo_sphinx/mixins/indexer'
|
50
|
+
require 'mongo_sphinx/mixins/properties'
|
25
51
|
|
26
52
|
|
27
53
|
# Include the Indexer mixin from the original Document class of
|
Binary file
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'singleton'
|
3
|
+
|
4
|
+
module MongoSphinx
|
5
|
+
# This class both keeps track of the configuration settings for Sphinx and
|
6
|
+
# also generates the resulting file for Sphinx to use.
|
7
|
+
#
|
8
|
+
# Here are the default settings, relative to RAILS_ROOT where relevant:
|
9
|
+
#
|
10
|
+
# config file:: config/#{environment}.sphinx.conf
|
11
|
+
# searchd log file:: log/searchd.log
|
12
|
+
# query log file:: log/searchd.query.log
|
13
|
+
# pid file:: log/searchd.#{environment}.pid
|
14
|
+
# searchd files:: db/sphinx/#{environment}/
|
15
|
+
# address:: 127.0.0.1
|
16
|
+
# port:: 9312
|
17
|
+
# allow star:: false
|
18
|
+
# min prefix length:: 1
|
19
|
+
# min infix length:: 1
|
20
|
+
# mem limit:: 64M
|
21
|
+
# max matches:: 1000
|
22
|
+
# morphology:: nil
|
23
|
+
# charset type:: utf-8
|
24
|
+
# charset table:: nil
|
25
|
+
# ignore chars:: nil
|
26
|
+
# html strip:: false
|
27
|
+
# html remove elements:: ''
|
28
|
+
# searchd_binary_name:: searchd
|
29
|
+
# indexer_binary_name:: indexer
|
30
|
+
#
|
31
|
+
# If you want to change these settings, create a YAML file at
|
32
|
+
# config/sphinx.yml with settings for each environment, in a similar
|
33
|
+
# fashion to database.yml - using the following keys: config_file,
|
34
|
+
# searchd_log_file, query_log_file, pid_file, searchd_file_path, port,
|
35
|
+
# allow_star, enable_star, min_prefix_len, min_infix_len, mem_limit,
|
36
|
+
# max_matches, morphology, charset_type, charset_table, ignore_chars,
|
37
|
+
# html_strip, html_remove_elements, delayed_job_priority,
|
38
|
+
# searchd_binary_name, indexer_binary_name.
|
39
|
+
#
|
40
|
+
# I think you've got the idea.
|
41
|
+
#
|
42
|
+
# Each setting in the YAML file is optional - so only put in the ones you
|
43
|
+
# want to change.
|
44
|
+
#
|
45
|
+
# Keep in mind, if for some particular reason you're using a version of
|
46
|
+
# Sphinx older than 0.9.8 r871 (that's prior to the proper 0.9.8 release),
|
47
|
+
# don't set allow_star to true.
|
48
|
+
#
|
49
|
+
class Configuration
|
50
|
+
include Singleton
|
51
|
+
|
52
|
+
attr_accessor :searchd_file_path, :allow_star,:app_root, :delayed_job_priority
|
53
|
+
attr_accessor :version
|
54
|
+
|
55
|
+
attr_accessor :source_options, :index_options
|
56
|
+
|
57
|
+
attr_reader :environment, :configuration, :controller
|
58
|
+
|
59
|
+
def initialize(app_root = Dir.pwd)
|
60
|
+
self.reset
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.configure(&block)
|
64
|
+
yield instance
|
65
|
+
instance.reset(instance.app_root)
|
66
|
+
end
|
67
|
+
|
68
|
+
def reset(custom_app_root=nil)
|
69
|
+
if custom_app_root
|
70
|
+
self.app_root = custom_app_root
|
71
|
+
else
|
72
|
+
self.app_root = RAILS_ROOT if defined?(RAILS_ROOT)
|
73
|
+
self.app_root = Merb.root if defined?(Merb)
|
74
|
+
self.app_root ||= app_root
|
75
|
+
end
|
76
|
+
|
77
|
+
@configuration = Riddle::Configuration.new
|
78
|
+
@configuration.searchd.pid_file = "#{self.app_root}/log/mongo_sphinx.searchd.#{environment}.pid"
|
79
|
+
@configuration.searchd.log = "#{self.app_root}/log/mongo_sphinx.searchd.log"
|
80
|
+
@configuration.searchd.query_log = "#{self.app_root}/log/mongo_sphinx.query.log"
|
81
|
+
|
82
|
+
@controller = Riddle::Controller.new @configuration,
|
83
|
+
"#{self.app_root}/config/#{environment}.mongo_sphinx.conf"
|
84
|
+
|
85
|
+
self.address = "127.0.0.1"
|
86
|
+
self.port = 9312
|
87
|
+
self.searchd_file_path = "#{self.app_root}/db/mongo_sphinx/#{environment}"
|
88
|
+
self.allow_star = false
|
89
|
+
self.delayed_job_priority = 0
|
90
|
+
self.source_options = {}
|
91
|
+
self.index_options = {
|
92
|
+
:charset_type => "utf-8"
|
93
|
+
}
|
94
|
+
|
95
|
+
self.version = nil
|
96
|
+
self.version ||= @controller.sphinx_version
|
97
|
+
|
98
|
+
self
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.environment
|
102
|
+
Thread.current[:mongo_sphinx_environment] ||= begin
|
103
|
+
if defined?(Merb)
|
104
|
+
Merb.environment
|
105
|
+
elsif defined?(RAILS_ENV)
|
106
|
+
RAILS_ENV
|
107
|
+
else
|
108
|
+
ENV['RAILS_ENV'] || 'development'
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def environment
|
114
|
+
self.class.environment
|
115
|
+
end
|
116
|
+
|
117
|
+
def address
|
118
|
+
@address
|
119
|
+
end
|
120
|
+
|
121
|
+
def address=(address)
|
122
|
+
@address = address
|
123
|
+
@configuration.searchd.address = address
|
124
|
+
end
|
125
|
+
|
126
|
+
def port
|
127
|
+
@port
|
128
|
+
end
|
129
|
+
|
130
|
+
def port=(port)
|
131
|
+
@port = port
|
132
|
+
@configuration.searchd.port = port
|
133
|
+
end
|
134
|
+
|
135
|
+
def pid_file
|
136
|
+
@configuration.searchd.pid_file
|
137
|
+
end
|
138
|
+
|
139
|
+
def pid_file=(pid_file)
|
140
|
+
@configuration.searchd.pid_file = pid_file
|
141
|
+
end
|
142
|
+
|
143
|
+
def searchd_log_file
|
144
|
+
@configuration.searchd.log
|
145
|
+
end
|
146
|
+
|
147
|
+
def searchd_log_file=(file)
|
148
|
+
@configuration.searchd.log = file
|
149
|
+
end
|
150
|
+
|
151
|
+
def query_log_file
|
152
|
+
@configuration.searchd.query_log
|
153
|
+
end
|
154
|
+
|
155
|
+
def query_log_file=(file)
|
156
|
+
@configuration.searchd.query_log = file
|
157
|
+
end
|
158
|
+
|
159
|
+
def config_file
|
160
|
+
@controller.path
|
161
|
+
end
|
162
|
+
|
163
|
+
def config_file=(file)
|
164
|
+
@controller.path = file
|
165
|
+
end
|
166
|
+
|
167
|
+
def bin_path
|
168
|
+
@controller.bin_path
|
169
|
+
end
|
170
|
+
|
171
|
+
def bin_path=(path)
|
172
|
+
@controller.bin_path = path
|
173
|
+
end
|
174
|
+
|
175
|
+
def searchd_binary_name
|
176
|
+
@controller.searchd_binary_name
|
177
|
+
end
|
178
|
+
|
179
|
+
def searchd_binary_name=(name)
|
180
|
+
@controller.searchd_binary_name = name
|
181
|
+
end
|
182
|
+
|
183
|
+
def indexer_binary_name
|
184
|
+
@controller.indexer_binary_name
|
185
|
+
end
|
186
|
+
|
187
|
+
def indexer_binary_name=(name)
|
188
|
+
@controller.indexer_binary_name = name
|
189
|
+
end
|
190
|
+
|
191
|
+
def client
|
192
|
+
client = Riddle::Client.new address, port
|
193
|
+
client.max_matches = configuration.searchd.max_matches || 1000
|
194
|
+
client
|
195
|
+
end
|
196
|
+
end
|
197
|
+
end
|
File without changes
|
Binary file
|
@@ -107,6 +107,9 @@ module MongoMapper # :nodoc:
|
|
107
107
|
attr_accessor :skip_delta_index
|
108
108
|
alias_method :skip_delta_index?, :skip_delta_index
|
109
109
|
|
110
|
+
attr_accessor :skip_set_delta
|
111
|
+
alias_method :skip_set_delta?, :skip_set_delta
|
112
|
+
|
110
113
|
self.has_delta_index = opts[:delta] || false
|
111
114
|
|
112
115
|
self.fulltext_keys = keys
|
@@ -130,7 +133,7 @@ module MongoMapper # :nodoc:
|
|
130
133
|
self.class::reindex_delta unless self.skip_delta_index?
|
131
134
|
end
|
132
135
|
define_method(:set_delta) do
|
133
|
-
self.delta = true
|
136
|
+
self.delta = true unless self.skip_set_delta?
|
134
137
|
end
|
135
138
|
end
|
136
139
|
|
@@ -140,7 +143,7 @@ module MongoMapper # :nodoc:
|
|
140
143
|
end
|
141
144
|
define_method :reindex_core do
|
142
145
|
Rails.logger.info("reindexing #{self.to_s.underscore}_core")
|
143
|
-
Process.fork {`rake
|
146
|
+
Process.fork {`rake mongo_sphinx:rebuild index=#{self.to_s.underscore}_core`}
|
144
147
|
end
|
145
148
|
if opts[:delta]
|
146
149
|
define_method :xml_for_sphinx_delta do
|
@@ -148,7 +151,7 @@ module MongoMapper # :nodoc:
|
|
148
151
|
end
|
149
152
|
define_method :reindex_delta do
|
150
153
|
Rails.logger.info("reindexing #{self.to_s.underscore}_delta")
|
151
|
-
Process.fork {`rake
|
154
|
+
Process.fork {`rake mongo_sphinx:rebuild index=#{self.to_s.underscore}_delta`}
|
152
155
|
end
|
153
156
|
end
|
154
157
|
end
|
@@ -209,6 +212,7 @@ module MongoMapper # :nodoc:
|
|
209
212
|
index_names += "#{class_name.underscore}_core "
|
210
213
|
index_names += "#{class_name.underscore}_delta " if class_name.camelize.constantize.has_delta_index
|
211
214
|
end
|
215
|
+
debugger
|
212
216
|
index_names = "*" if index_names.blank?
|
213
217
|
result = client.query(query, index_names)
|
214
218
|
|
File without changes
|
File without changes
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
namespace :mongo_sphinx do
|
4
|
+
task :app_env do
|
5
|
+
if defined?(RAILS_ROOT)
|
6
|
+
Rake::Task[:environment].invoke
|
7
|
+
|
8
|
+
if defined?(Rails.configuration)
|
9
|
+
Rails.configuration.cache_classes = false
|
10
|
+
else
|
11
|
+
Rails::Initializer.run { |config| config.cache_classes = false }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Rake::Task[:merb_env].invoke if defined?(Merb)
|
16
|
+
end
|
17
|
+
|
18
|
+
desc "Output the current Mongo Sphinx version"
|
19
|
+
task :version => :app_env do
|
20
|
+
puts "Mongo Sphinx v" + MongoSphinx.version
|
21
|
+
end
|
22
|
+
|
23
|
+
desc "Stop if running, then start a Sphinx searchd daemon using Mongo Sphinx's settings"
|
24
|
+
task :running_start => :app_env do
|
25
|
+
Rake::Task["mongo_sphinx:stop"].invoke if sphinx_running?
|
26
|
+
Rake::Task["mongo_sphinx:start"].invoke
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Start a Sphinx searchd daemon using Mongo Sphinx's settings"
|
30
|
+
task :start => :app_env do
|
31
|
+
config = MongoSphinx::Configuration.instance
|
32
|
+
|
33
|
+
FileUtils.mkdir_p config.searchd_file_path
|
34
|
+
raise RuntimeError, "searchd is already running." if sphinx_running?
|
35
|
+
|
36
|
+
Dir["#{config.searchd_file_path}/*.spl"].each { |file| File.delete(file) }
|
37
|
+
|
38
|
+
config.controller.start
|
39
|
+
|
40
|
+
if sphinx_running?
|
41
|
+
puts "Started successfully (pid #{sphinx_pid})."
|
42
|
+
else
|
43
|
+
puts "Failed to start searchd daemon. Check #{config.searchd_log_file}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "Stop Sphinx using Mongo Sphinx's settings"
|
48
|
+
task :stop => :app_env do
|
49
|
+
unless sphinx_running?
|
50
|
+
puts "searchd is not running"
|
51
|
+
else
|
52
|
+
config = MongoSphinx::Configuration.instance
|
53
|
+
pid = sphinx_pid
|
54
|
+
config.controller.stop
|
55
|
+
puts "Stopped search daemon (pid #{pid})."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
desc "Restart Sphinx"
|
60
|
+
task :restart => [:app_env, :stop, :start]
|
61
|
+
|
62
|
+
desc "Generate the Sphinx configuration file using Mongo Sphinx's settings"
|
63
|
+
task :configure => :app_env do
|
64
|
+
config = MongoSphinx::Configuration.instance
|
65
|
+
puts "Generating Configuration to #{config.config_file}"
|
66
|
+
config.build
|
67
|
+
end
|
68
|
+
|
69
|
+
desc "Index data for Sphinx using Mongo Sphinx's settings"
|
70
|
+
task :index => :app_env do
|
71
|
+
config = MongoSphinx::Configuration.instance
|
72
|
+
# unless ENV["INDEX_ONLY"] == "true"
|
73
|
+
# puts "Generating Configuration to #{config.config_file}"
|
74
|
+
# config.build
|
75
|
+
# end
|
76
|
+
|
77
|
+
FileUtils.mkdir_p config.searchd_file_path
|
78
|
+
config.controller.index :verbose => true
|
79
|
+
end
|
80
|
+
|
81
|
+
desc "Reindex Sphinx without regenerating the configuration file"
|
82
|
+
task :reindex => :app_env do
|
83
|
+
config = MongoSphinx::Configuration.instance
|
84
|
+
FileUtils.mkdir_p config.searchd_file_path
|
85
|
+
puts config.controller.index
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx"
|
89
|
+
task :rebuild => :app_env do
|
90
|
+
Rake::Task["mongo_sphinx:stop"].invoke if sphinx_running?
|
91
|
+
Rake::Task["mongo_sphinx:index"].invoke
|
92
|
+
Rake::Task["mongo_sphinx:start"].invoke
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
namespace :ms do
|
97
|
+
desc "Output the current Mongo Sphinx version"
|
98
|
+
task :version => "mongo_sphinx:version"
|
99
|
+
desc "Stop if running, then start a Sphinx searchd daemon using Mongo Sphinx's settings"
|
100
|
+
task :run => "mongo_sphinx:running_start"
|
101
|
+
desc "Start a Sphinx searchd daemon using Mongo Sphinx's settings"
|
102
|
+
task :start => "mongo_sphinx:start"
|
103
|
+
desc "Stop Sphinx using Mongo Sphinx's settings"
|
104
|
+
task :stop => "mongo_sphinx:stop"
|
105
|
+
desc "Index data for Sphinx using Mongo Sphinx's settings"
|
106
|
+
task :in => "mongo_sphinx:index"
|
107
|
+
task :index => "mongo_sphinx:index"
|
108
|
+
desc "Reindex Sphinx without regenerating the configuration file"
|
109
|
+
task :reindex => "mongo_sphinx:reindex"
|
110
|
+
desc "Restart Sphinx"
|
111
|
+
task :restart => "mongo_sphinx:restart"
|
112
|
+
desc "Generate the Sphinx configuration file using Mongo Sphinx's settings"
|
113
|
+
task :conf => "mongo_sphinx:configure"
|
114
|
+
desc "Generate the Sphinx configuration file using Mongo Sphinx's settings"
|
115
|
+
task :config => "mongo_sphinx:configure"
|
116
|
+
desc "Stop Sphinx (if it's running), rebuild the indexes, and start Sphinx"
|
117
|
+
task :rebuild => "mongo_sphinx:rebuild"
|
118
|
+
end
|
119
|
+
|
120
|
+
def sphinx_pid
|
121
|
+
MongoSphinx.sphinx_pid
|
122
|
+
end
|
123
|
+
|
124
|
+
def sphinx_running?
|
125
|
+
MongoSphinx.sphinx_running?
|
126
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yoomee-mongosphinx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 8
|
10
|
+
version: 0.1.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matt Atkins
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-24 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -29,11 +29,16 @@ extra_rdoc_files:
|
|
29
29
|
- README.rdoc
|
30
30
|
files:
|
31
31
|
- README.rdoc
|
32
|
-
-
|
33
|
-
- lib/
|
34
|
-
- lib/
|
35
|
-
- lib/mixins/
|
36
|
-
- lib/indexer.rb
|
32
|
+
- lib/mongo_sphinx.rb
|
33
|
+
- lib/mongo_sphinx/tasks.rb
|
34
|
+
- lib/mongo_sphinx/multi_attribute.rb
|
35
|
+
- lib/mongo_sphinx/mixins/properties.rb
|
36
|
+
- lib/mongo_sphinx/mixins/indexer.rb
|
37
|
+
- lib/mongo_sphinx/mixins/.DS_Store
|
38
|
+
- lib/mongo_sphinx/indexer.rb
|
39
|
+
- lib/mongo_sphinx/configuration.rb
|
40
|
+
- lib/mongo_sphinx/.DS_Store
|
41
|
+
- lib/.DS_Store
|
37
42
|
has_rdoc: true
|
38
43
|
homepage: http://github.com/yoomee/mongosphinx
|
39
44
|
licenses: []
|