Commit 711a7e56 authored by Matija Obreza's avatar Matija Obreza

termStatisticsAuto

Layout for filter-block
parent 33e8a08b
......@@ -43,4 +43,6 @@ public interface ElasticService {
TermResult termStatistics(AppliedFilters appliedFilters, String term, int size) throws SearchException;
TermResult termStatisticsAuto(AppliedFilters appliedFilters, String term, int size) throws SearchException;
}
......@@ -110,7 +110,6 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
throw new SearchException(e.getMessage(), e);
}
}
@Override
public TermResult termStatistics(AppliedFilters appliedFilters, String term, int size) throws SearchException {
......@@ -123,12 +122,35 @@ public class ElasticsearchSearchServiceImpl implements ElasticService, Initializ
try {
FacetedPage<AccessionDetails> page = elasticsearchTemplate.queryForPage(searchQuery, AccessionDetails.class);
return (TermResult) page.getFacet("f");
} catch (Throwable e) {
throw new SearchException(e.getMessage(), e);
}
}
/**
* Runs TermFacet, but will automatically increase size if #otherCount is
* more than 10%
*/
@Override
public TermResult termStatisticsAuto(AppliedFilters appliedFilters, String term, int size) throws SearchException {
TermResult termResult = null;
int newSize = size;
do {
termResult = termStatistics(appliedFilters, term, newSize);
// Avoid div/0
if (termResult.getTotalCount() == 0)
break;
double otherPerc = (double) termResult.getOtherCount() / (termResult.getMissingCount() + termResult.getTotalCount());
if (otherPerc < 0.1)
break;
newSize += size + Math.max(1, (size / 3));
} while (newSize < 2 * size);
return termResult;
}
private AndFilterBuilder getFilterBuilder(AppliedFilters appliedFilters) {
AndFilterBuilder filterBuilder = FilterBuilders.andFilter();
for (AppliedFilter appliedFilter : appliedFilters) {
......
......@@ -465,30 +465,30 @@ public class ExplorerController extends BaseController {
}
private void overviewInstitutes(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsInstCode", elasticService.termStatistics(appliedFilters, FilterConstants.INSTCODE, 10));
model.addAttribute("statsInstCountry", elasticService.termStatistics(appliedFilters, FilterConstants.INSTITUTE_COUNTRY_ISO3, 10));
model.addAttribute("statsInstCode", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.INSTCODE, 10));
model.addAttribute("statsInstCountry", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.INSTITUTE_COUNTRY_ISO3, 10));
}
private void overviewSources(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsOrgCty", elasticService.termStatistics(appliedFilters, FilterConstants.ORGCTY_ISO3, 10));
model.addAttribute("statsDonorCode", elasticService.termStatistics(appliedFilters, FilterConstants.DONORCODE, 10));
model.addAttribute("statsOrgCty", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.ORGCTY_ISO3, 10));
model.addAttribute("statsDonorCode", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.DONORCODE, 10));
}
private void overviewAvailability(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsMLS", elasticService.termStatistics(appliedFilters, FilterConstants.MLSSTATUS, 2));
model.addAttribute("statsAvailable", elasticService.termStatistics(appliedFilters, FilterConstants.AVAILABLE, 2));
model.addAttribute("statsMLS", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.MLSSTATUS, 2));
model.addAttribute("statsAvailable", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.AVAILABLE, 2));
}
private void overviewManagement(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsStorage", elasticService.termStatistics(appliedFilters, FilterConstants.STORAGE, 10));
model.addAttribute("statsDuplSite", elasticService.termStatistics(appliedFilters, FilterConstants.DUPLSITE, 10));
model.addAttribute("statsStorage", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.STORAGE, 30));
model.addAttribute("statsDuplSite", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.DUPLSITE, 10));
}
private void overviewComposition(ModelMap model, AppliedFilters appliedFilters) throws SearchException {
model.addAttribute("statsGenus", elasticService.termStatistics(appliedFilters, FilterConstants.TAXONOMY_GENUS, 10));
model.addAttribute("statsSpecies", elasticService.termStatistics(appliedFilters, FilterConstants.TAXONOMY_SPECIES, 10));
model.addAttribute("statsCrops", elasticService.termStatistics(appliedFilters, FilterConstants.CROPS, 10));
model.addAttribute("statsSampStat", elasticService.termStatistics(appliedFilters, FilterConstants.SAMPSTAT, 10));
model.addAttribute("statsGenus", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.TAXONOMY_GENUS, 10));
model.addAttribute("statsSpecies", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.TAXONOMY_SPECIES, 10));
model.addAttribute("statsCrops", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.CROPS, 30));
model.addAttribute("statsSampStat", elasticService.termStatisticsAuto(appliedFilters, FilterConstants.SAMPSTAT, 30));
}
}
......@@ -1158,7 +1158,7 @@ html[dir="rtl"] #stats .stat-lists ol li img {
text-transform:uppercase;
}
.applied-filters {
#allfilters.applied-filters {
border-top:1px solid #c9c9c7;
border-bottom:1px solid #c9c9c7;
color:#6f6e69;
......@@ -1166,6 +1166,10 @@ html[dir="rtl"] #stats .stat-lists ol li img {
margin: 10px 0;
}
#allfilters.applied-filters.disabled {
padding:2px 0;
}
.filtval {
background:#e6e0c6 url('../images/icon_remove_from_list.png') no-repeat top right;
cursor:pointer;
......@@ -1176,6 +1180,7 @@ html[dir="rtl"] #stats .stat-lists ol li img {
#allfilters.disabled .filter-block {
padding:2px 5px;
margin: 2px 0;
}
#allfilters.disabled .filter-block .filtval {
......@@ -1341,8 +1346,8 @@ table.crop-details h4 {
#allfilters .filter-block {
background:#f8f7f5;
margin:5px 0 0 0;
padding:10px;
margin:5px 0;
padding:6px 10px;
}
#allfilters .filter-block .filter-new, #allfilters .filter-block .filter-apply-btn {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment