0
@@ -41,21 +41,33 @@ module Ultrasphinx
0
say "rebuilding configurations for #{RAILS_ENV} environment"
0
say "available models are #{MODEL_CONFIGURATION.keys.to_sentence}"
0
- File.open(CONF_PATH, "w") do |conf|
0
+ File.open(CONF_PATH, "w") do |conf|
0
conf.puts global_header
0
- cached_groups = Fields.instance.groups.join("\n")
0
- MODEL_CONFIGURATION.each_with_index do |model_options, class_id|
0
- model, options = model_options
0
- klass, source = model.constantize, model.tableize.gsub('/', '__')
0
- conf.puts build_source(Fields.instance, model, options, class_id, klass, source, cached_groups)
0
+ INDEXES.each do |index|
0
+ cached_groups = Fields.instance.groups.join("\n")
0
+ MODEL_CONFIGURATION.each_with_index do |model_and_options, class_id|
0
+ # This relies on hash sort order being deterministic per-machine
0
+ model, options = model_and_options
0
+ klass = model.constantize
0
+ source = "#{model.tableize.gsub('/', '__')}_#{index}"
0
+ if index != DELTA_INDEX or options['delta']
0
+ # If we are building the delta, we only want to include the models that requested it
0
+ conf.puts build_source(index, Fields.instance, model, options, class_id, klass, source, cached_groups)
0
+ # Don't generate a delta index if there are no delta tables
0
+ conf.puts build_index(index, sources)
0
- conf.puts build_index(sources)
0
@@ -68,7 +80,8 @@ module Ultrasphinx
0
["\n# Auto-generated at #{Time.now}.",
0
"# Hand modifications will be overwritten.",
0
- INDEXER_SETTINGS._to_conf_string('indexer'),
0
+ INDEXER_SETTINGS.except('delta')._to_conf_string('indexer'),
0
DAEMON_SETTINGS._to_conf_string("searchd")]
0
@@ -86,9 +99,31 @@ module Ultrasphinx
0
+ def build_delta_condition(index, klass, options)
0
+ if index == DELTA_INDEX and options['delta']
0
+ # Add delta condition if necessary
0
+ table, field = klass.table_name, options['delta']['field']
0
+ source_string = "#{table}.#{field}"
0
+ delta_column = klass.columns_hash[field]
0
+ raise ConfigurationError, "#{source_string} is not a :datetime" unless delta_column.type == :datetime
0
+ if (options['fields'] + options['concatenate'] + options['include']).detect { |entry| entry['sortable'] }
0
+ # Warning about the sortable problem
0
+ # XXX Kind of in an odd place, but I want to happen at index time
0
+ Ultrasphinx.say "warning; text sortable columns on #{klass.name} will return wrong results with partial delta indexing"
0
+ string = "#{source_string} > #{SQL_FUNCTIONS[ADAPTER]['delta']._interpolate(INDEXER_SETTINGS['delta'])}";
0
+ Ultrasphinx.say "warning; #{klass.name} will reindex the entire table during delta indexing"
0
- def setup_source_arrays(
klass, fields, class_id, conditions)
0
+ def setup_source_arrays(
index, klass, fields, class_id, conditions)
0
condition_strings = Array(conditions).map do |condition|
0
@@ -101,12 +136,13 @@ module Ultrasphinx
0
- def range_select_string(klass
)
0
+ def range_select_string(klass
, delta_condition)
0
["sql_query_range = SELECT",
0
SQL_FUNCTIONS[ADAPTER]['range_cast']._interpolate("MIN(#{klass.primary_key})"),
0
SQL_FUNCTIONS[ADAPTER]['range_cast']._interpolate("MAX(#{klass.primary_key})"),
0
- "FROM #{klass.table_name}"
0
+ "FROM #{klass.table_name}",
0
+ ("WHERE #{delta_condition}" if delta_condition),
0
@@ -116,11 +152,16 @@ module Ultrasphinx
0
- def build_source(
fields, model, options, class_id, klass, source, groups)
0
+ def build_source(
index, fields, model, options, class_id, klass, source, groups)
0
column_strings, join_strings, condition_strings, group_bys, use_distinct, remaining_columns =
0
- klass, fields, class_id, options['conditions'])
0
+ index, klass, fields, class_id, options['conditions'])
0
+ build_delta_condition(
0
+ index, klass, options)
0
+ condition_strings << delta_condition if delta_condition
0
column_strings, join_strings, group_bys, remaining_columns =
0
@@ -140,7 +181,7 @@ module Ultrasphinx
0
SOURCE_SETTINGS._to_conf_string,
0
setup_source_database(klass),
0
- range_select_string(klass
),
0
+ range_select_string(klass
, delta_condition),
0
build_query(klass, column_strings, join_strings, condition_strings, use_distinct, group_bys),
0
query_info_string(klass, class_id),
0
@@ -271,13 +312,13 @@ module Ultrasphinx
0
- def build_index(
sources)
0
+ def build_index(
index, sources)
0
["\n# Index configuration\n\n",
0
- "index #{
UNIFIED_INDEX_NAME}\n{",
0
sources.sort.map do |source|
0
- INDEX_SETTINGS.merge('path' => INDEX_SETTINGS['path'] + "/sphinx_index_#{
UNIFIED_INDEX_NAME}")._to_conf_string,
0
+ INDEX_SETTINGS.merge('path' => INDEX_SETTINGS['path'] + "/sphinx_index_#{
index}")._to_conf_string,