From 3705398481c7d08d2f2648789d370530fe3abdd7 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 9 Jan 2008 22:44:25 +0000 Subject: [PATCH] ActionItem128: filtered stop words from the query --- app/controllers/public/search_controller.rb | 3 ++- app/helpers/search_helper.rb | 9 +++++++++ test/functional/search_controller_test.rb | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index 603f292..cf9201e 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -39,7 +39,8 @@ class SearchController < ApplicationController def index @query = params[:query] || '' - @results = search(@query) + @filtered_query = remove_stop_words(@query) + @results = search(@filtered_query) end def tags diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb index 35ee5ba..76e416a 100644 --- a/app/helpers/search_helper.rb +++ b/app/helpers/search_helper.rb @@ -1,8 +1,17 @@ module SearchHelper + STOP_WORDS = { + 'pt_BR' => Ferret::Analysis::FULL_PORTUGUESE_STOP_WORDS, + 'en' => Ferret::Analysis::FULL_ENGLISH_STOP_WORDS, + } + def relevance_for(hit) n = (hit.ferret_score if hit.respond_to?(:ferret_score)) n ||= 1.0 (n * 100.0).round end + + def remove_stop_words(query) + (query.downcase.split(' ') - STOP_WORDS[Locale.current.to_s]).join(' ') + end end diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index c1a9203..4d5ff68 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -21,4 +21,11 @@ class SearchControllerTest < Test::Unit::TestCase end + should 'filter stop words' do + get 'index', :query => 'a carne da vaca' + assert_response :success + assert_template 'index' + assert_equal 'carne vaca', assigns('filtered_query') + end + end -- libgit2 0.21.2