Example usage for org.apache.solr.client.solrj SolrQuery addFacetPivotField

List of usage examples for org.apache.solr.client.solrj SolrQuery addFacetPivotField

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj SolrQuery addFacetPivotField.

Prototype

public SolrQuery addFacetPivotField(String... fields) 

Source Link

Document

Add field(s) for pivot computation.

Usage

From source file:com.frank.search.solr.core.DefaultQueryParser.java

License:Apache License

private void appendFacetingOnPivot(SolrQuery solrQuery, FacetQuery query) {
    if (VersionUtil.isSolr3XAvailable()) {
        throw new UnsupportedOperationException(
                "Pivot Facets are not available for solr version lower than 4.x - Please check your depdendencies.");
    }//from  w w  w. j  a  v  a2s .c  o  m

    FacetOptions facetOptions = query.getFacetOptions();
    String[] pivotFields = convertFieldListToStringArray(facetOptions.getFacetOnPivots());
    solrQuery.addFacetPivotField(pivotFields);
}

From source file:ddf.catalog.source.solr.SolrCatalogProvider.java

License:Open Source License

@Override
public Set<ContentType> getContentTypes() {

    Set<ContentType> finalSet = new HashSet<>();

    String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeFormat.STRING, true);
    String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeFormat.STRING,
            true);// w w w. ja v a2s.  c o  m

    /*
     * If we didn't find the field, it most likely means it does not exist. If it does not
     * exist, then we can safely say that no content types are in this catalog provider
     */
    if (contentTypeField == null || contentTypeVersionField == null) {
        return finalSet;
    }

    SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]");
    query.setFacet(true);
    query.addFacetField(contentTypeField);
    query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField);

    try {
        QueryResponse solrResponse = server.query(query, METHOD.POST);
        List<FacetField> facetFields = solrResponse.getFacetFields();
        for (Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) {

            // if no content types have an associated version, the list of pivot fields will be
            // empty.
            // however, the content type names can still be obtained via the facet fields.
            if (CollectionUtils.isEmpty(entry.getValue())) {
                LOGGER.debug("No content type versions found associated with any available content types.");

                if (CollectionUtils.isNotEmpty(facetFields)) {
                    // Only one facet field was added. That facet field may contain multiple
                    // values (content type names).
                    for (FacetField.Count currContentType : facetFields.get(0).getValues()) {
                        // unknown version, so setting it to null
                        ContentTypeImpl contentType = new ContentTypeImpl(currContentType.getName(), null);

                        finalSet.add(contentType);
                    }
                }
            } else {
                for (PivotField pf : entry.getValue()) {

                    String contentTypeName = pf.getValue().toString();
                    LOGGER.debug("contentTypeName:{}", contentTypeName);

                    if (CollectionUtils.isEmpty(pf.getPivot())) {
                        // if there are no sub-pivots, that means that there are no content type
                        // versions
                        // associated with this content type name
                        LOGGER.debug("Content type does not have associated contentTypeVersion: {}",
                                contentTypeName);
                        ContentTypeImpl contentType = new ContentTypeImpl(contentTypeName, null);

                        finalSet.add(contentType);

                    } else {
                        for (PivotField innerPf : pf.getPivot()) {

                            LOGGER.debug("contentTypeVersion:{}. For contentTypeName: {}", innerPf.getValue(),
                                    contentTypeName);

                            ContentTypeImpl contentType = new ContentTypeImpl(contentTypeName,
                                    innerPf.getValue().toString());

                            finalSet.add(contentType);
                        }
                    }
                }
            }
        }

    } catch (SolrServerException e) {
        LOGGER.info("SOLR server exception getting content types", e);
    }

    return finalSet;
}

From source file:ddf.catalog.source.solr.SolrMetacardClientImpl.java

License:Open Source License

