Ticket #17 (closed defect: fixed)
Ticket
| Reported by: | jennyw@… | Owned by: | anonymous |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | component1 | Version: | 2.0 |
| Keywords: | MESSAGE | Cc: | Roma |
Description
I had a problem with fuzzy search and created what I think is the right fix. The problem happens when you have some terms that are larger than Ferret::Search::TYPICAL_LONGEST_WORD_IN_INDEX (and possibly not in all cases).
When running a search, I'd get an error like this (partial stack trace):
NoMethodError: You have a nil object when you didn't expect it!
The error occured while evaluating nil.<
from c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.3.1/lib/ferret/search/fuzzy_term_enum.rb:166:in `similarity'
from c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.3.1/lib/ferret/search/fuzzy_term_enum.rb:151:in `synchronize'
from c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.3.1/lib/ferret/search/fuzzy_term_enum.rb:151:in `similarity'
from c:/ruby/lib/ruby/gems/1.8/gems/ferret-0.3.1/lib/ferret/search/fuzzy_term_enum.rb:82:in `term_compare'
I saw that the line in question was:
if (max_distance < (m-n).abs)
So it seems that max_distance is equal to nil. I looked through the program and saw that max_distance gets set a line above:
max_distance = max_distance(m)
by the max_distance function. This function is currently written like:
def max_distance(m)
if (m >= @max_distances.length)
@max_distances[m] = calculate_max_distance(m)
end
return @max_distances[m]
end
I figure this happens when because @max_distances is expanded and the elements between the old last element and the new last element are now nil. Since @max_distances gets initialized by initialize_max_distances and it sets each element using the calculate_max_distance method (with the position as the parameter), I changed max_distance to:
def max_distance(m)
old_size = @max_distances.length
if (m >= old_size)
for i in old_size..m
@max_distances[i] = calculate_max_distance(i)
end
end
return @max_distances[m]
end
And it seems to work. Of course, I made this change based on an educated guess and I don't completely grok everything in the file (let alone the whole of Ferret), so this might or might not be the right thing to do. The results are what I'd expect, though, so that's a good sign!
Jen

