Hi,

I have i am trying to add a search feature to a ruby on rails blog, so
ive decided to use ferret. So far i have had quite a few problems with
it, from following a few tutorials i didnt really understand... i am at
the point where i can make a search and it returns the score of the
result. I want it to also show the title of the post and i think i have
implemented it correctly but it doesn't.

This is the code in my search.rhtml:

<% @results.each_with_index do |result, index| %>
                <%= result[:title] %>
                    Score: <%= result[:score] %><br/><br/>
<% end %>

And this is the controller:

def search
    @query = params[:q]
    @total, @results = Post.find_storage_by_contents(@query, :page =>
    (params[:page]||1))
    @pages = pages_for(@total)
end

This is the code from post.rb:

def self.find_storage_by_contents(query, options = {})
    # Get the index that acts_as_ferret created for us
    index = self.aaf_index.ferret_index
    results = []

    # search_each is the core search function from Ferret, which
Acts_as_ferret hides
    total_hits = index.search_each(query, options) do |doc, score|
      result = {}

      # Store each field in a hash which we can reference in our views
      result[:title] = index[doc][:title]


      # We can even put the score in the hash, nice!
      result[:score] = score

      results.push result
    end
    return block_given? ? total_hits : [total_hits, results]
  end

there is probably something i have missed before this is able to work,
if u have any ideas please help! thanks, Will

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ferret-talk mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ferret-talk

Reply via email to