<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -37,7 +37,7 @@ module ThinkingSphinx
   module Version #:nodoc:
     Major = 1
     Minor = 1
-    Tiny  = 22
+    Tiny  = 23
     
     String = [Major, Minor, Tiny].join('.')
   end</diff>
      <filename>lib/thinking_sphinx.rb</filename>
    </modified>
    <modified>
      <diff>@@ -124,10 +124,10 @@ module ThinkingSphinx
     # Special case is the multi-valued attribute that needs some
     # extra configuration. 
     # 
-    def config_value(offset = nil)
+    def config_value(offset = nil, delta = false)
       if type == :multi
         multi_config = include_as_association? ? &quot;field&quot; :
-          source_value(offset).gsub(/\s+/m, &quot; &quot;).strip
+          source_value(offset, delta).gsub(/\s+/m, &quot; &quot;).strip
         &quot;uint #{unique_name} from #{multi_config}&quot;
       else
         unique_name
@@ -183,13 +183,20 @@ module ThinkingSphinx
     
     private
     
-    def source_value(offset)
+    def source_value(offset, delta)
       if is_string?
-        &quot;#{query_source.to_s.dasherize}; #{columns.first.__name}&quot;
-      elsif query_source == :ranged_query
-        &quot;ranged-query; #{query offset} #{query_clause}; #{range_query}&quot;
+        return &quot;#{query_source.to_s.dasherize}; #{columns.first.__name}&quot;
+      end
+      
+      query = query(offset)
+
+      if query_source == :ranged_query
+        query += query_clause
+        query += &quot; AND #{query_delta.strip}&quot; if delta
+        &quot;ranged-query; #{query}; #{range_query}&quot;
       else
-        &quot;query; #{query offset}&quot;
+        query += &quot;WHERE #{query_delta.strip}&quot; if delta
+        &quot;query; #{query}&quot;
       end
     end
     
@@ -211,6 +218,15 @@ FROM #{quote_table_name base_assoc.table} #{association_joins}
       &quot;WHERE #{foreign_key} &gt;= $start AND #{foreign_key} &lt;= $end&quot;
     end
     
+    def query_delta
+      foreign_key = foreign_key_for_mva base_association_for_mva
+      &lt;&lt;-SQL
+#{foreign_key} IN (SELECT #{quote_column model.primary_key}
+FROM #{model.quoted_table_name}
+WHERE #{@source.index.delta_object.clause(model, true)})
+      SQL
+    end
+    
     def range_query
       assoc       = base_association_for_mva
       foreign_key = foreign_key_for_mva assoc</diff>
      <filename>lib/thinking_sphinx/attribute.rb</filename>
    </modified>
    <modified>
      <diff>@@ -8,7 +8,7 @@ module ThinkingSphinx
     
     attr_accessor :model, :fields, :attributes, :conditions, :groupings,
       :options
-    attr_reader :base
+    attr_reader :base, :index
     
     def initialize(index, options = {})
       @index        = index
@@ -56,7 +56,7 @@ module ThinkingSphinx
       source.parent = &quot;#{name}_core_#{index}&quot;
       
       set_source_database_settings  source
-      set_source_attributes         source, offset
+      set_source_attributes         source, offset, true
       set_source_sql                source, offset, true
       
       source
@@ -89,9 +89,9 @@ module ThinkingSphinx
       source.sql_sock = config[:socket]
     end
     
-    def set_source_attributes(source, offset)
+    def set_source_attributes(source, offset, delta = false)
       attributes.each do |attrib|
-        source.send(attrib.type_to_config) &lt;&lt; attrib.config_value(offset)
+        source.send(attrib.type_to_config) &lt;&lt; attrib.config_value(offset, delta)
       end
     end
     </diff>
      <filename>lib/thinking_sphinx/source.rb</filename>
    </modified>
    <modified>
      <diff>@@ -4,6 +4,8 @@ describe ThinkingSphinx::Attribute do
   before :each do
     @index  = ThinkingSphinx::Index.new(Person)
     @source = ThinkingSphinx::Source.new(@index)
+    
+    @index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
   end
   
   describe '#initialize' do
@@ -232,6 +234,23 @@ describe ThinkingSphinx::Attribute do
     end
   end
   
