Commit 3705398481c7d08d2f2648789d370530fe3abdd7
1 parent
4f534f4a
Exists in
master
and in
29 other branches
ActionItem128: filtered stop words from the query
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1183 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
18 additions
and
1 deletions
Show diff stats
app/controllers/public/search_controller.rb
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 | ... | ... |