Commit f4699a8e484f86fdaab420746c7682b4321239d9
1 parent
e9b2ae4f
Exists in
master
and in
22 other branches
[search-improvements] If no results indexed, relevance must be zero
Showing
2 changed files
with
9 additions
and
0 deletions
Show diff stats
app/models/search_term.rb
| @@ -42,6 +42,7 @@ class SearchTerm < ActiveRecord::Base | @@ -42,6 +42,7 @@ class SearchTerm < ActiveRecord::Base | ||
| 42 | 42 | ||
| 43 | def calculate_relevance(valid_occurrences) | 43 | def calculate_relevance(valid_occurrences) |
| 44 | indexed = valid_occurrences.last.indexed.to_f | 44 | indexed = valid_occurrences.last.indexed.to_f |
| 45 | + return 0 if indexed == 0 | ||
| 45 | total = valid_occurrences.last.total.to_f | 46 | total = valid_occurrences.last.total.to_f |
| 46 | (1 - indexed/total)*100 | 47 | (1 - indexed/total)*100 |
| 47 | end | 48 | end |
test/unit/search_term_test.rb
| @@ -118,4 +118,12 @@ class SearchTermTest < ActiveSupport::TestCase | @@ -118,4 +118,12 @@ class SearchTermTest < ActiveSupport::TestCase | ||
| 118 | 118 | ||
| 119 | assert st1.score > st2.score, "Less ratio results:total are not getting higher scores." | 119 | assert st1.score > st2.score, "Less ratio results:total are not getting higher scores." |
| 120 | end | 120 | end |
| 121 | + | ||
| 122 | + should 'consider relevance zero if no results indexed' do | ||
| 123 | + st = SearchTerm.find_or_create('st', Environment.default) | ||
| 124 | + SearchTermOccurrence.create!(:search_term => st, :total => 10, :indexed => 0) | ||
| 125 | + SearchTerm.calculate_scores | ||
| 126 | + st.reload | ||
| 127 | + assert_equal 0, st.score | ||
| 128 | + end | ||
| 121 | end | 129 | end |