@Override
public Set<ContentType> getContentTypes() {
    Set<ContentType> finalSet = new HashSet<>();

    String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeType.AttributeFormat.STRING,
            true);// ww  w . jav  a2s .  c o  m
    String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION,
            AttributeType.AttributeFormat.STRING, true);

    /*
     * If we didn't find the field, it most likely means it does not exist. If it does not
     * exist, then we can safely say that no content types are in this catalog provider
     */
    if (contentTypeField == null || contentTypeVersionField == null) {
        return finalSet;
    }

    SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]");
    query.setFacet(true);
    query.addFacetField(contentTypeField);
    query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField);

    try {
        QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST);
        List<FacetField> facetFields = solrResponse.getFacetFields();
        for (Map.Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) {

            // if no content types have an associated version, the list of pivot fields will be
            // empty.
            // however, the content type names can still be obtained via the facet fields.
            if (CollectionUtils.isEmpty(entry.getValue())) {
                LOGGER.debug("No content type versions found associated with any available content types.");

                if (CollectionUtils.isNotEmpty(facetFields)) {
                    // Only one facet field was added. That facet field may contain multiple
                    // values (content type names).
                    for (FacetField.Count currContentType : facetFields.get(0).getValues()) {
                        // unknown version, so setting it to null
                        ContentType contentType = new ContentTypeImpl(currContentType.getName(), null);

                        finalSet.add(contentType);
                    }
                }
            } else {
                for (PivotField pf : entry.getValue()) {

                    String contentTypeName = pf.getValue().toString();
                    LOGGER.debug("contentTypeName: {}", contentTypeName);

                    if (CollectionUtils.isEmpty(pf.getPivot())) {
                        // if there are no sub-pivots, that means that there are no content type
                        // versions
                        // associated with this content type name
                        LOGGER.debug("Content type does not have associated contentTypeVersion: {}",
                                contentTypeName);
                        ContentType contentType = new ContentTypeImpl(contentTypeName, null);

                        finalSet.add(contentType);

                    } else {
                        for (PivotField innerPf : pf.getPivot()) {

                            LOGGER.debug("contentTypeVersion: {}. For contentTypeName: {}", innerPf.getValue(),
                                    contentTypeName);

                            ContentType contentType = new ContentTypeImpl(contentTypeName,
                                    innerPf.getValue().toString());

                            finalSet.add(contentType);
                        }
                    }
                }
            }
        }

    } catch (SolrServerException | IOException e) {
        LOGGER.info("Solr exception getting content types", e);
    }

    return finalSet;
}

From source file:edu.vt.vbi.patric.common.DataApiHandler.java

License:Apache License

/**
 * wrapper function of pivot facet query
 *
 * @param core SolrCore/*w ww.j  ava 2s.c  om*/
 * @param queryParam query condition
 * @param filterParam filter condition
 * @param facetFields comma separated list of fields
 */

public Map getPivotFacets(SolrCore core, String queryParam, String filterParam, String facetFields)
        throws IOException {
    Map<String, Object> res = new HashMap<>();
    SolrQuery query = new SolrQuery();

    query.setQuery(queryParam);
    if (filterParam != null) {
        query.addFilterQuery(filterParam);
    }
    query.setRows(0).setFacet(true).setFacetLimit(-1).setFacetMinCount(1)
            .setFacetSort(FacetParams.FACET_SORT_INDEX);
    query.addFacetPivotField(facetFields);

    LOGGER.trace("getPivotFacets: [{}] {}", core.getSolrCoreName(), query.toString());
    String response = this.solrQuery(core, query);
    Map<String, Object> resp = jsonParser.readValue(response);
    Map facet_fields = (Map) ((Map) resp.get("facet_counts")).get("facet_pivot");
    List<Map> values = (List) facet_fields.get(facetFields);

    Map<String, Object> facet = new LinkedHashMap<>();

    for (Map value : values) {
        String localKey = value.get("value").toString();
        List<Map> localValues = (List) value.get("pivot");

        Map<String, Integer> pivotValues = new LinkedHashMap<>();
        for (Map local : localValues) {
            pivotValues.put(local.get("value").toString(), (Integer) local.get("count"));
        }
        facet.put(localKey, pivotValues);
    }

    res.put("total", ((Map) resp.get("response")).get("numFound"));
    res.put(facetFields, facet);

    return res;
}

From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java

License:Apache License

