Hi!
I faced some issue while using it for dynamic attrs indexing/search.
Maybe I made something wrong. Here is test method. Everything works just
fine until last line http://pastie.caboo.se/66274 . Tested on both
stable and trunk of aaf and ferret 0.11.4.
the short version of code below:
Contact.acts_as_ferret :fields => [ :first_name ]
assert Contact.find(:first).respond_to?(:first_name_to_ferret)
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
Contact.aaf_index.close
FileUtils.rm_rf ''index''
Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
assert Contact.find(:first).respond_to?(:last_name_to_ferret)
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
assert_equal 1, Contact.find_by_contents(''K*'').total_hits #
assertion
fails here: get 0 instead of 1 !!
Maybe there is any better solution to add new fields to existing index?
Best regards,
Yury Kotlyarov
--
Posted via http://www.ruby-forum.com/.
Hi!
I faced some issue while using it for dynamic attrs indexing/search.
Maybe I made something wrong. Here is test method. Everything works just
fine until last line http://pastie.caboo.se/66274 . Tested on both
stable and trunk of aaf and ferret 0.11.4.
the short version of code below:
Contact.acts_as_ferret :fields => [ :first_name ]
assert Contact.find(:first).respond_to?(:first_name_to_ferret)
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
Contact.aaf_index.close
FileUtils.rm_rf ''index''
Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
assert Contact.find(:first).respond_to?(:last_name_to_ferret)
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
assert_equal 1, Contact.find_by_contents(''K*'').total_hits #
assertion
fails here: get 0 instead of 1 !!
Maybe there is any better solution to add new fields to existing index?
--
Best regards,
Yury Kotlyarov
<;-) BrainHouse
web: http://www.brainhouse.ru
email: yura at brainhouse.ru
send all code we have so far and full test case code.
--- model: contact.rb
class Contact < ActiveRecord::Base
end
--- migration: 001_create_contacts_table.rb
class CreateContacts < ActiveRecord::Migration
def self.up
create_table :contacts do |t|
t.column :first_name, :string
t.column :last_name, :string
end
end
def self.down
drop_table :contacts
end
end
--- fixture: contacts.yml
renat:
id: 1
first_name: Renat
last_name: Akhmerov
yura:
id: 2
first_name: Yury
last_name: Kotlyarov
--- test: contact_test.rb
require File.dirname(__FILE__) + ''/../test_helper''
require ''fileutils''
class ContactTest < Test::Unit::TestCase
fixtures :contacts
def setup
if File.exists?(''index'')
FileUtils.rm_rf(''index'')
end
end
def test_new_field
Contact.acts_as_ferret :fields => [ :first_name ]
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
Contact.aaf_index.close
FileUtils.rm_rf(''index'')
Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
# it fails on the following line!! a bug here?
assert_equal 1, Contact.find_by_contents(''K*'').total_hits
end
end
direct access to the index works - thanks to Thomas Nichols for the idea
--- test: contact_test.rb
require File.dirname(__FILE__) + ''/../test_helper''
require ''fileutils''
require ''ferret''
class ContactTest < Test::Unit::TestCase
fixtures :contacts
def setup
if File.exists?(''index'')
FileUtils.rm_rf(''index'')
end
end
def test_new_field
Contact.acts_as_ferret :fields => [ :first_name ]
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
Contact.aaf_index.close
FileUtils.rm_rf(''index'')
Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
# it fails on the following line!! a bug here?
#assert_equal 1, Contact.find_by_contents(''K*'').total_hits
idx = Ferret::Index::Index.new(ath =>
''index/test/contact'',
:create_if_missing => false)
assert_equal 1, idx.search(''last_name:K*'').total_hits
assert_equal 1, idx.search(''K*'').total_hits
end
end
Yury Kotlyarov wrote:> send all code we have so far and full test case code.
>
> --- model: contact.rb
> class Contact < ActiveRecord::Base
> end
>
> --- migration: 001_create_contacts_table.rb
> class CreateContacts < ActiveRecord::Migration
> def self.up
> create_table :contacts do |t|
> t.column :first_name, :string
> t.column :last_name, :string
> end
> end
>
> def self.down
> drop_table :contacts
> end
> end
>
> --- fixture: contacts.yml
> renat:
> id: 1
> first_name: Renat
> last_name: Akhmerov
> yura:
> id: 2
> first_name: Yury
> last_name: Kotlyarov
>
> --- test: contact_test.rb
>
> require File.dirname(__FILE__) + ''/../test_helper''
> require ''fileutils''
>
> class ContactTest < Test::Unit::TestCase
> fixtures :contacts
>
> def setup
> if File.exists?(''index'')
> FileUtils.rm_rf(''index'')
> end
> end
>
> def test_new_field
> Contact.acts_as_ferret :fields => [ :first_name ]
> assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
> assert_equal 1,
Contact.find_by_contents(''Y*'').total_hits
>
> Contact.aaf_index.close
> FileUtils.rm_rf(''index'')
>
> Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
>
> assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
> # it fails on the following line!! a bug here?
> assert_equal 1,
Contact.find_by_contents(''K*'').total_hits
> end
> end
>
>
> _______________________________________________
> Ferret-talk mailing list
> Ferret-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ferret-talk
>
>
--
Best regards,
Yury Kotlyarov
<;-) BrainHouse
web: http://www.brainhouse.ru
email: yura at brainhouse.ru
skype: yura__115
phone: +7 905 758 1491
jabber: yury.kotlyarov at jabber.ru
Yury Kotlyarov
2007-May-31 22:00 UTC
[Ferret-talk] aaf and dynamic attrs: a bug? WORKAROUND
Got a workaround!
Adding following line solves the problem:
Contact.aaf_index.ferret_index.options[:default_field] <<
''last_name''
So is it a bug in aaf?
--- here is full testrequire File.dirname(__FILE__) +
''/../test_helper''
require ''fileutils''
class ContactTest < Test::Unit::TestCase
fixtures :contacts
def setup
if File.exists?(''index'')
FileUtils.rm_rf(''index'')
end
end
def test_new_field
Contact.acts_as_ferret :fields => [ :first_name ]
assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
assert_equal 1, Contact.find_by_contents(''Y*'').total_hits
Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
Contact.aaf_index.close
FileUtils.rm_rf(''index'')
Contact.aaf_index.ferret_index.options[:default_field] <<
''last_name''
assert_equal 1, Contact.find_by_contents(''K*'').total_hits
end
end
Yury Kotlyarov wrote:> direct access to the index works - thanks to Thomas Nichols for the idea
>
> --- test: contact_test.rb
> require File.dirname(__FILE__) + ''/../test_helper''
> require ''fileutils''
> require ''ferret''
>
> class ContactTest < Test::Unit::TestCase
> fixtures :contacts
>
> def setup
> if File.exists?(''index'')
> FileUtils.rm_rf(''index'')
> end
> end
>
> def test_new_field
> Contact.acts_as_ferret :fields => [ :first_name ]
> assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
> assert_equal 1,
Contact.find_by_contents(''Y*'').total_hits
>
> Contact.aaf_index.close
> FileUtils.rm_rf(''index'')
>
> Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
>
> assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
>
> # it fails on the following line!! a bug here?
> #assert_equal 1,
Contact.find_by_contents(''K*'').total_hits
>
> idx = Ferret::Index::Index.new(ath =>
''index/test/contact'',
> :create_if_missing => false)
> assert_equal 1, idx.search(''last_name:K*'').total_hits
> assert_equal 1, idx.search(''K*'').total_hits
> end
> end
>
>
> Yury Kotlyarov wrote:
>
>> send all code we have so far and full test case code.
>>
>> --- model: contact.rb
>> class Contact < ActiveRecord::Base
>> end
>>
>> --- migration: 001_create_contacts_table.rb
>> class CreateContacts < ActiveRecord::Migration
>> def self.up
>> create_table :contacts do |t|
>> t.column :first_name, :string
>> t.column :last_name, :string
>> end
>> end
>>
>> def self.down
>> drop_table :contacts
>> end
>> end
>>
>> --- fixture: contacts.yml
>> renat:
>> id: 1
>> first_name: Renat
>> last_name: Akhmerov
>> yura:
>> id: 2
>> first_name: Yury
>> last_name: Kotlyarov
>>
>> --- test: contact_test.rb
>>
>> require File.dirname(__FILE__) + ''/../test_helper''
>> require ''fileutils''
>>
>> class ContactTest < Test::Unit::TestCase
>> fixtures :contacts
>>
>> def setup
>> if File.exists?(''index'')
>> FileUtils.rm_rf(''index'')
>> end
>> end
>>
>> def test_new_field
>> Contact.acts_as_ferret :fields => [ :first_name ]
>> assert_equal 1,
Contact.find_by_contents(''first_name:Y*'').total_hits
>> assert_equal 1,
Contact.find_by_contents(''Y*'').total_hits
>>
>> Contact.aaf_index.close
>> FileUtils.rm_rf(''index'')
>>
>> Contact.acts_as_ferret :fields => [ :first_name, :last_name ]
>>
>> assert_equal 1,
Contact.find_by_contents(''last_name:K*'').total_hits
>> # it fails on the following line!! a bug here?
>> assert_equal 1,
Contact.find_by_contents(''K*'').total_hits
>> end
>> end
>>
>>
>> _______________________________________________
>> Ferret-talk mailing list
>> Ferret-talk at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ferret-talk
>>
>>
>>
>
>
>
--
Best regards,
Yury Kotlyarov
<;-) BrainHouse
web: http://www.brainhouse.ru
email: yura at brainhouse.ru
skype: yura__115
phone: +7 905 758 1491
jabber: yury.kotlyarov at jabber.ru