Search in sources :

Example 1 with FacetOptionList

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;
}
Also used : FacetOptionList(com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList) HashMap(java.util.HashMap) NamedList(org.apache.solr.common.util.NamedList) FacetField(org.apache.solr.client.solrj.response.FacetField) FieldList(com.odysseusinc.arachne.portal.service.impl.solr.FieldList) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) List(java.util.List) FacetOptionList(com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with FacetOptionList

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;
}
Also used : FacetOptionList(com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList) Long.parseLong(java.lang.Long.parseLong) FieldList(com.odysseusinc.arachne.portal.service.impl.solr.FieldList) NamedList(org.apache.solr.common.util.NamedList) ArrayList(java.util.ArrayList) List(java.util.List) FacetOptionList(com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) HashMap(java.util.HashMap) Map(java.util.Map) SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap)

Aggregations

FacetOptionList (com.odysseusinc.arachne.portal.api.v1.dto.FacetOptionList)2 FieldList (com.odysseusinc.arachne.portal.service.impl.solr.FieldList)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NamedList (org.apache.solr.common.util.NamedList)2 SimpleOrderedMap (org.apache.solr.common.util.SimpleOrderedMap)2 Long.parseLong (java.lang.Long.parseLong)1 FacetField (org.apache.solr.client.solrj.response.FacetField)1