taxon[i] = convertStars(taxon[i]);
}
LOGGER.debug("input " + i + " = '" + taxon[i] + "'");
}
TreeSearchResults oldRes;
{
SearchResults<?> sr = (TreeSearchResults) searchResults(request);
if (sr != null) {
oldRes = (TreeSearchResults) sr; // (TreeSearchResults) sr.convertToTrees();
} else {
oldRes = new TreeSearchResults (); // TODO: Convert existing search results to new type
}
}
LOGGER.info("doSearch old results contained " + oldRes.size() + " item(s)");
Collection<PhyloTree> newRes;
PhyloTreeService treeService = getSearchService().getPhyloTreeService();
TaxonVariant[] taxonVariant = new TaxonVariant[taxon.length];
List<String> resolutionError = new LinkedList<String> ();
for (int i=0; i<taxon.length; i++) {
if (taxon[i] == null) continue;
if (taxon[i].equals(""))
resolutionError.add("TaxonVariant name " + i + " missing");
Set<TaxonVariant> tvSet = getTaxonLabelService().findTaxonVariantByName(taxon[i]);
taxonVariant[i] = tvSet.isEmpty() ? null : tvSet.iterator().next(); // FIXME: This is not really the right behavior
if (taxonVariant[i] == null)
resolutionError.add("Couldn't resolve TaxonVariant '" + taxon[i] + "'");
else
LOGGER.debug("input '" + taxon[i] + "' resolved to TV " + taxonVariant[i].getId() + " ('" + taxonVariant[i].getFullName() + "')");
}
if (! resolutionError.isEmpty()) {
addMessages(request, resolutionError);
return new ModelAndView("search/treeTopSearch", Constants.RESULT_SET, oldRes);
}
switch (searchType) {
case topology3Search:
checkTaxa(taxonVariant, 3);
newRes = treeService.findByTopology3(taxonVariant[0], taxonVariant[1], taxonVariant[2]);
break;
case topology4aSearch:
checkTaxa(taxonVariant, 4);
newRes = treeService.findByTopology4a(taxonVariant[0], taxonVariant[1], taxonVariant[2], taxonVariant[3]);
break;
case topology4sSearch:
checkTaxa(taxonVariant, 4);
newRes = treeService.findByTopology4s(taxonVariant[0], taxonVariant[1], taxonVariant[2], taxonVariant[3]);
break;
default:
throw new Error ("Unknown search type '" + searchType + "'");
}
if (newRes != null) { LOGGER.info("doSearch '" + searchType + "' found " + newRes.size() + " result(s)"); }
if (newRes == null || newRes.isEmpty()) {
addMessage(request, "No matching trees found");
} else {
if (oldRes == null) {
oldRes = new TreeSearchResults(newRes);
} else { oldRes.intersect(newRes); }
}
saveSearchResults(request, oldRes);
LOGGER.info("doSearch '" + searchType + "' after intersection: " + oldRes.size() + " result(s)");
return new ModelAndView("search/treeTopSearch", Constants.RESULT_SET, oldRes);
}