+  describe &quot;MVA with source query for a delta source&quot; do
+    before :each do
+      @attribute = ThinkingSphinx::Attribute.new(@source,
+        [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
+        :as =&gt; :tag_ids, :source =&gt; :query
+      )
+    end
+    
+    it &quot;should use a query&quot; do
+      @attribute.type_to_config.should == :sql_attr_multi
+      
+      declaration, query = @attribute.config_value(nil, true).split('; ')
+      declaration.should == &quot;uint tag_ids from query&quot;
+      query.should       == &quot;SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)&quot;
+    end
+  end
+  
   describe &quot;MVA via a HABTM association with a source query&quot; do
     before :each do
       @attribute = ThinkingSphinx::Attribute.new(@source,
@@ -267,6 +286,24 @@ describe ThinkingSphinx::Attribute do
     end
   end
   
+  describe &quot;MVA with ranged source query for a delta source&quot; do
+    before :each do
+      @attribute = ThinkingSphinx::Attribute.new(@source,
+        [ThinkingSphinx::Index::FauxColumn.new(:tags, :id)],
+        :as =&gt; :tag_ids, :source =&gt; :ranged_query
+      )
+    end
+    
+    it &quot;should use a ranged query&quot; do
+      @attribute.type_to_config.should == :sql_attr_multi
+      
+      declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
+      declaration.should == &quot;uint tag_ids from ranged-query&quot;
+      query.should       == &quot;SELECT `tags`.`person_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `tags`.`id` AS `tag_ids` FROM `tags` WHERE `tags`.`person_id` &gt;= $start AND `tags`.`person_id` &lt;= $end AND `tags`.`person_id` IN (SELECT `id` FROM `people` WHERE `people`.`delta` = 1)&quot;
+      range_query.should == &quot;SELECT MIN(`tags`.`person_id`), MAX(`tags`.`person_id`) FROM `tags`&quot;
+    end
+  end
+  
   describe &quot;MVA via a has-many :through with a ranged source query&quot; do
     before :each do
       @attribute = ThinkingSphinx::Attribute.new(@source,
@@ -341,6 +378,28 @@ describe ThinkingSphinx::Attribute do
     end
   end
   
+  describe &quot;MVA via two has-many associations with a ranged source query for a delta source&quot; do
+    before :each do
+      @index  = ThinkingSphinx::Index.new(Alpha)
+      @source = ThinkingSphinx::Source.new(@index)
+      @attribute = ThinkingSphinx::Attribute.new(@source,
+        [ThinkingSphinx::Index::FauxColumn.new(:betas, :gammas, :value)],
+        :as =&gt; :gamma_values, :source =&gt; :ranged_query
+      )
+      
+      @index.delta_object = ThinkingSphinx::Deltas::DefaultDelta.new @index, @index.local_options
+    end
+    
+    it &quot;should use a ranged query&quot; do
+      @attribute.type_to_config.should == :sql_attr_multi
+      
+      declaration, query, range_query = @attribute.config_value(nil, true).split('; ')
+      declaration.should == &quot;uint gamma_values from ranged-query&quot;
+      query.should       == &quot;SELECT `betas`.`alpha_id` #{ThinkingSphinx.unique_id_expression} AS `id`, `gammas`.`value` AS `gamma_values` FROM `betas` LEFT OUTER JOIN `gammas` ON gammas.beta_id = betas.id WHERE `betas`.`alpha_id` &gt;= $start AND `betas`.`alpha_id` &lt;= $end AND `betas`.`alpha_id` IN (SELECT `id` FROM `alphas` WHERE `alphas`.`delta` = 1)&quot;
+      range_query.should == &quot;SELECT MIN(`betas`.`alpha_id`), MAX(`betas`.`alpha_id`) FROM `betas`&quot;
+    end
+  end
+  
   describe &quot;with custom queries&quot; do
     before :each do
       index = CricketTeam.sphinx_indexes.first</diff>
      <filename>spec/unit/thinking_sphinx/attribute_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,11 +2,11 @@
 
 Gem::Specification.new do |s|
   s.name = %q{thinking-sphinx}
-  s.version = &quot;1.1.22&quot;
+  s.version = &quot;1.1.23&quot;
 
   s.required_rubygems_version = Gem::Requirement.new(&quot;&gt;= 0&quot;) if s.respond_to? :required_rubygems_version=
   s.authors = [&quot;Pat Allan&quot;]
-  s.date = %q{2009-06-22}
+  s.date = %q{2009-06-28}
   s.description = %q{A concise and easy-to-use Ruby library that connects ActiveRecord to the Sphinx search daemon, managing configuration, indexing and searching.}
   s.email = %q{pat@freelancing-gods.com}
   s.files = [&quot;rails/init.rb&quot;, &quot;lib/thinking_sphinx/active_record/attribute_updates.rb&quot;, &quot;lib/thinking_sphinx/active_record/delta.rb&quot;, &quot;lib/thinking_sphinx/active_record/has_many_association.rb&quot;, &quot;lib/thinking_sphinx/active_record/search.rb&quot;, &quot;lib/thinking_sphinx/active_record.rb&quot;, &quot;lib/thinking_sphinx/adapters/abstract_adapter.rb&quot;, &quot;lib/thinking_sphinx/adapters/mysql_adapter.rb&quot;, &quot;lib/thinking_sphinx/adapters/postgresql_adapter.rb&quot;, &quot;lib/thinking_sphinx/association.rb&quot;, &quot;lib/thinking_sphinx/attribute.rb&quot;, &quot;lib/thinking_sphinx/class_facet.rb&quot;, &quot;lib/thinking_sphinx/collection.rb&quot;, &quot;lib/thinking_sphinx/configuration.rb&quot;, &quot;lib/thinking_sphinx/core/string.rb&quot;, &quot;lib/thinking_sphinx/deltas/datetime_delta.rb&quot;, &quot;lib/thinking_sphinx/deltas/default_delta.rb&quot;, &quot;lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb&quot;, &quot;lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb&quot;, &quot;lib/thinking_sphinx/deltas/delayed_delta/job.rb&quot;, &quot;lib/thinking_sphinx/deltas/delayed_delta.rb&quot;, &quot;lib/thinking_sphinx/deltas.rb&quot;, &quot;lib/thinking_sphinx/deploy/capistrano.rb&quot;, &quot;lib/thinking_sphinx/facet.rb&quot;, &quot;lib/thinking_sphinx/facet_collection.rb&quot;, &quot;lib/thinking_sphinx/field.rb&quot;, &quot;lib/thinking_sphinx/index/builder.rb&quot;, &quot;lib/thinking_sphinx/index/faux_column.rb&quot;, &quot;lib/thinking_sphinx/index.rb&quot;, &quot;lib/thinking_sphinx/property.rb&quot;, &quot;lib/thinking_sphinx/rails_additions.rb&quot;, &quot;lib/thinking_sphinx/search/facets.rb&quot;, &quot;lib/thinking_sphinx/search.rb&quot;, &quot;lib/thinking_sphinx/source/internal_properties.rb&quot;, &quot;lib/thinking_sphinx/source/sql.rb&quot;, &quot;lib/thinking_sphinx/source.rb&quot;, &quot;lib/thinking_sphinx/tasks.rb&quot;, &quot;lib/thinking_sphinx.rb&quot;, &quot;LICENCE&quot;, &quot;README.textile&quot;, &quot;tasks/distribution.rb&quot;, &quot;tasks/testing.rb&quot;, &quot;tasks/rails.rake&quot;, &quot;vendor/after_commit&quot;, &quot;vendor/after_commit/init.rb&quot;, &quot;vendor/after_commit/lib&quot;, &quot;vendor/after_commit/lib/after_commit&quot;, &quot;vendor/after_commit/lib/after_commit/active_record.rb&quot;, &quot;vendor/after_commit/lib/after_commit/connection_adapters.rb&quot;, &quot;vendor/after_commit/lib/after_commit.rb&quot;, &quot;vendor/after_commit/LICENSE&quot;, &quot;vendor/after_commit/Rakefile&quot;, &quot;vendor/after_commit/README&quot;, &quot;vendor/after_commit/test&quot;, &quot;vendor/after_commit/test/after_commit_test.rb&quot;, &quot;vendor/delayed_job&quot;, &quot;vendor/delayed_job/lib&quot;, &quot;vendor/delayed_job/lib/delayed&quot;, &quot;vendor/delayed_job/lib/delayed/job.rb&quot;, &quot;vendor/delayed_job/lib/delayed/message_sending.rb&quot;, &quot;vendor/delayed_job/lib/delayed/performable_method.rb&quot;, &quot;vendor/delayed_job/lib/delayed/worker.rb&quot;, &quot;vendor/riddle&quot;, &quot;vendor/riddle/lib&quot;, &quot;vendor/riddle/lib/riddle&quot;, &quot;vendor/riddle/lib/riddle/client&quot;, &quot;vendor/riddle/lib/riddle/client/filter.rb&quot;, &quot;vendor/riddle/lib/riddle/client/message.rb&quot;, &quot;vendor/riddle/lib/riddle/client/response.rb&quot;, &quot;vendor/riddle/lib/riddle/client.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration&quot;, &quot;vendor/riddle/lib/riddle/configuration/distributed_index.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/index.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/indexer.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/remote_index.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/searchd.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/section.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/source.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/sql_source.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration/xml_source.rb&quot;, &quot;vendor/riddle/lib/riddle/configuration.rb&quot;, &quot;vendor/riddle/lib/riddle/controller.rb&quot;, &quot;vendor/riddle/lib/riddle.rb&quot;, &quot;spec/unit/thinking_sphinx/active_record/delta_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/active_record/has_many_association_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/active_record/search_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/active_record_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/association_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/attribute_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/collection_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/configuration_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/core/string_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/facet_collection_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/facet_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/field_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/index/builder_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/index/faux_column_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/index_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/rails_additions_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/search_spec.rb&quot;, &quot;spec/unit/thinking_sphinx/source_spec.rb&quot;, &quot;spec/unit/thinking_sphinx_spec.rb&quot;]</diff>
      <filename>thinking-sphinx.gemspec</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cb770957280c312b7a92e3cb23194bbc35cba31c</id>
    </parent>
  </parents>
  <author>
    <name>Pat Allan</name>
    <email>pat@freelancing-gods.com</email>
  </author>
  <url>http://github.com/freelancing-god/thinking-sphinx/commit/3f3e798d495bf54ba43bc609f292a22b31853575</url>
  <id>3f3e798d495bf54ba43bc609f292a22b31853575</id>
  <committed-date>2009-06-27T22:08:27-07:00</committed-date>
  <authored-date>2009-06-27T22:08:27-07:00</authored-date>
  <message>Allowing for MVAs to use delta column if necessary.</message>
  <tree>7ed53d8632c19d400155520a4fd7a28117f3df5e</tree>
  <committer>
    <name>Pat Allan</name>
    <email>pat@freelancing-gods.com</email>
  </committer>
</commit>