public QueryResponse getSolr4Docs(String solrServer, String solrCoreName, String uniqueKey, List<String> fields,
        Long solrDocFectCount, String cursorMark, StringBuilder filters, List<SolrAggrParam> solrAggrParams,
        List<SolrSortParam> solrSortParams, List<String> aggrFieldNames, boolean isGroup,
        boolean useFacetPivotFromGroupCount) {

    String solrUrl = solrServer;//from   ww  w .  j av a2s.  co  m
    if (solrCoreName != null) {
        solrUrl = solrServer + solrCoreName;
    }
    SolrClient solrClient = new HttpSolrClient(solrUrl);
    String fieldStr = null;
    String[] fieldListArr = null;
    List<String> statsFieldList = Lists.newArrayList();

    SolrQuery solrQuery = new SolrQuery().setTermsRegexFlag("case_insensitive").setQuery(uniqueKey + ":*")
            .setRows(0);

    if (filters.length() > 0) {
        solrQuery.setParam("fq", filters.toString());
        SolrClientAPIExec.logger.debug("Filter query [ " + filters.toString() + " ]");
    }

    if (!fields.isEmpty()) {
        fieldStr = Joiner.on(",").join(fields);
        solrQuery.setParam("fl", fieldStr);
        solrQuery.setRows(solrDocFectCount.intValue());
        SolrClientAPIExec.logger.debug("Response field list [" + fieldStr + "]");
    }
    // facet.pivot={!stats=s1}category,manufacturer
    // stats.field={!key=avg_price tag=s1 mean=true}price
    // stats.field={!tag=s1 min=true max=true}user_rating

    if (solrAggrParams != null && !solrAggrParams.isEmpty() && !useFacetPivotFromGroupCount) {
        solrQuery.setGetFieldStatistics(true);
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String statsField = solrAggrParam.getFieldName();
            if (!fields.contains(statsField)) {
                statsField = uniqueKey;
            }
            if (!statsFieldList.contains(statsField)) {
                statsFieldList.add(statsField);
            }
            fields.remove(statsField);
        }
        if (!fields.isEmpty()) {
            fieldListArr = fields.toArray(new String[fields.size()]);
        }

        for (String statsField : statsFieldList) {
            solrQuery.setGetFieldStatistics(statsField);
            SolrClientAPIExec.logger.debug("Adding stats field parameter.. [ " + statsField + " ]");
            if (isGroup) {
                List<String> groupFields = Lists.newArrayList();
                for (String aggrField : aggrFieldNames) {
                    if (fields.contains(aggrField)) {
                        groupFields.add(aggrField);
                    }
                }
                SolrClientAPIExec.logger.debug("Adding stats facet parameters.. [ " + groupFields + " ]");
                solrQuery.addStatsFieldFacets(statsField, groupFields.toArray(new String[groupFields.size()]));
            }

        }
        solrQuery.setRows(0);
    } else if (isGroup) {
        fieldListArr = fields.toArray(new String[fields.size()]);
        solrQuery.setFacet(true);
        if (fields.size() == 1) {
            solrQuery.addFacetField(fieldListArr);
            solrQuery.setFacetLimit(-1);
        } else {
            solrQuery.addFacetPivotField(Joiner.on(",").join(fields));
        }
        solrQuery.setRows(0);
        solrQuery.setFacetMinCount(1);

        // solrQuery.set(GroupParams.GROUP, true);
        // solrQuery.set(GroupParams.GROUP_FIELD, fieldListArr);
        // solrQuery.set(GroupParams.GROUP_MAIN, true);
        // solrQuery.set(GroupParams.GROUP_FORMAT, "simple");
        // solrQuery.set("group.ngroups", "true");
    }
    if (!solrSortParams.isEmpty()) {
        for (SolrSortParam solrSortParam : solrSortParams) {
            String solrSortField = solrSortParam.getSortFieldName();
            ORDER solrSortDir = solrSortParam.getSortDir();
            solrQuery.addSort(solrSortField, solrSortDir);

        }
    } else {
        solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
        solrQuery.setSort(SolrQuery.SortClause.desc(uniqueKey));
    }
    QueryResponse rsp = null;
    try {
        SolrClientAPIExec.logger
                .info("Submitting Query :" + solrServer + "/select" + solrQuery.toQueryString());

        rsp = solrClient.query(solrQuery);

        SolrClientAPIExec.logger.info("Response recieved from [ " + solrServer + " ] core [ " + solrCoreName
                + " ] in " + rsp.getQTime() + " MS.");

    } catch (SolrServerException | IOException e) {
        SolrClientAPIExec.logger
                .debug("Error occured while fetching results from solr server " + e.getMessage());
    } finally {
        try {
            solrClient.close();
        } catch (IOException e) {
            SolrClientAPIExec.logger
                    .debug("Error occured while closing connection of solr server " + e.getMessage());
        }
    }

    return rsp;
}

From source file:org.apache.drill.exec.store.solr.SolrClientAPIExec.java

License:Apache License

public QueryResponse getSolrDocs(String solrServer, String solrCoreName, String uniqueKey, List<String> fields,
        Long solrDocFectCount, String cursorMark, StringBuilder filters, List<SolrAggrParam> solrAggrParams,
        List<SolrSortParam> solrSortParams, List<String> aggrFieldNames, boolean isGroup,
        boolean isCountOnlyQuery) {

    String solrUrl = solrServer;/* w w  w .  j  ava  2s .c  o  m*/
    if (solrCoreName != null) {
        solrUrl = solrServer + solrCoreName;
    }
    SolrClient solrClient = new HttpSolrClient(solrUrl);

    String fieldStr = null;
    String[] fieldListArr = null;
    List<String> statsFieldList = Lists.newArrayList();

    SolrQuery solrQuery = new SolrQuery().setQuery("{!cache=false}" + uniqueKey + ":*").setRows(0);

    if (filters.length() > 0) {
        solrQuery.setParam("fq", filters.toString());
        SolrClientAPIExec.logger.debug("Filter query [ " + filters.toString() + " ]");
    }

    if (!fields.isEmpty()) {
        fieldStr = Joiner.on(",").join(fields);
        solrQuery.setParam("fl", fieldStr);
        solrQuery.setRows(solrDocFectCount.intValue());
        SolrClientAPIExec.logger.debug("Response field list [" + fieldStr + "]");
    }
    if (solrAggrParams != null && !solrAggrParams.isEmpty() && !isCountOnlyQuery) {
        solrQuery.setGetFieldStatistics(true);
        String referenceToStatsTag = "{!stats=t1}";
        String statsTag = "{!tag=t1}";
        for (SolrAggrParam solrAggrParam : solrAggrParams) {
            String statsField = solrAggrParam.getFieldName();
            if (!fields.contains(statsField)) {
                statsField = uniqueKey;
            }
            if (!statsFieldList.contains(statsField)) {
                statsFieldList.add(statsField);
            }
            fields.remove(statsField);
        }
        if (!fields.isEmpty()) {
            fieldListArr = fields.toArray(new String[fields.size()]);
        }
        SolrClientAPIExec.logger.debug("Adding stats field parameter.." + statsFieldList + "");

        if (isGroup) {
            List<String> groupFields = Lists.newArrayList();
            solrQuery.addGetFieldStatistics(statsTag + Joiner.on(",").join(statsFieldList));
            for (String aggrField : fields) {
                if (fields.contains(aggrField)) {
                    groupFields.add(aggrField);
                }
            }
            if (groupFields.size() == 1) {
                SolrClientAPIExec.logger.debug("Adding stats facet parameters.." + groupFields + "");
                for (String statsField : statsFieldList) {
                    solrQuery.addStatsFieldFacets(statsField,
                            groupFields.toArray(new String[groupFields.size()]));
                }
            } else {
                SolrClientAPIExec.logger.debug("Adding facet pivot parameters.." + groupFields + "");
                solrQuery.addFacetPivotField(referenceToStatsTag + Joiner.on(",").join(groupFields));
                solrQuery.setFacetLimit(-1);
            }
        } else {
            for (String statsField : statsFieldList) {
                solrQuery.setGetFieldStatistics(statsField);
            }
        }
        solrQuery.setRows(0);
    } else if (isGroup) {
        fieldListArr = fields.toArray(new String[fields.size()]);
        solrQuery.setFacet(true);
        if (fields.size() == 1) {
            solrQuery.addFacetField(fieldListArr);
            solrQuery.setFacetLimit(-1);
        } else {
            solrQuery.addFacetPivotField(Joiner.on(",").join(fields));
        }
        solrQuery.setRows(0);
        solrQuery.setFacetMinCount(1);
        solrQuery.setFacetLimit(-1);
    } else {
        solrQuery.set(CursorMarkParams.CURSOR_MARK_PARAM, cursorMark);
        solrQuery.addSort(SolrQuery.SortClause.desc(uniqueKey));

    }
    if (!solrSortParams.isEmpty()) {
        for (SolrSortParam solrSortParam : solrSortParams) {
            String solrSortField = solrSortParam.getSortFieldName();
            ORDER solrSortDir = solrSortParam.getSortDir();
            solrQuery.addSort(solrSortField, solrSortDir);

        }
    }

    QueryResponse rsp = null;
    try {
        SolrClientAPIExec.logger.info("Submitting Query :" + solrUrl + "/select" + solrQuery.toQueryString());

        rsp = solrClient.query(solrQuery);

        SolrClientAPIExec.logger.info("Response recieved from [ " + solrServer + " ] core [ " + solrCoreName
                + " ] in " + rsp.getQTime() + " MS.");

    } catch (SolrServerException | IOException e) {
        SolrClientAPIExec.logger
                .debug("Error occured while fetching results from solr server " + e.getMessage());
    } finally {
        try {
            solrClient.close();
        } catch (IOException e) {
            SolrClientAPIExec.logger
                    .debug("Error occured while closing connection of solr server " + e.getMessage());
        }
    }

    return rsp;
}

From source file:org.emonocot.persistence.dao.hibernate.SearchableDaoImpl.java

License:Open Source License

public CellSet analyse(String rows, String cols, Integer firstCol, Integer maxCols, Integer firstRow,
        Integer maxRows, Map<String, String> selectedFacets, String[] facets, Cube cube)
        throws SolrServerException {
    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    SolrQuery totalQuery = new SolrQuery();
    totalQuery.setQuery("*:*");

    // We're not interested in the results themselves
    query.setRows(1);/*from w ww. ja v  a 2 s .  co  m*/
    query.setStart(0);
    totalQuery.setRows(1);
    totalQuery.setStart(0);

    if (rows == null) {
        query.setFacet(true);
        query.setFacetMinCount(1);
        query.setFacetSort(FacetParams.FACET_SORT_INDEX);
        query.addFacetField(cube.getDefaultLevel());
        includeMissing(query, cube.getDefaultLevel());
        includeMissing(totalQuery, cube.getDefaultLevel());
        if (maxRows != null) {
            totalQuery.setFacet(true);
            totalQuery.setFacetMinCount(1);
            totalQuery.addFacetField("{!key=totalRows}" + cube.getDefaultLevel());

            query.add("f." + cube.getDefaultLevel() + ".facet.limit", maxRows.toString());
            query.add("f." + cube.getDefaultLevel() + ".facet.mincount", "1");
            if (firstRow != null) {
                query.add("f." + cube.getDefaultLevel() + ".facet.offset", firstRow.toString());
            }
        }
    } else if (cols == null) {
        query.setFacet(true);
        query.setFacetMinCount(1);
        query.setFacetSort(FacetParams.FACET_SORT_INDEX);
        query.addFacetField(rows);
        includeMissing(query, rows);
        includeMissing(totalQuery, rows);
        if (maxRows != null) {
            totalQuery.setFacet(true);
            totalQuery.setFacetMinCount(1);
            totalQuery.addFacetField("{!key=totalRows}" + rows);
            query.add("f." + rows + ".facet.limit", maxRows.toString());
            query.add("f." + rows + ".facet.mincount", "1");
            if (firstRow != null) {
                query.add("f." + rows + ".facet.offset", firstRow.toString());
            }
        }
        if (cube.getLevel(rows).isMultiValued() && cube.getLevel(rows).getHigher() != null) {
            Level higher = cube.getLevel(rows).getHigher();
            totalQuery.add("f." + rows + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
            query.add("f." + rows + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
        }
    } else {
        query.setFacet(true);
        query.setFacetMinCount(1);
        query.setFacetSort(FacetParams.FACET_SORT_INDEX);
        query.addFacetField(rows);
        includeMissing(query, rows);
        includeMissing(totalQuery, rows);
        if (maxRows != null) {
            totalQuery.setFacet(true);
            totalQuery.setFacetMinCount(1);
            totalQuery.addFacetField("{!key=totalRows}" + rows);
            query.add("f." + rows + ".facet.limit", maxRows.toString());
            query.add("f." + rows + ".facet.mincount", "1");
            if (firstRow != null) {
                query.add("f." + rows + ".facet.offset", firstRow.toString());
            }
        }
        if (cube.getLevel(rows).isMultiValued() && cube.getLevel(rows).getHigher() != null) {
            Level higher = cube.getLevel(rows).getHigher();
            totalQuery.add("f." + rows + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
            query.add("f." + rows + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
        }
        query.addFacetField(cols);
        includeMissing(query, cols);
        if (maxCols != null) {
            totalQuery.setFacet(true);
            totalQuery.setFacetMinCount(1);
            totalQuery.addFacetField("{!key=totalCols}" + cols);
            /**
             * Facet pivot does not behave the same way on columns - the limit is
             */
            //query.add("f." + cols + ".facet.limit", maxCols.toString());
            //query.add("f." + cols + ".facet.mincount", "1");
            //if (firstCol != null) {
            //   query.add("f." + cols + ".facet.offset", firstCol.toString());
            //}
        }
        if (cube.getLevel(cols).isMultiValued() && cube.getLevel(cols).getHigher() != null) {
            Level higher = cube.getLevel(cols).getHigher();
            totalQuery.add("f." + cols + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
            query.add("f." + cols + ".facet.prefix", selectedFacets.get(higher.getFacet()) + "_");
        }
        query.addFacetPivotField(rows + "," + cols);
    }

    if (selectedFacets != null && !selectedFacets.isEmpty()) {
        for (String facetName : selectedFacets.keySet()) {
            String facetValue = selectedFacets.get(facetName);
            if (StringUtils.isNotEmpty(facetValue)) {
                totalQuery.addFilterQuery(facetName + ":" + selectedFacets.get(facetName));
                query.addFilterQuery(facetName + ":" + selectedFacets.get(facetName));
            } else {//Subtract/Exclude documents with any value for the facet
                totalQuery.addFilterQuery("-" + facetName + ":[* TO *]");
                query.addFilterQuery("-" + facetName + ":[* TO *]");
            }
        }
    }

    if (facets != null && facets.length != 0) {
        query.setFacet(true);
        query.setFacetMinCount(1);
        query.setFacetSort(FacetParams.FACET_SORT_INDEX);

        for (String facetName : facets) {
            if (rows != null && rows.equals(facetName)) {
            } else if (cols != null && cols.equals(facetName)) {
            } else if (rows == null && facetName.equals(cube.getDefaultLevel())) {
            } else {
                includeMissing(query, facetName);
                query.addFacetField(facetName);
            }
        }
    }

    QueryResponse response = solrServer.query(query);
    QueryResponse totalResponse = solrServer.query(totalQuery);
    FacetField totalRows = null;
    FacetField totalCols = null;
    if (totalResponse.getFacetField("totalRows") != null) {
        totalRows = totalResponse.getFacetField("totalRows");
    }

    if (totalResponse.getFacetField("totalCols") != null) {
        totalCols = totalResponse.getFacetField("totalCols");
    }

    CellSet cellSet = new CellSet(response, selectedFacets, query, rows, cols, firstRow, maxRows, firstCol,
            maxCols, totalRows, totalCols, cube);

    return cellSet;
}

From source file:org.mousephenotype.cda.solr.service.ObservationService.java

License:Apache License

public Map<String, Set<String>> getColoniesByPhenotypingCenter(List<String> resourceName, ZygosityType zygosity)
        throws SolrServerException, IOException, InterruptedException {

    Map<String, Set<String>> res = new HashMap<>();
    SolrQuery q = new SolrQuery();
    String pivotFacet = ObservationDTO.PHENOTYPING_CENTER + "," + ObservationDTO.COLONY_ID;
    NamedList<List<PivotField>> response;

    if (resourceName != null) {
        q.setQuery(ObservationDTO.DATASOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":"));
    } else {/*w w  w  .  j  a v  a  2  s . c  om*/
        q.setQuery("*:*");
    }

    if (zygosity != null) {
        q.addFilterQuery(ObservationDTO.ZYGOSITY + ":" + zygosity.name());
    }

    q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental");
    q.addFacetPivotField(pivotFacet);
    q.setFacet(true);
    q.setFacetLimit(-1);
    q.setFacetMinCount(1);
    q.setRows(0);

    try {
        response = experimentCore.query(q).getFacetPivot();
        for (PivotField genePivot : response.get(pivotFacet)) {
            if (genePivot.getPivot() != null) {
                String center = genePivot.getValue().toString();
                HashSet<String> colonies = new HashSet<>();
                for (PivotField f : genePivot.getPivot()) {
                    colonies.add(f.getValue().toString());
                }
                res.put(center, colonies);
            }
        }
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }
    return res;
}

From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java

License:Apache License

public Map<String, Set<String>> getAccessionProceduresMap(String resourceName) {

    SolrQuery query = new SolrQuery();
    Map<String, Set<String>> res = new HashMap<>();
    NamedList<List<PivotField>> response;

    if (resourceName == null) {
        query.setQuery("*:*");
    } else {/* w  w  w .j ava2 s  .c o  m*/
        query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName);
    }
    query.setFacet(true);
    query.addFacetPivotField(
            StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);
    query.setRows(0);

    try {
        response = statisticalResultCore.query(query).getFacetPivot();
        for (PivotField genePivot : response.get(
                StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID)) {
            if (genePivot.getPivot() != null) {
                String geneName = genePivot.getValue().toString();
                Set<String> procedures = new HashSet<>();
                for (PivotField f : genePivot.getPivot()) {
                    procedures.add(f.getValue().toString());
                }
                res.put(geneName, procedures);
            }
        }
    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }
    return res;
}

From source file:uk.ac.ebi.phenotype.service.ObservationService.java

License:Apache License

public Map<String, Set<String>> getColoniesByPhenotypingCenter(ArrayList<String> resourceName,
        ZygosityType zygosity) throws SolrServerException, InterruptedException {

    Map<String, Set<String>> res = new HashMap<>();
    SolrQuery q = new SolrQuery();
    String pivotFacet = ObservationDTO.PHENOTYPING_CENTER + "," + ObservationDTO.COLONY_ID;
    NamedList<List<PivotField>> response;

    if (resourceName != null) {
        q.setQuery(ObservationDTO.DATASOURCE_NAME + ":"
                + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":"));
    } else {/* w  w  w .  j a  va2  s.c  om*/
        q.setQuery("*:*");
    }

    if (zygosity != null) {
        q.addFilterQuery(ObservationDTO.ZYGOSITY + ":" + zygosity.name());
    }

    q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental");
    q.addFacetPivotField(pivotFacet);
    q.setFacet(true);
    q.setFacetLimit(-1);
    q.setFacetMinCount(1);
    q.setRows(0);

    try {
        response = solr.query(q).getFacetPivot();
        for (PivotField genePivot : response.get(pivotFacet)) {
            String center = genePivot.getValue().toString();
            HashSet<String> colonies = new HashSet<>();
            for (PivotField f : genePivot.getPivot()) {
                colonies.add(f.getValue().toString());
            }
            res.put(center, colonies);
        }
    } catch (SolrServerException e) {
        e.printStackTrace();
    }
    return res;
}