Skip to content

Commit

Permalink
Tree view for scientific results, no disambiguation for duplicate res…
Browse files Browse the repository at this point in the history
…ults, and all results have more information (search presentation); resolves EOLINFRASTRUCTURE-1666

git-svn-id: file:///data/subversion/eol/trunk@1811 78829999-583a-0410-bd01-8a9b849fd409
  • Loading branch information
jrice committed Mar 31, 2010
1 parent 7552396 commit aa3e152
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 32 deletions.
17 changes: 5 additions & 12 deletions app/views/taxa/_search_results_table.html.haml
Expand Up @@ -21,23 +21,16 @@
%a{ :href => url_for(:action => 'search_clicked', :id => result['id']) }
%img{ :title => strip_tags(result['best_matched_scientific_name']), :src => result['top_image'].smart_medium_thumb, :alt => strip_tags(result['best_matched_scientific_name']) }
%td{ :class => column_class }
- if result['duplicate']
.ancestor= result['ancestor_common']
.parent= result['parent_common']
%div{:class => "result#{' duplicate' if result['duplicate']}"}
%div{:class => "result"}
= link_to hh(result['best_matched_common_name']), {:action => 'search_clicked', :id => result['id']}, :method=>:post
= result['common_shown_as']
- if result['duplicate']
%span.recognized_by= "Taxon recognized by #{result['recognized_by']}"
%td{ :class => column_class }
- if result['duplicate']
.ancestor= result['ancestor_scientific']
.parent= result['parent_scientific']
%div{:class => "result#{' duplicate' if result['duplicate']}"}
.ancestor= result['ancestor_scientific']
.parent= result['parent_scientific']
%div{:class => "result duplicate"}
= link_to hh(result['best_matched_scientific_name']), {:action => 'search_clicked', :id => result['id']}, :method=>:post
= result['scientific_shown_as']
- if result['duplicate']
%span.recognized_by= "Taxon recognized by #{result['recognized_by']}"
%span.recognized_by= "Taxon recognized by #{result['recognized_by']}"
-# end results.each
= will_paginate(results)
- # /search_results
Expand Down
16 changes: 5 additions & 11 deletions lib/eol/search_results_collection.rb
Expand Up @@ -34,7 +34,7 @@ def initialize(results, options = {})
# time being, we always are. In the future, this will want to be abstracted out, so that we inherit all the common
# behaviour and add this behaviour if it's a TC-based search:
update_results_with_current_data
handle_apparent_duplicates
add_mini_tree_and_attribution
adapt_results_for_view
end

Expand Down Expand Up @@ -115,7 +115,7 @@ def get_current_data_from_taxon_concept_id(id, result)
return {'preferred_scientific_name' => (tc.scientific_name(@session_hierarchy) ||
result["preferred_scientific_name"] || ''),
'preferred_common_name' => (tc.common_name(@session_hierarchy) || result["preferred_common_name"] || ''),
# There are some "expensive" operations we only want to do on duplicates, so store the TC here:
# There are some "expensive" operations done later, so store tc here:
'taxon_concept' => tc }
# Really, we don't want to save these exceptions, since what good is a search result if the TC is missing?
# However, tests sometimes create situations where this is possible and not "wrong", (creating TCs is expensive!) so:
Expand Down Expand Up @@ -166,19 +166,15 @@ def repair_missing_match_fields(result)
result[@best_match_field_name] ||= ''
end

def handle_apparent_duplicates
def add_mini_tree_and_attribution
return nil unless @results
best_names = @results.map {|r| r[@best_match_field_name]}
@results.each do |result|
if best_names.find_all {|r| r == result[@best_match_field_name]}.length > 1
handle_duplicate(result) unless ENV['RAILS_ENV'] == 'production'
end
add_tree_and_arttribution_fields(result) unless ENV['RAILS_ENV'] == 'production'
end
end

private
def handle_duplicate(result)
result["duplicate"] = true
def add_tree_and_arttribution_fields(result)
tc = result["taxon_concept"]
if tc
result["recognized_by"] = result["taxon_concept"].entry.hierarchy.label
Expand All @@ -187,10 +183,8 @@ def handle_duplicate(result)
ancestor = ancestors[-3]
if parent and parent.class == TaxonConcept
result["parent_scientific"] = parent.scientific_name
result["parent_common"] = parent.common_name
if ancestor and ancestor.class == TaxonConcept
result["ancestor_scientific"] = ancestor.scientific_name
result["ancestor_common"] = ancestor.common_name
end
end
else
Expand Down
2 changes: 0 additions & 2 deletions spec/controllers/taxa_controller_spec.rb
Expand Up @@ -34,13 +34,11 @@ def hijack_search_for_tiger

it 'should show the parent taxon_concept of the duplicates' do
hijack_search_for_tiger
response.should have_tag('div.parent', :text => @parent_concept.common_name)
response.should have_tag('div.parent', :text => @parent_concept.scientific_name)
end

it 'should show the ancestor (grandparent) taxon_concept of the duplicates' do
hijack_search_for_tiger
response.should have_tag('div.ancestor', :text => @ancestor_concept.common_name)
response.should have_tag('div.ancestor', :text => @ancestor_concept.scientific_name)
end

Expand Down
7 changes: 0 additions & 7 deletions spec/lib/eol_search_results_collection_spec.rb
Expand Up @@ -40,11 +40,6 @@
@tc_result["preferred_common_name"].should == @new_common_name
end

it 'should mark duplicates' do
@tc_result["duplicate"].should be_true
@dup_tc_result["duplicate"].should be_true
end

it 'should show whom duplicate entries are recognized by' do
@tc_result["recognized_by"].should == @taxon_concept.entry.hierarchy.label
@dup_tc_result["recognized_by"].should == @duplicate_taxon_concept.entry.hierarchy.label
Expand All @@ -54,8 +49,6 @@
ancestors = @tc_result['taxon_concept'].ancestors
parent_concept = ancestors[-2]
ancestor_concept = ancestors[-3]
@tc_result["parent_common"].should == parent_concept.common_name
@tc_result["ancestor_common"].should == ancestor_concept.common_name
@tc_result["parent_scientific"].should == parent_concept.scientific_name
@tc_result["ancestor_scientific"].should == ancestor_concept.scientific_name
end
Expand Down

0 comments on commit aa3e152

Please sign in to comment.