Forum: Ferret highlighting with find_with_ferret

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.
Af3e7006b5dec6098012c2a35e92aaf2?d=identicon&s=25 Romina Castillo (iuranchita)
on 2009-02-09 15:57
Hello!

I'm trying to highlight my search results,  but it doesn't work.-

In the model i have this:

acts_as_ferret( :fields => {
          :name => {:store => :yes , :boots => 100},
          :description => {:store => :yes , :boots => 50}
      })

...and i'm using find_with_ferret, so, in the controller i have this:

@repos = Repo.find_with_ferret(cad)

I don't know what to do in the view, because everything i try never
works.

I hope you can help me.
Thanks and I apologize by my bad english!!!!!
236e5f67c35a7db58901b2ac90f49b4f?d=identicon&s=25 JT Kimbell (studbucket)
on 2009-02-12 17:27
I'm also having trouble with highlighting and would appreciate seeing an
answer to this.

Thanks,

JT
Af3e7006b5dec6098012c2a35e92aaf2?d=identicon&s=25 Romina Castillo (iuranchita)
on 2009-02-12 18:41
JT Kimbell wrote:
> I'm also having trouble with highlighting and would appreciate seeing an
> answer to this.

well, this is the solution that worked for me.
in the controller:

    def busqueda
        @cad = prepare_query(params[:query])
  @repos = Repo.find_with_ferret(@cad)
    end

in the view:
<% for repo in @repos %>
   <%= repo.highlight(@cad, :field=> :name , :pre_tag => "<strong>" ,
:post_tag=>"</strong>" %>
<% end %>

in the model:

acts_as_ferret( :fields => {:name => {:store => :yes , :boost => 2}})



my english is really bad, so i'm sorry

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