use of com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList in project ArachneCentralAPI by OHDSI.
the class SearchResultToFacetedSearchResultDTOConverter method buildFacets.
protected Map<String, FacetOptionList> buildFacets(SearchResult source, FieldList solrFields) {
Map<String, List<String>> excludedOptions = source.getExcludedOptions();
NamedList response = source.getSolrResponse().getResponse();
Map facetsMap = (Map) response.asMap(10).get("facets");
Map<String, FacetOptionList> facets = new HashMap<>();
// Facets for option list and numeric type
List<FacetField> facetFieldList = source.getSolrResponse().getFacetFields();
if (facetFieldList != null) {
for (FacetField facetField : facetFieldList) {
FacetOptionList facetOptionList = getFacetOptionList(facetsMap, facetField.getName(), excludedOptions.get(facetField.getName()));
facets.put(solrFields.getBySolrName(facetField.getName()).getName(), facetOptionList);
}
}
return facets;
}
use of com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList in project ArachneCentralAPI by OHDSI.
the class SearchResultToFacetedSearchResultDTOConverter method getFacetOptionList.
@SuppressWarnings(value = "unchecked")
private FacetOptionList getFacetOptionList(Map facets, String facetName, List<String> excludedOptions) {
Map facetLabel = (Map) facets.get(getFacetLabel(facetName));
List<SimpleOrderedMap> buckets = (List<SimpleOrderedMap>) facetLabel.get("buckets");
FacetOptionList facetOptionList = new FacetOptionList();
boolean isNumberType = false;
for (SimpleOrderedMap each : buckets) {
Map entry = each.asMap(2);
if (!isNumberType && entry.get("val") instanceof Long) {
isNumberType = true;
}
final String val = entry.get("val").toString();
if (excludedOptions != null && excludedOptions.contains(val)) {
continue;
}
final Object count = entry.get("count");
facetOptionList.put(val, count);
}
if (isNumberType) {
Long min = parseLong(facetOptionList.entrySet().stream().min(comparing(o -> parseLong(o.getKey()))).get().getKey());
Long max = parseLong(facetOptionList.entrySet().stream().max(comparing(o -> parseLong(o.getKey()))).get().getKey());
facetOptionList.setMin(min);
facetOptionList.setMax(max);
}
return facetOptionList;
}
Aggregations