Indeed, it is slow, but I'd only be using that init method for 
integration/acceptance tests, and otherwise be disabling the callbacks.

The alternative to calling stop and clear is to delete records in the indices, 
which may work well enough, but it's certainly more fiddly (query Sphinx for 
index list, then for each index, query for each record and delete it - there's 
no simple DELETE FROM index command available, sadly).

On 14 Mar 2014, at 11:24 am, Enrico Pilotto <[email protected]> wrote:

> If I change my method 
> 
>   def init_thinking_sphinx
>     ThinkingSphinx::Test.stop
>     delete_indices_files
>     ThinkingSphinx::Test.init
>     ThinkingSphinx::Test.start
>     generate
>   end
> 
> all works, but start and stop searchd for every test is slow. In your opinion 
> is there a way to do without restarting searchd? Thanks for your help! ... 
> again :D
> 
> 
> Il giorno venerdì 14 marzo 2014 01:06:41 UTC+1, Pat Allan ha scritto:
> Hi Enrico
> 
> The start_with_autostop method means that the daemon stops after the entire 
> test process has finished. This also means that even though you've deleted 
> the index files, Sphinx will still have the old data loaded (real-time 
> indices are largely stored in RAM).
> 
> Could you try with the examples of my previous post in this thread instead, 
> while using the latest version of TS from the develop branch?
> 
> You shouldn't need a generate method - the callbacks will automatically 
> populate data.
> 
> -- 
> Pat
> 
> On 14 Mar 2014, at 2:14 am, Enrico Pilotto <[email protected]> wrote:
> 
>> Hi, I've similar issue with tests and Thinking Sphinx with Real Time indices.
>> I've a test helper: sphinx_helper.rb like this:
>> 
>> module SphinxHelper
>>   def init_thinking_sphinx
>>     delete_indeces_files
>>     ThinkingSphinx::Test.init
>>     ThinkingSphinx::Test.start_with_autostop
>>     generate
>>   end
>> 
>>   def generate
>>     
>> ActiveSupport::Notifications.unsubscribe('start_populating.thinking_sphinx.real_time')
>>     
>> ActiveSupport::Notifications.unsubscribe('populated.thinking_sphinx.real_time')
>>     
>> ActiveSupport::Notifications.unsubscribe('finish_populating.thinking_sphinx.real_time')
>>     indices = ThinkingSphinx::Configuration.instance.indices.select { 
>> |index| index.type == 'rt' }
>>     indices.each do |index|
>>       ThinkingSphinx::RealTime::Populator.populate index
>>     end
>>   end
>> 
>>   def delete_indeces_files
>>     # FileUtils.rm_rf(ThinkingSphinx::Test.config.indices_location)
>>     Dir[Rails.root.join(ThinkingSphinx::Test.config.indices_location, 
>> '*.{meta,ram}')].each do |file|
>>       FileUtils.rm_rf(file)
>>     end
>>   end
>> 
>> end
>> 
>> In tests that use ts in setup method I call the method init_thinking_sphinx 
>> that delete indices, init ts, start ts and generate indices. All seems works 
>> if I run unit tests and integration tests separately. But if I run all my 
>> test (unit and integration) with rake test I get the error 
>> ThinkingSphinx::Search::StaleIdsException: Record IDs found by Sphinx but 
>> not by ActiveRecord ONLY on integration test that use thinking sphinx. If I 
>> run integration tests alone, I get no errors.
>> 
>> Thx for reply!
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Thinking Sphinx" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/thinking-sphinx.
>> For more options, visit https://groups.google.com/d/optout.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Reply via email to