I have kind of a problem when trying to test thinking sphinx in my
Rails application. I don't want to mock it because I want to be sure
config and search options are working the desired way.
- Ruby: 1.8.7 (i686-darwin10.6.0); Rails: 2.3.11; Thinking Sphinx: 1.4.3
I only index a join-table model:
class AffiliatesAddress < ActiveRecord::Base
# DB relations:
belongs_to :address
belongs_to :affiliate, :polymorphic => true, :dependent => :delete
# Thinking-sphinx configuration
define_index do
...
has affiliate.direct, :as => :formato_direct, :type => :boolean
has affiliate.papel, :as => :formato_papel, :type => :boolean
has 'CRC32(affiliate_type)', :as => :affiliate_type, :type => :integer
end
end
To setup sphinx I need a relation for every affiliate type in DB,
which is ok. The problem is that if I save those relations in the same
execution I configure thinking sphinx, indexing is not aware of the
data in DB.
For example: I created a rake task as a per-requisite for
thinking-sphinx:index. The first time i run index, with an empty DB,
the config process doesn´t create the right SQL (it does without
polymorphic relations). But if I run index one more time, this time
with the relations remaining from previous execution, then all goes
ok. The same if I save the relations in a before(:all) block from
rspec. I am pretty sure relations are successfully saved before
calling indexing/config process.
In local, I generated the config first and then tweaked the tests to
avoid config again when DB is empty. But it's not a good solution for
the integration server or to share with the other team members.
Am I doing something wrong (other than my English)? some ideas?
Thanks for your time.
--
Rodrigo García Suárez
It looks like you're aware that TS requires data for polymorphic joins to index them correctly... so I'm not entirely sure what's going wrong here.
Are you using transactions for your tests? Because Sphinx can't operate with those. Also, are you using ThinkingSphinx::Test? I highly recommend you do, as you shouldn't need to use any of the TS rake tasks from within your tests...
In particular:
ThinkingSphinx::Test.index 'affiliates_address_core'
More info is here:
http://freelancing-god.github.com/ts/en/testing.html#functional
Let me know if I'm not understanding things quite right, or you get stuck with something else.
Cheers
--
Pat
> --
> You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
> To post to this group, send email to thinkin...@googlegroups.com.
> To unsubscribe from this group, send email to thinking-sphi...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
>
I think the issue here is that the configuration file isn't rewritten when you index. Try adding the following after creating your addresses:
ThinkingSphinx::Test.config.build
Cheers
--
Pat
Can you share the code you've got in your before(:each) block?
--
Pat
Maybe you've tried this already and I'm misunderstanding earlier emails, but what happens if you put ThinkingSphinx::Test.config.build above the ThinkingSphinx::Test.index line:
# ... creating objects
3.times { ComplimentsAffiliate.make.addresses << Address.make }
ThinkingSphinx::Test.config.build
ThinkingSphinx::Test.index
ThinkingSphinx::Test.start
# stubbing objects
--
Pat