unepwcmc/SAPI — pull request #306 by agnessa (2014-04-24 07:00:39+00:00)
Title: Subspecies search improvements

This addresses 2 issues with searching subspecies in S+:

1. subspecies which used to be explicitly listed in their own right should be visible, e.g. Falco peregrinus peregrinus (affects auto complete)
2. subspecies which were never listed in their own right should not be visible, e.g. Amazona festiva festiva (affects search results)

The first issue was addresses by adding a step to the cites listing calculation which sets a 'cites/eu/cms_historically_listed' flag on the listing hstore. For CITES / EU this gets set if there are any listing changes under that designation present. For CMS it also looks at instruments. This flag is later used to calculate the show_in_species_plus_ac flag. To fix the second issue without further slowing down the search a new flag was added that says 'show_in_species_plus'; it is calculated similarly to the _ac flag, however it only considers species + subspecies. The search query could be therefore simplified (ranks and name status filter removed).

Note that under CMS probably all subspecies should be visible according to the rules (e.g. Cervus elaphus bactrianus has no listing, but has an intrument and therefore shows) - there don't seem to be any subspecies with neither listing or instrument.

To enjoy fully:

rake db:migrate

select * from set_cites_historically_listed_flag_for_node(null);
select * from set_eu_historically_listed_flag_for_node(null);
select * from set_cms_historically_listed_flag_for_node(null);
select * from rebuild_taxon_concepts_mview();

rake tmp:cache:clear