Higlighting problem

Hi,

I’ve been having a problem getting highlighting to work with aaf.

I have a class defined as follows such:

class Link < ActiveRecord::Base
acts_as_ferret :fields => { :description => { :store => :yes } }
end

I get back the correct results when I do Link.find_by_contents, however,
I’d like to highlight them.

If I do something like iterate through the list of results and call
result.highlight(“myquery”, :field => :description), but this is
returning nil for each result. How is this possible if these results are
correctly returned because “myquery” is a token in their description? Am
I incorrectly using the api?

Thanks for the help,
Ben

On Fri, Mar 09, 2007 at 05:06:08AM +0100, Ben wrote:

I get back the correct results when I do Link.find_by_contents, however,
I’d like to highlight them.

If I do something like iterate through the list of results and call
result.highlight(“myquery”, :field => :description), but this is
returning nil for each result. How is this possible if these results are
correctly returned because “myquery” is a token in their description? Am
I incorrectly using the api?

your usage of the api is perfectly right. I’m not sure what’s going on
there, and can’t reproduce this here.

To help debug this a bit, could you please try this in the console:

results = Link.find_by_contents(query)
result = results.first
result.highlight(query, :field => :description) # returns nil

doc_num = result.document_number

if you are on aaf trunk:

Link.aaf_index.ferret_index.highlight(query, doc_num, :field =>
:description)

if on aaf stable:

Link.ferret_index.highlight(query, doc_num, :field => :description)

this would directly use ferret’s highlight method. Btw, what version of
aaf do you use?

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
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

On Thu, Mar 29, 2007 at 01:07:00PM +0200, P. Schrammel wrote:

:description)
still ‘nil’.
How can I find out if :store is set to :yes?

retrieve a ferret document from the index and try to access the field in
question:

doc = index[doc_num]
puts doc[:field]

if it gives the contents of the field, the field is :store => :yes, if
nil, it isn’t.

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
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa

Jens K. wrote:

results = Link.find_by_contents(query)
result = results.first
result.highlight(query, :field => :description) # returns nil

doc_num = result.document_number

if you are on aaf trunk:

Link.aaf_index.ferret_index.highlight(query, doc_num, :field =>
:description)

if on aaf stable:

Link.ferret_index.highlight(query, doc_num, :field => :description)

this would directly use ferret’s highlight method. Btw, what version of
aaf do you use?


Hi all,
same Problem here…using gem version 0.11.3. I tried the above but
still ‘nil’.
How can I find out if :store is set to :yes?

Regards
Peter

Now it works…don’t ask why. I’ll try to explain what I did, perhaps
you’ll find the error:

Created a rails model:

class Article < ActiveRecord::Base
acts_as_ferret :fields => [:normalized_text],
:analyzer => HTMLAnalyzer.new
end

-filled in the data. Found docs that I should use :store
-called Article.delete_all on the rails console
-rewrote article.rb :

class Article < ActiveRecord::Base
acts_as_ferret :fields => { :normalized_text => {:store => :yes }},
:analyzer => HTMLAnalyzer.new
end

-fill in the data (highlight didn’t work)
-did Article.delete_all again
-rm RAILS_ROOT/index/article/*
-fill in the data
-highlight works

Thanks
Peter

On Thu, Mar 29, 2007 at 02:59:04PM +0200, P. Schrammel wrote:

Now it works…don’t ask why. I’ll try to explain what I did, perhaps
you’ll find the error:

yeah, delete_all is evil because it only does the sql delete without
calling the Rails callback methods for the deleted records - so there’s
no way for aaf to remove the old entries from the index. destroy_all
would have worked. By deleting the index directory you forced aaf to
rebuild the index, which then used the new aaf-options.

Long story short: Calling Article.rebuild_index after changing the aaf
options would have worked, too :slight_smile:

Jens

-rewrote article.rb :
-highlight works


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
[email protected] | www.webit.de

Amtsgericht Dresden | HRB 15422
GF Sven Haubold, Hagen Malessa