Commit 3705398481c7d08d2f2648789d370530fe3abdd7

Authored by MoisesMachado
1 parent 4f534f4a

ActionItem128: filtered stop words from the query


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1183 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -39,7 +39,8 @@ class SearchController < ApplicationController
39 39  
40 40 def index
41 41 @query = params[:query] || ''
42   - @results = search(@query)
  42 + @filtered_query = remove_stop_words(@query)
  43 + @results = search(@filtered_query)
43 44 end
44 45  
45 46 def tags
... ...
app/helpers/search_helper.rb
1 1 module SearchHelper
2 2  
  3 + STOP_WORDS = {
  4 + 'pt_BR' => Ferret::Analysis::FULL_PORTUGUESE_STOP_WORDS,
  5 + 'en' => Ferret::Analysis::FULL_ENGLISH_STOP_WORDS,
  6 + }
  7 +
3 8 def relevance_for(hit)
4 9 n = (hit.ferret_score if hit.respond_to?(:ferret_score))
5 10 n ||= 1.0
6 11 (n * 100.0).round
7 12 end
  13 +
  14 + def remove_stop_words(query)
  15 + (query.downcase.split(' ') - STOP_WORDS[Locale.current.to_s]).join(' ')
  16 + end
8 17 end
... ...
test/functional/search_controller_test.rb
... ... @@ -21,4 +21,11 @@ class SearchControllerTest < Test::Unit::TestCase
21 21  
22 22 end
23 23  
  24 + should 'filter stop words' do
  25 + get 'index', :query => 'a carne da vaca'
  26 + assert_response :success
  27 + assert_template 'index'
  28 + assert_equal 'carne vaca', assigns('filtered_query')
  29 + end
  30 +
24 31 end
... ...