warp-thinking-sphinx 1.2.12 → 1.3.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +21 -4
- data/VERSION +1 -0
- data/features/abstract_inheritance.feature +10 -0
- data/features/alternate_primary_key.feature +1 -1
- data/features/attribute_updates.feature +22 -5
- data/features/deleting_instances.feature +3 -0
- data/features/facets.feature +6 -0
- data/features/facets_across_model.feature +2 -2
- data/features/searching_across_models.feature +1 -1
- data/features/searching_by_index.feature +40 -0
- data/features/sphinx_scopes.feature +7 -0
- data/features/step_definitions/alpha_steps.rb +14 -1
- data/features/step_definitions/beta_steps.rb +1 -1
- data/features/step_definitions/common_steps.rb +12 -2
- data/features/step_definitions/facet_steps.rb +5 -1
- data/features/step_definitions/scope_steps.rb +4 -0
- data/features/step_definitions/sphinx_steps.rb +8 -4
- data/features/sti_searching.feature +5 -0
- data/features/support/{db/database.example.yml → database.example.yml} +0 -0
- data/features/support/db/fixtures/foxes.rb +3 -0
- data/features/support/db/fixtures/music.rb +4 -0
- data/features/support/db/fixtures/robots.rb +1 -1
- data/features/support/db/fixtures/tags.rb +1 -1
- data/features/support/db/migrations/create_alphas.rb +1 -0
- data/features/support/db/migrations/create_genres.rb +3 -0
- data/features/support/db/migrations/create_music.rb +6 -0
- data/features/support/db/migrations/create_robots.rb +1 -2
- data/features/support/env.rb +16 -1
- data/features/support/models/alpha.rb +12 -0
- data/features/support/models/comment.rb +3 -3
- data/features/support/models/fox.rb +5 -0
- data/features/support/models/genre.rb +3 -0
- data/features/support/models/medium.rb +5 -0
- data/features/support/models/music.rb +8 -0
- data/features/support/models/post.rb +2 -1
- data/features/support/models/robot.rb +4 -0
- data/lib/cucumber/thinking_sphinx/external_world.rb +8 -0
- data/lib/cucumber/thinking_sphinx/internal_world.rb +126 -0
- data/lib/cucumber/thinking_sphinx/sql_logger.rb +20 -0
- data/lib/thinking_sphinx.rb +56 -37
- data/lib/thinking_sphinx/active_record.rb +257 -192
- data/lib/thinking_sphinx/active_record/attribute_updates.rb +10 -12
- data/lib/thinking_sphinx/active_record/delta.rb +0 -26
- data/lib/thinking_sphinx/active_record/scopes.rb +37 -1
- data/lib/thinking_sphinx/adapters/mysql_adapter.rb +1 -1
- data/lib/thinking_sphinx/adapters/postgresql_adapter.rb +18 -11
- data/lib/thinking_sphinx/attribute.rb +19 -4
- data/lib/thinking_sphinx/auto_version.rb +22 -0
- data/lib/thinking_sphinx/configuration.rb +57 -59
- data/lib/thinking_sphinx/context.rb +74 -0
- data/lib/thinking_sphinx/deltas.rb +0 -2
- data/lib/thinking_sphinx/deltas/default_delta.rb +14 -20
- data/lib/thinking_sphinx/deploy/capistrano.rb +1 -1
- data/lib/thinking_sphinx/facet_search.rb +3 -1
- data/lib/thinking_sphinx/index.rb +77 -19
- data/lib/thinking_sphinx/index/builder.rb +2 -2
- data/lib/thinking_sphinx/search.rb +47 -9
- data/lib/thinking_sphinx/search_methods.rb +22 -4
- data/lib/thinking_sphinx/source.rb +9 -8
- data/lib/thinking_sphinx/source/sql.rb +5 -3
- data/lib/thinking_sphinx/tasks.rb +13 -57
- data/lib/thinking_sphinx/test.rb +52 -0
- data/rails/init.rb +4 -2
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/delta_spec.rb +4 -6
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/active_record/has_many_association_spec.rb +0 -0
- data/spec/thinking_sphinx/active_record/scopes_spec.rb +177 -0
- data/spec/thinking_sphinx/active_record_spec.rb +622 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/association_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/attribute_spec.rb +39 -0
- data/spec/thinking_sphinx/auto_version_spec.rb +39 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/configuration_spec.rb +27 -61
- data/spec/thinking_sphinx/context_spec.rb +119 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/array_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/core/string_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/excerpter_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_search_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/facet_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/field_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/builder_spec.rb +24 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/index/faux_column_spec.rb +0 -0
- data/spec/thinking_sphinx/index_spec.rb +183 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/rails_additions_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_methods_spec.rb +0 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/search_spec.rb +41 -0
- data/spec/{lib/thinking_sphinx → thinking_sphinx}/source_spec.rb +1 -1
- data/spec/thinking_sphinx_spec.rb +204 -0
- data/tasks/distribution.rb +6 -20
- data/tasks/testing.rb +8 -19
- metadata +117 -142
- data/VERSION.yml +0 -4
- data/features/a.rb +0 -17
- data/features/datetime_deltas.feature +0 -66
- data/features/delayed_delta_indexing.feature +0 -37
- data/features/step_definitions/datetime_delta_steps.rb +0 -15
- data/features/step_definitions/delayed_delta_indexing_steps.rb +0 -7
- data/features/support/db/active_record.rb +0 -40
- data/features/support/db/fixtures/delayed_betas.rb +0 -10
- data/features/support/db/fixtures/thetas.rb +0 -10
- data/features/support/db/migrations/create_delayed_betas.rb +0 -17
- data/features/support/db/migrations/create_thetas.rb +0 -5
- data/features/support/db/mysql.rb +0 -3
- data/features/support/db/postgresql.rb +0 -3
- data/features/support/models/delayed_beta.rb +0 -7
- data/features/support/models/theta.rb +0 -7
- data/features/support/post_database.rb +0 -43
- data/features/support/z.rb +0 -19
- data/lib/thinking_sphinx/deltas/datetime_delta.rb +0 -50
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +0 -30
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +0 -24
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +0 -27
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +0 -26
- data/spec/lib/thinking_sphinx/active_record/scopes_spec.rb +0 -96
- data/spec/lib/thinking_sphinx/active_record_spec.rb +0 -353
- data/spec/lib/thinking_sphinx/deltas/job_spec.rb +0 -32
- data/spec/lib/thinking_sphinx/index_spec.rb +0 -45
- data/spec/lib/thinking_sphinx_spec.rb +0 -162
- data/vendor/after_commit/LICENSE +0 -20
- data/vendor/after_commit/README +0 -16
- data/vendor/after_commit/Rakefile +0 -22
- data/vendor/after_commit/init.rb +0 -8
- data/vendor/after_commit/lib/after_commit.rb +0 -45
- data/vendor/after_commit/lib/after_commit/active_record.rb +0 -114
- data/vendor/after_commit/lib/after_commit/connection_adapters.rb +0 -103
- data/vendor/after_commit/test/after_commit_test.rb +0 -53
- data/vendor/delayed_job/lib/delayed/job.rb +0 -251
- data/vendor/delayed_job/lib/delayed/message_sending.rb +0 -7
- data/vendor/delayed_job/lib/delayed/performable_method.rb +0 -55
- data/vendor/delayed_job/lib/delayed/worker.rb +0 -54
- data/vendor/riddle/lib/riddle.rb +0 -30
- data/vendor/riddle/lib/riddle/client.rb +0 -635
- data/vendor/riddle/lib/riddle/client/filter.rb +0 -53
- data/vendor/riddle/lib/riddle/client/message.rb +0 -66
- data/vendor/riddle/lib/riddle/client/response.rb +0 -84
- data/vendor/riddle/lib/riddle/configuration.rb +0 -33
- data/vendor/riddle/lib/riddle/configuration/distributed_index.rb +0 -48
- data/vendor/riddle/lib/riddle/configuration/index.rb +0 -142
- data/vendor/riddle/lib/riddle/configuration/indexer.rb +0 -19
- data/vendor/riddle/lib/riddle/configuration/remote_index.rb +0 -17
- data/vendor/riddle/lib/riddle/configuration/searchd.rb +0 -25
- data/vendor/riddle/lib/riddle/configuration/section.rb +0 -43
- data/vendor/riddle/lib/riddle/configuration/source.rb +0 -23
- data/vendor/riddle/lib/riddle/configuration/sql_source.rb +0 -34
- data/vendor/riddle/lib/riddle/configuration/xml_source.rb +0 -28
- data/vendor/riddle/lib/riddle/controller.rb +0 -53
@@ -10,22 +10,25 @@ module ThinkingSphinx
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def update_attribute_values
|
13
|
-
return unless ThinkingSphinx.updates_enabled? &&
|
13
|
+
return true unless ThinkingSphinx.updates_enabled? &&
|
14
|
+
ThinkingSphinx.sphinx_running?
|
14
15
|
|
15
16
|
config = ThinkingSphinx::Configuration.instance
|
16
|
-
client =
|
17
|
+
client = config.client
|
17
18
|
|
18
|
-
self.sphinx_indexes.each do |index|
|
19
|
+
self.class.sphinx_indexes.each do |index|
|
19
20
|
attribute_pairs = attribute_values_for_index(index)
|
20
21
|
attribute_names = attribute_pairs.keys
|
21
22
|
attribute_values = attribute_names.collect { |key|
|
22
23
|
attribute_pairs[key]
|
23
24
|
}
|
24
25
|
|
25
|
-
client.update "#{index.
|
26
|
+
client.update "#{index.core_name}", attribute_names, {
|
26
27
|
sphinx_document_id => attribute_values
|
27
|
-
} if
|
28
|
+
} if self.class.search_for_id(sphinx_document_id, index.core_name)
|
28
29
|
end
|
30
|
+
|
31
|
+
true
|
29
32
|
end
|
30
33
|
|
31
34
|
def updatable_attributes(index)
|
@@ -34,15 +37,10 @@ module ThinkingSphinx
|
|
34
37
|
|
35
38
|
def attribute_values_for_index(index)
|
36
39
|
updatable_attributes(index).inject({}) { |hash, attrib|
|
37
|
-
|
38
|
-
hash[attrib.unique_name.to_s] = attrib.live_value(self).to_time.to_i
|
39
|
-
else
|
40
|
-
hash[attrib.unique_name.to_s] = attrib.live_value self
|
41
|
-
end
|
42
|
-
|
40
|
+
hash[attrib.unique_name.to_s] = attrib.live_value self
|
43
41
|
hash
|
44
42
|
}
|
45
43
|
end
|
46
44
|
end
|
47
45
|
end
|
48
|
-
end
|
46
|
+
end
|
@@ -12,32 +12,6 @@ module ThinkingSphinx
|
|
12
12
|
def self.included(base)
|
13
13
|
base.class_eval do
|
14
14
|
class << self
|
15
|
-
# Temporarily disable delta indexing inside a block, then perform a single
|
16
|
-
# rebuild of index at the end.
|
17
|
-
#
|
18
|
-
# Useful when performing updates to batches of models to prevent
|
19
|
-
# the delta index being rebuilt after each individual update.
|
20
|
-
#
|
21
|
-
# In the following example, the delta index will only be rebuilt once,
|
22
|
-
# not 10 times.
|
23
|
-
#
|
24
|
-
# SomeModel.suspended_delta do
|
25
|
-
# 10.times do
|
26
|
-
# SomeModel.create( ... )
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
#
|
30
|
-
def suspended_delta(reindex_after = true, &block)
|
31
|
-
original_setting = ThinkingSphinx.deltas_enabled?
|
32
|
-
ThinkingSphinx.deltas_enabled = false
|
33
|
-
begin
|
34
|
-
yield
|
35
|
-
ensure
|
36
|
-
ThinkingSphinx.deltas_enabled = original_setting
|
37
|
-
self.index_delta if reindex_after
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
15
|
# Build the delta index for the related model. This won't be called
|
42
16
|
# if running in the test environment.
|
43
17
|
#
|
@@ -8,6 +8,40 @@ module ThinkingSphinx
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
+
|
12
|
+
# Similar to ActiveRecord's default_scope method Thinking Sphinx supports
|
13
|
+
# a default_sphinx_scope. For example:
|
14
|
+
#
|
15
|
+
# default_sphinx_scope :some_sphinx_named_scope
|
16
|
+
#
|
17
|
+
# The scope is automatically applied when the search method is called. It
|
18
|
+
# will only be applied if it is an existing sphinx_scope.
|
19
|
+
def default_sphinx_scope(sphinx_scope_name)
|
20
|
+
@default_sphinx_scope = sphinx_scope_name
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the default_sphinx_scope or nil if none is set.
|
24
|
+
def get_default_sphinx_scope
|
25
|
+
@default_sphinx_scope
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns true if the current Model has a default_sphinx_scope. Also checks if
|
29
|
+
# the default_sphinx_scope actually is a scope.
|
30
|
+
def has_default_sphinx_scope?
|
31
|
+
!@default_sphinx_scope.nil? && sphinx_scopes.include?(@default_sphinx_scope)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Similar to ActiveRecord's named_scope method Thinking Sphinx supports
|
35
|
+
# scopes. For example:
|
36
|
+
#
|
37
|
+
# sphinx_scope(:latest_first) {
|
38
|
+
# {:order => 'created_at DESC, @relevance DESC'}
|
39
|
+
# }
|
40
|
+
#
|
41
|
+
# Usage:
|
42
|
+
#
|
43
|
+
# @articles = Article.latest_first.search 'pancakes'
|
44
|
+
#
|
11
45
|
def sphinx_scope(method, &block)
|
12
46
|
@sphinx_scopes ||= []
|
13
47
|
@sphinx_scopes << method
|
@@ -21,7 +55,9 @@ module ThinkingSphinx
|
|
21
55
|
end
|
22
56
|
end
|
23
57
|
end
|
24
|
-
|
58
|
+
|
59
|
+
# This returns an Array of all defined scopes. The default
|
60
|
+
# scope shows as :default.
|
25
61
|
def sphinx_scopes
|
26
62
|
@sphinx_scopes || []
|
27
63
|
end
|
@@ -13,7 +13,7 @@ module ThinkingSphinx
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def group_concatenate(clause, separator = ' ')
|
16
|
-
"GROUP_CONCAT(DISTINCT #{clause} SEPARATOR '#{separator}')"
|
16
|
+
"GROUP_CONCAT(DISTINCT IFNULL(#{clause}, '0') SEPARATOR '#{separator}')"
|
17
17
|
end
|
18
18
|
|
19
19
|
def cast_to_string(clause)
|
@@ -10,18 +10,17 @@ module ThinkingSphinx
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def concatenate(clause, separator = ' ')
|
13
|
-
clause
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}.join(" || '#{separator}' || ")
|
13
|
+
if clause[/^COALESCE/]
|
14
|
+
clause.split('), ').join(") || '#{separator}' || ")
|
15
|
+
else
|
16
|
+
clause.split(', ').collect { |field|
|
17
|
+
"CAST(COALESCE(#{field}, '') as varchar)"
|
18
|
+
}.join(" || '#{separator}' || ")
|
19
|
+
end
|
21
20
|
end
|
22
21
|
|
23
22
|
def group_concatenate(clause, separator = ' ')
|
24
|
-
"array_to_string(array_accum(#{clause}), '#{separator}')"
|
23
|
+
"array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
|
25
24
|
end
|
26
25
|
|
27
26
|
def cast_to_string(clause)
|
@@ -37,8 +36,16 @@ module ThinkingSphinx
|
|
37
36
|
end
|
38
37
|
|
39
38
|
def convert_nulls(clause, default = '')
|
40
|
-
default =
|
41
|
-
|
39
|
+
default = case default
|
40
|
+
when String
|
41
|
+
"'#{default}'"
|
42
|
+
when NilClass
|
43
|
+
'NULL'
|
44
|
+
when Fixnum
|
45
|
+
"#{default}::bigint"
|
46
|
+
else
|
47
|
+
default
|
48
|
+
end
|
42
49
|
|
43
50
|
"COALESCE(#{clause}, #{default})"
|
44
51
|
end
|
@@ -101,14 +101,14 @@ module ThinkingSphinx
|
|
101
101
|
when :datetime
|
102
102
|
adapter.cast_to_datetime(part)
|
103
103
|
when :multi
|
104
|
-
part = adapter.cast_to_datetime(part)
|
105
|
-
adapter.convert_nulls(part, 0)
|
104
|
+
part = adapter.cast_to_datetime(part) if is_many_datetimes?
|
105
|
+
part = adapter.convert_nulls(part, '0') if is_many_ints?
|
106
|
+
part
|
106
107
|
else
|
107
108
|
part
|
108
109
|
end
|
109
110
|
}.join(', ')
|
110
111
|
|
111
|
-
# clause = adapter.cast_to_datetime(clause) if type == :datetime
|
112
112
|
clause = adapter.crc(clause) if @crc
|
113
113
|
clause = adapter.concatenate(clause, separator) if concat_ws?
|
114
114
|
|
@@ -179,7 +179,7 @@ module ThinkingSphinx
|
|
179
179
|
object = instance
|
180
180
|
column = @columns.first
|
181
181
|
column.__stack.each { |method| object = object.send(method) }
|
182
|
-
object.send(column.__name)
|
182
|
+
sphinx_value object.send(column.__name)
|
183
183
|
end
|
184
184
|
|
185
185
|
def all_ints?
|
@@ -336,5 +336,20 @@ block:
|
|
336
336
|
}
|
337
337
|
}
|
338
338
|
end
|
339
|
+
|
340
|
+
def sphinx_value(value)
|
341
|
+
case value
|
342
|
+
when TrueClass
|
343
|
+
1
|
344
|
+
when FalseClass, NilClass
|
345
|
+
0
|
346
|
+
when Time
|
347
|
+
value.to_i
|
348
|
+
when Date
|
349
|
+
value.to_time.to_i
|
350
|
+
else
|
351
|
+
value
|
352
|
+
end
|
353
|
+
end
|
339
354
|
end
|
340
355
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ThinkingSphinx
|
2
|
+
class AutoVersion
|
3
|
+
def self.detect
|
4
|
+
version = ThinkingSphinx::Configuration.instance.controller.sphinx_version
|
5
|
+
case version
|
6
|
+
when '0.9.8', '0.9.9'
|
7
|
+
require "riddle/#{version}"
|
8
|
+
else
|
9
|
+
STDERR.puts %Q{
|
10
|
+
Sphinx cannot be found on your system. You may need to configure the following
|
11
|
+
settings in your config/sphinx.yml file:
|
12
|
+
* bin_path
|
13
|
+
* searchd_binary_name
|
14
|
+
* indexer_binary_name
|
15
|
+
|
16
|
+
For more information, read the documentation:
|
17
|
+
http://freelancing-god.github.com/ts/en/advanced_config.html
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -13,7 +13,7 @@ module ThinkingSphinx
|
|
13
13
|
# pid file:: log/searchd.#{environment}.pid
|
14
14
|
# searchd files:: db/sphinx/#{environment}/
|
15
15
|
# address:: 127.0.0.1
|
16
|
-
# port::
|
16
|
+
# port:: 9312
|
17
17
|
# allow star:: false
|
18
18
|
# min prefix length:: 1
|
19
19
|
# min infix length:: 1
|
@@ -49,25 +49,27 @@ module ThinkingSphinx
|
|
49
49
|
class Configuration
|
50
50
|
include Singleton
|
51
51
|
|
52
|
-
SourceOptions = %w( mysql_connect_flags
|
53
|
-
|
52
|
+
SourceOptions = %w( mysql_connect_flags mysql_ssl_cert mysql_ssl_key
|
53
|
+
mysql_ssl_ca sql_range_step sql_query_pre sql_query_post
|
54
|
+
sql_query_killlist sql_ranged_throttle sql_query_post_index unpack_zlib
|
55
|
+
unpack_mysqlcompress unpack_mysqlcompress_maxsize )
|
54
56
|
|
55
|
-
IndexOptions = %w( charset_table charset_type docinfo
|
56
|
-
exceptions html_index_attrs html_remove_elements html_strip
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
IndexOptions = %w( charset_table charset_type charset_dictpath docinfo
|
58
|
+
enable_star exceptions html_index_attrs html_remove_elements html_strip
|
59
|
+
index_exact_words ignore_chars inplace_docinfo_gap inplace_enable
|
60
|
+
inplace_hit_gap inplace_reloc_factor inplace_write_factor min_infix_len
|
61
|
+
min_prefix_len min_stemming_len min_word_len mlock morphology ngram_chars
|
62
|
+
ngram_len ondisk_dict overshort_step phrase_boundary phrase_boundary_step
|
63
|
+
preopen stopwords stopwords_step wordforms )
|
60
64
|
|
61
65
|
CustomOptions = %w( disable_range )
|
62
66
|
|
63
|
-
attr_accessor :
|
64
|
-
:
|
65
|
-
:database_yml_file, :app_root, :bin_path, :model_directories,
|
66
|
-
:delayed_job_priority, :searchd_binary_name, :indexer_binary_name
|
67
|
+
attr_accessor :searchd_file_path, :allow_star, :database_yml_file,
|
68
|
+
:app_root, :model_directories, :delayed_job_priority
|
67
69
|
|
68
70
|
attr_accessor :source_options, :index_options
|
69
71
|
|
70
|
-
attr_reader :environment, :configuration
|
72
|
+
attr_reader :environment, :configuration, :controller
|
71
73
|
|
72
74
|
# Load in the configuration settings - this will look for config/sphinx.yml
|
73
75
|
# and parse it according to the current environment.
|
@@ -92,16 +94,17 @@ module ThinkingSphinx
|
|
92
94
|
|
93
95
|
@configuration = Riddle::Configuration.new
|
94
96
|
@configuration.searchd.address = "127.0.0.1"
|
95
|
-
@configuration.searchd.port =
|
97
|
+
@configuration.searchd.port = 9312
|
96
98
|
@configuration.searchd.pid_file = "#{self.app_root}/log/searchd.#{environment}.pid"
|
97
99
|
@configuration.searchd.log = "#{self.app_root}/log/searchd.log"
|
98
100
|
@configuration.searchd.query_log = "#{self.app_root}/log/searchd.query.log"
|
99
101
|
|
102
|
+
@controller = Riddle::Controller.new @configuration,
|
103
|
+
"#{self.app_root}/config/#{environment}.sphinx.conf"
|
104
|
+
|
100
105
|
self.database_yml_file = "#{self.app_root}/config/database.yml"
|
101
|
-
self.config_file = "#{self.app_root}/config/#{environment}.sphinx.conf"
|
102
106
|
self.searchd_file_path = "#{self.app_root}/db/sphinx/#{environment}"
|
103
107
|
self.allow_star = false
|
104
|
-
self.bin_path = ""
|
105
108
|
self.model_directories = ["#{app_root}/app/models/"] +
|
106
109
|
Dir.glob("#{app_root}/vendor/plugins/*/app/models/")
|
107
110
|
self.delayed_job_priority = 0
|
@@ -111,16 +114,13 @@ module ThinkingSphinx
|
|
111
114
|
:charset_type => "utf-8"
|
112
115
|
}
|
113
116
|
|
114
|
-
self.searchd_binary_name = "searchd"
|
115
|
-
self.indexer_binary_name = "indexer"
|
116
|
-
|
117
117
|
parse_config
|
118
118
|
|
119
119
|
self
|
120
120
|
end
|
121
121
|
|
122
122
|
def self.environment
|
123
|
-
|
123
|
+
Thread.current[:thinking_sphinx_environment] ||= (
|
124
124
|
defined?(Merb) ? Merb.environment : ENV['RAILS_ENV']
|
125
125
|
) || "development"
|
126
126
|
end
|
@@ -129,22 +129,19 @@ module ThinkingSphinx
|
|
129
129
|
self.class.environment
|
130
130
|
end
|
131
131
|
|
132
|
-
def controller
|
133
|
-
@controller ||= Riddle::Controller.new(@configuration, self.config_file)
|
134
|
-
end
|
135
|
-
|
136
132
|
# Generate the config file for Sphinx by using all the settings defined and
|
137
133
|
# looping through all the models with indexes to build the relevant
|
138
134
|
# indexer and searchd configuration, and sources and indexes details.
|
139
135
|
#
|
140
136
|
def build(file_path=nil)
|
141
|
-
load_models
|
142
137
|
file_path ||= "#{self.config_file}"
|
143
138
|
|
144
139
|
@configuration.indexes.clear
|
145
140
|
|
146
|
-
ThinkingSphinx.indexed_models.
|
147
|
-
|
141
|
+
ThinkingSphinx.context.indexed_models.each do |model|
|
142
|
+
model = model.constantize
|
143
|
+
model.define_indexes
|
144
|
+
@configuration.indexes.concat model.to_riddle
|
148
145
|
end
|
149
146
|
|
150
147
|
open(file_path, "w") do |file|
|
@@ -152,37 +149,6 @@ module ThinkingSphinx
|
|
152
149
|
end
|
153
150
|
end
|
154
151
|
|
155
|
-
# Make sure all models are loaded - without reloading any that
|
156
|
-
# ActiveRecord::Base is already aware of (otherwise we start to hit some
|
157
|
-
# messy dependencies issues).
|
158
|
-
#
|
159
|
-
def load_models
|
160
|
-
return if defined?(Rails) &&
|
161
|
-
Rails::VERSION::STRING.to_f > 2.1 &&
|
162
|
-
Rails.configuration.cache_classes
|
163
|
-
|
164
|
-
self.model_directories.each do |base|
|
165
|
-
Dir["#{base}**/*.rb"].each do |file|
|
166
|
-
model_name = file.gsub(/^#{base}([\w_\/\\]+)\.rb/, '\1')
|
167
|
-
|
168
|
-
next if model_name.nil?
|
169
|
-
next if ::ActiveRecord::Base.send(:subclasses).detect { |model|
|
170
|
-
model.name == model_name
|
171
|
-
}
|
172
|
-
|
173
|
-
begin
|
174
|
-
model_name.camelize.constantize
|
175
|
-
rescue LoadError
|
176
|
-
model_name.gsub!(/.*[\/\\]/, '').nil? ? next : retry
|
177
|
-
rescue NameError
|
178
|
-
next
|
179
|
-
rescue StandardError
|
180
|
-
puts "Warning: Error loading #{file}"
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
|
186
152
|
def address
|
187
153
|
@configuration.searchd.address
|
188
154
|
end
|
@@ -223,6 +189,38 @@ module ThinkingSphinx
|
|
223
189
|
@configuration.searchd.query_log = file
|
224
190
|
end
|
225
191
|
|
192
|
+
def config_file
|
193
|
+
@controller.path
|
194
|
+
end
|
195
|
+
|
196
|
+
def config_file=(file)
|
197
|
+
@controller.path = file
|
198
|
+
end
|
199
|
+
|
200
|
+
def bin_path
|
201
|
+
@controller.bin_path
|
202
|
+
end
|
203
|
+
|
204
|
+
def bin_path=(path)
|
205
|
+
@controller.bin_path = path
|
206
|
+
end
|
207
|
+
|
208
|
+
def searchd_binary_name
|
209
|
+
@controller.searchd_binary_name
|
210
|
+
end
|
211
|
+
|
212
|
+
def searchd_binary_name=(name)
|
213
|
+
@controller.searchd_binary_name = name
|
214
|
+
end
|
215
|
+
|
216
|
+
def indexer_binary_name
|
217
|
+
@controller.indexer_binary_name
|
218
|
+
end
|
219
|
+
|
220
|
+
def indexer_binary_name=(name)
|
221
|
+
@controller.indexer_binary_name = name
|
222
|
+
end
|
223
|
+
|
226
224
|
def client
|
227
225
|
client = Riddle::Client.new address, port
|
228
226
|
client.max_matches = configuration.searchd.max_matches || 1000
|
@@ -231,7 +229,7 @@ module ThinkingSphinx
|
|
231
229
|
|
232
230
|
def models_by_crc
|
233
231
|
@models_by_crc ||= begin
|
234
|
-
ThinkingSphinx.indexed_models.inject({}) do |hash, model|
|
232
|
+
ThinkingSphinx.context.indexed_models.inject({}) do |hash, model|
|
235
233
|
hash[model.constantize.to_crc32] = model
|
236
234
|
Object.subclasses_of(model.constantize).each { |subclass|
|
237
235
|
hash[subclass.to_crc32] = subclass.name
|