Forum: Ferret Using Highlight on Concatenated ActsAsFerret::SearchResults

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.
JT K. (Guest)
on 2008-12-11 17:44
Hi,

This is my first attempt at trying to use aaf's highlight function, and
I am having a getting it to return anything.  First I'll give some
background, then show you my problem.

In my model, I have the content field stored.

acts_as_ferret :fields => { :title => {:store => :no}, :content =>
{:store => :yes}}

In my controller, I have a list of queries that I have created (A causes
B, B is caused by A, A may cause B, etc) and when a link is selected all
of those 'synonymous' queries are executed and their results are
concatenated together.  Some code for that is below:

@results = []
@queries = #List of unique queries from database
for @q in @queries
   @results.concat(Result.find_by_contents(CGI::unescape(@q.exactquery),
:lazy => :true))
end

So, you see that I now have an array containing individual
ActsAsFerret::SearchResult objects.  When one of the results is
selected, I grab that result from the array and attempt to display it
with the query highlighted in my view.  Here is that code:

<%= @result.highlight(@query, :field => :content, :num_excerpts => 1,
:pre_tag => "<strong>", :post_tag => "</strong>").to_s %>

If I put <%= @result.content %> in the view, the content is posted just
fine, but if I have the above code in the view, nothing is displayed on
the page.

Am I doing something wrong with highlighting?  Am I losing something
when concatenating the results into an array?

Your help is much appreciated.

JT
JT K. (Guest)
on 2008-12-16 22:29
Just bumping this to see if someone could help me out.  Is there
somewhere/someone else I should be asking?

Thanks,

JT
JT K. (Guest)
on 2009-01-20 06:08
One last bump, I really, really, really would appreciate some help on
this.

If you can't help me here, is there somewhere else I can look for help?

Thanks,

JT
This topic is locked and can not be replied to.