Forum: Ferret index.rb:384 [BUG]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ae4934509f3f81bf970dde18ffd6fad8?d=identicon&s=25 Xavier Belanche (Guest)
on 2007-03-12 17:02
Hi folks,
I've working and playing with acts_as_ferret and follow this fantastic
tutorial:
http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial

When I try to implement the field storage tip, it crash. So, I try to
make it via script/console:

1. I have a simple model called Articles:
class Article < ActiveRecord::Base
        acts_as_ferret :fields => ['title']
end

2. In the console, I try this:

>> index = Article.ferret_index
=> #<Ferret::Index::Index:0x2b686dc76860 @writer=nil,
@default_input_field=:id, @qp=nil,
@dir=#<Ferret::Store::FSDirectory:0x2b686dc76748>,
@mon_entering_queue=[], @default_field=["title"], @key=:id,
@mon_count=0, @auto_flush=true, @open=true, @close_dir=true,
@id_field=:id, @mon_owner=nil, @reader=nil, @searcher=nil,
@options={:lock_retry_time=>2,
:path=>"script/../config/../config/../index/development/article",
:create_if_missing=>true, :default_field=>["title"],
:analyzer=>#<Ferret::Analysis::StandardAnalyzer:0x2b686dc75f78>,
:auto_flush=>true, :or_default=>false,
:dir=>#<Ferret::Store::FSDirectory:0x2b686dc76748>, :key=>:id,
:handle_parse_errors=>true}, @mon_waiting_queue=[]>

(it's ok, seems to run ok! :)

>> query = "ruby"
=> "ruby"
>> options =""

(mmmh, just enough! Now.... )
>> index.search_each(query, options) do |doc, score|
?> puts index[doc][:title]
>> end

And the next and horrible message!

/usr/local/lib/site_ruby/1.8/ferret/index.rb:384: [BUG] Segmentation
fault
ruby 1.8.4 (2005-12-24) [x86_64-linux]

Woops!
Someone has the same bug!????

For more tech information:

Rails 1.2.2
Gem 0.9.2
acts_as_ferret (0.3.1)
ferret (0.11.3)

Thanks everyone!
C9dd93aa135988cabf9183d3210665ca?d=identicon&s=25 Jens Kraemer (Guest)
on 2007-03-13 09:41
(Received via mailing list)
On Mon, Mar 12, 2007 at 05:02:53PM +0100, Xavier Belanche wrote:
>         acts_as_ferret :fields => ['title']
> end

you'll have to tell aaf to store field values in the index:

acts_as_ferret :fields => { :title => { :store => :yes } }


Jens


--
Jens Krämer
webit! Gesellschaft für neue Medien mbH
Schnorrstraße 76 | 01069 Dresden
Telefon +49 351 46766-0 | Telefax +49 351 46766-66
kraemer@webit.de | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2007-03-13 11:59
(Received via mailing list)
On 3/13/07, Xavier Belanche <xbelanch@gmail.com> wrote:
> /usr/local/lib/site_ruby/1.8/ferret/index.rb:384: [BUG] Segmentation
> fault
> ruby 1.8.4 (2005-12-24) [x86_64-linux]

options must be a Hash or nil, not a String. One of the things I still
need to do with Ferret is add argument checking. At the moment, if you
pass a string when a hash is expected you'll get a segfault or bus
error like this. I do plan to fix this in future.

Cheers,
Dave
Ae4934509f3f81bf970dde18ffd6fad8?d=identicon&s=25 Xavier Belanche (Guest)
on 2007-03-13 19:44
David Balmain wrote:
> On 3/13/07, Xavier Belanche <xbelanch@gmail.com> wrote:
>> /usr/local/lib/site_ruby/1.8/ferret/index.rb:384: [BUG] Segmentation
>> fault
>> ruby 1.8.4 (2005-12-24) [x86_64-linux]
>
> options must be a Hash or nil, not a String. One of the things I still
> need to do with Ferret is add argument checking. At the moment, if you
> pass a string when a hash is expected you'll get a segfault or bus
> error like this. I do plan to fix this in future.
>
> Cheers,
> Dave

Thanks David.
It's that you say: if I pass options like a Hash or nil not appears a
bus error. In other way, I dont undertand why is the reason I always
recieve a nil result when I use this method in the same way:

$ ./script/console
Loading development environment.
>> article = Article.find 1
=> #<Article:0x2b5120600828 @attributes={"title"=>"Ruby on Rails",
"id"=>"1", "content"=>"Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Nullam tempor risus et ante. Maecenas consectetuer
feugiat orci. Fusce vehicula velit id odio. Phasellus ut mauris. Aenean
faucibus dolor quis nibh. Praesent convallis est id ante. In felis. "}>

Ok! I put in the Article model those lines :)

class Article < ActiveRecord::Base
        acts_as_ferret :fields => {
                :title=> {:store=> :yes}
                }
end

I return to console and I put the follow lines:

>> index = Article.ferret_index
=> #<Ferret::Index::Index:0x2b5120574120 @writer=nil,
@default_input_field=:id, @qp=nil,
@dir=#<Ferret::Store::FSDirectory:0x2b51205734f0>,
@mon_entering_queue=[], @default_field=[:title], @key=:id, @mon_count=0,
@auto_flush=true, @open=true, @close_dir=true, @id_field=:id,
@mon_owner=nil, @reader=nil, @searcher=nil,
@options={:lock_retry_time=>2,
:path=>"script/../config/../config/../index/development/article",
:create_if_missing=>true, :default_field=>[:title],
:analyzer=>#<Ferret::Analysis::StandardAnalyzer:0x2b5120572460>,
:auto_flush=>true, :or_default=>false,
:dir=>#<Ferret::Store::FSDirectory:0x2b51205734f0>, :key=>:id,
:handle_parse_errors=>true}, @mon_waiting_queue=[]>

Next, I try to evaluate the search_each method

>> index.search_each("Ruby",{}) do |doc, score|
?> puts index[doc][:title]
>> puts doc,score
>> end
nil
1
0.764464735984802

Great! I recieve a score value (value), the correct id value (doc),  but
it's not possible to acquire the :title value with the
"index[doc][:title]" expression...  :( it's always returns the nil value
:(
So, any way to achieve it?

Thanks for all!
B5e329ffa0cc78efbfc7ae2d084c149f?d=identicon&s=25 David Balmain (Guest)
on 2007-03-14 02:58
(Received via mailing list)
On 3/14/07, Xavier Belanche <xbelanch@gmail.com> wrote:

> adipiscing elit. Nullam tempor risus et ante. Maecenas consectetuer
>
> :path=>"script/../config/../config/../index/development/article",
> >> puts doc,score
>
> Thanks for all!

Did you rebuild your index when you changed the title to a stored
field? I don't think this will happen automatically.
Ae4934509f3f81bf970dde18ffd6fad8?d=identicon&s=25 Xavier Belanche (Guest)
on 2007-03-14 19:11
David Balmain wrote:
> On 3/14/07, Xavier Belanche <xbelanch@gmail.com> wrote:
>
>> adipiscing elit. Nullam tempor risus et ante. Maecenas consectetuer
>>
>> :path=>"script/../config/../config/../index/development/article",
>> >> puts doc,score
>>
>> Thanks for all!
>
> Did you rebuild your index when you changed the title to a stored
> field? I don't think this will happen automatically.

Thanks! it's ok now :DDDDDDD

Only make:
>> Article.rebuild_index

And that's run ok! :D

Thanks again!
This topic is locked and can not be replied to.