#63 ✓resolved

Odd interactions between num_excerpts, ferret_score and searched text in highlighted search results

Reported by Jens | February 13th, 2010 @ 12:39 AM

As a newbie to Ruby, Rails and Ferret, I am a bit reluctant to submit an observation as a "defect", so I hope you'll forgive me if I have overlooked something obvious to all the experienced people out there. Yet what I am seeing prevents me from incorporating Ferret as I would like. So, here goes...

I am running Win2K and using Ruby 1.8.6, Rails 1.2.4, ferret-0.11.4-mswin32 and the plug-in from :svn//projects.jkraemer.net/acts_as_ferret/tags/stable/acts_as_ferret. I have incorporated Ferret into a single-table, two-field search along the lines documented in Gregg's Tutorial at railsenvy.com. My table contains info on local Organizations (Class = Org) and the fields searched are org.name (a [[MySQL]] string) and org.description (a [[MySQL]] blob). Class Org contains the following statement:

  acts_as_ferret :fields=>{

            :name => {:store => :yes},
            :description => {:store => :yes}

My controller accepts a string of keywords from a form and ORs their "fuzzy" forms together like this:

@cleaned_up_keywords=params[:keywords].gsub('"'," ").gsub(","," ").squeeze(" ").strip
@fuzzy_keywords=@cleaned_up_keywords.gsub(" ", "~ OR ") + "~"
@search_results = Org.find_by_contents(@fuzzy_keywords, :limit=>:all, :lazy => [:name, :description])

My view renders the results of the search back into the same template as the keyword submission Form. Here is the complete template:
<% form_tag :action => 'search' do%>
<label for="keywords">Enter search keywords</label><br/>
<%= text_field_tag 'keywords', value=@cleaned_up_keywords,options={:size=>60, :maxlength=>255}  %><br/>

<%= submit_tag 'Search' %> <%end%>

<% if @search_results.nil? == false then %>

<% @search_results.each do |r|%>
        <%= r.name %> says  
        "<%= r.highlight(@fuzzy_keywords, :fields => :description, :num_excerpts => 1, 
                    :pre_tag => "<strong style='color: green;'>", :post_tag => "</strong>",
                    :excerpt_length => 35)%>"


The attachment shows the template rendered for four different values of :num_excerpts. I fiddled with the text in the organization's descriptions in order to get ferret scores that resulted in the sequence of results shown in the first figure. That sequence makes the problem easier to see. Between generating each figure, I did not change anything but :num_excerpts in the template. I have verified that removing the
  • tags does not affect the results. While the attachment describes a couple of odd behaviors, the one that is most serious in my application is the appending of the :name field to the search results.

Thanks in advance for looking at this.

No comments found

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Shared Ticket Bins

People watching this ticket