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

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

Introduction

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

Prototype

public ModifiableSolrParams set(String name, String... val) 

Source Link

Document

Replace any existing parameter with the given name.

Usage

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

License:Apache License

public PhenotypeFacetResult getMPCallByMPAccessionAndFilter(String phenotype_id, List<String> procedureName,
        List<String> markerSymbol, List<String> mpTermName, Map<String, Synonym> synonyms)
        throws IOException, URISyntaxException, JSONException {

    String url = SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select/?";
    SolrQuery q = new SolrQuery();

    q.setQuery("*:*");
    q.addFilterQuery("(" + GenotypePhenotypeDTO.MP_TERM_ID + ":\"" + phenotype_id + "\" OR "
            + GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + phenotype_id + "\" OR "
            + GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + phenotype_id + "\")");
    q.setRows(10000000);//from w w w  .j  a  v  a  2s .com
    q.setFacet(true);
    q.setFacetMinCount(1);
    q.setFacetLimit(-1);
    q.addFacetField(GenotypePhenotypeDTO.PROCEDURE_NAME);
    q.addFacetField(GenotypePhenotypeDTO.MARKER_SYMBOL);
    q.addFacetField(GenotypePhenotypeDTO.MP_TERM_NAME);
    q.set("wt", "json");
    q.setSort(GenotypePhenotypeDTO.P_VALUE, ORDER.asc);

    q.setFields(GenotypePhenotypeDTO.MP_TERM_NAME, GenotypePhenotypeDTO.MP_TERM_ID,
            GenotypePhenotypeDTO.MPATH_TERM_NAME, GenotypePhenotypeDTO.MPATH_TERM_ID,
            GenotypePhenotypeDTO.EXTERNAL_ID, GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID,
            GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME, GenotypePhenotypeDTO.ALLELE_SYMBOL,
            GenotypePhenotypeDTO.PHENOTYPING_CENTER, GenotypePhenotypeDTO.ALLELE_ACCESSION_ID,
            GenotypePhenotypeDTO.MARKER_SYMBOL, GenotypePhenotypeDTO.MARKER_ACCESSION_ID,
            GenotypePhenotypeDTO.PHENOTYPING_CENTER, GenotypePhenotypeDTO.ZYGOSITY, GenotypePhenotypeDTO.SEX,
            GenotypePhenotypeDTO.LIFE_STAGE_NAME, GenotypePhenotypeDTO.RESOURCE_NAME,
            GenotypePhenotypeDTO.PARAMETER_STABLE_ID, GenotypePhenotypeDTO.PARAMETER_NAME,
            GenotypePhenotypeDTO.PIPELINE_STABLE_ID, GenotypePhenotypeDTO.PROJECT_NAME,
            GenotypePhenotypeDTO.PROJECT_EXTERNAL_ID, GenotypePhenotypeDTO.P_VALUE,
            GenotypePhenotypeDTO.EFFECT_SIZE, GenotypePhenotypeDTO.PROCEDURE_STABLE_ID,
            GenotypePhenotypeDTO.PROCEDURE_NAME, GenotypePhenotypeDTO.PIPELINE_NAME);

    if (procedureName != null) {
        q.addFilterQuery(GenotypePhenotypeDTO.PROCEDURE_NAME + ":(\""
                + StringUtils.join(procedureName, "\" OR \"") + "\")");
    }
    if (markerSymbol != null) {
        q.addFilterQuery(GenotypePhenotypeDTO.MARKER_SYMBOL + ":(\""
                + StringUtils.join(markerSymbol, "\" OR \"") + "\")");
    }
    if (mpTermName != null) {
        q.addFilterQuery(
                GenotypePhenotypeDTO.MP_TERM_NAME + ":(\"" + StringUtils.join(mpTermName, "\" OR \"") + "\")");
    }

    url += q;

    return createPhenotypeResultFromSolrResponse(url, synonyms);

}

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

License:Apache License

/**
 * Get a list of gene symbols for this phenotype
 * @param phenotype_id/*from www  . ja  v a  2 s. c om*/
 * @return
 * @throws IOException
 * @throws URISyntaxException
 * @throws SolrServerException
 */
public List<String> getGenesForMpId(String phenotype_id)
        throws IOException, URISyntaxException, SolrServerException {
    List<String> results = new ArrayList<>();
    String url = SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select/?";
    SolrQuery q = new SolrQuery();

    q.setQuery("*:*");
    q.addFilterQuery("(" + GenotypePhenotypeDTO.MP_TERM_ID + ":\"" + phenotype_id + "\" OR "
            + GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + phenotype_id + "\" OR "
            + GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + phenotype_id + "\")");
    q.setRows(10000000);
    q.setFacet(true);
    q.setFacetMinCount(1);
    q.setFacetLimit(-1);
    //q.addFacetField(GenotypePhenotypeDTO.MARKER_ACCESSION_ID);
    q.addFacetField(GenotypePhenotypeDTO.MARKER_SYMBOL);
    // q.addFacetField(GenotypePhenotypeDTO.MP_TERM_NAME );
    q.set("wt", "json");
    q.setSort(GenotypePhenotypeDTO.P_VALUE, ORDER.asc);
    q.setFields(GenotypePhenotypeDTO.MARKER_SYMBOL);
    //               q.setFields(GenotypePhenotypeDTO.MP_TERM_NAME, GenotypePhenotypeDTO.MP_TERM_ID, GenotypePhenotypeDTO.MPATH_TERM_NAME, GenotypePhenotypeDTO.MPATH_TERM_ID, GenotypePhenotypeDTO.EXTERNAL_ID,
    //                     GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID, GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME, GenotypePhenotypeDTO.ALLELE_SYMBOL, 
    //                     GenotypePhenotypeDTO.PHENOTYPING_CENTER, GenotypePhenotypeDTO.ALLELE_ACCESSION_ID, GenotypePhenotypeDTO.MARKER_SYMBOL,
    //                     GenotypePhenotypeDTO.MARKER_ACCESSION_ID, GenotypePhenotypeDTO.PHENOTYPING_CENTER, GenotypePhenotypeDTO.ZYGOSITY, 
    //                     GenotypePhenotypeDTO.SEX, GenotypePhenotypeDTO.LIFE_STAGE_NAME, GenotypePhenotypeDTO.RESOURCE_NAME, GenotypePhenotypeDTO.PARAMETER_STABLE_ID, GenotypePhenotypeDTO.PARAMETER_NAME,
    //                     GenotypePhenotypeDTO.PIPELINE_STABLE_ID, GenotypePhenotypeDTO.PROJECT_NAME, GenotypePhenotypeDTO.PROJECT_EXTERNAL_ID,
    //                     GenotypePhenotypeDTO.P_VALUE, GenotypePhenotypeDTO.EFFECT_SIZE, GenotypePhenotypeDTO.PROCEDURE_STABLE_ID,
    //                     GenotypePhenotypeDTO.PROCEDURE_NAME, GenotypePhenotypeDTO.PIPELINE_NAME);

    QueryResponse response = genotypePhenotypeCore.query(q);
    for (Count facet : response.getFacetField(GenotypePhenotypeDTO.MARKER_SYMBOL).getValues()) {
        //System.out.println("facet="+facet.getName());
        results.add(facet.getName());
    }
    return results;
}

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

License:Apache License

public SolrQuery buildQuery(String geneAccession, List<String> procedureName, List<String> alleleSymbol,
        List<String> phenotypingCenter, List<String> pipelineName, List<String> procedureStableIds,
        List<String> resource, List<String> mpTermId, Integer rows, List<String> sex, List<String> zygosities,
        String strain, String parameterStableId, String pipelineStableId, String metadataGroup,
        String alleleAccessionId) {

    SolrQuery query = new SolrQuery();

    query.setQuery("*:*");
    query.setRows(rows != null ? rows : Integer.MAX_VALUE);
    query.set("sort", StatisticalResultDTO.P_VALUE + " asc");
    query.set("wt", "xml");

    if (geneAccession != null) {
        query.addFilterQuery(StatisticalResultDTO.MARKER_ACCESSION_ID + ":\"" + geneAccession + "\"");
    }//from w  ww  .  jav a  2 s.c  om
    if (phenotypingCenter != null) {
        query.addFilterQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":(\""
                + StringUtils.join(phenotypingCenter, "\" OR \"") + "\")");
    }
    if (mpTermId != null) {
        query.addFilterQuery(StatisticalResultDTO.MP_TERM_ID + ":(\"" + StringUtils.join(mpTermId, "\" OR \"")
                + "\") OR " + StatisticalResultDTO.TOP_LEVEL_MP_TERM_ID + ":(\""
                + StringUtils.join(mpTermId, "\" OR \"") + "\") OR " + StatisticalResultDTO.MP_TERM_ID_OPTIONS
                + ":(\"" + StringUtils.join(mpTermId, "\" OR \"") + "\") OR "
                + StatisticalResultDTO.INTERMEDIATE_MP_TERM_ID + ":(\"" + StringUtils.join(mpTermId, "\" OR \"")
                + "\") OR " + StatisticalResultDTO.FEMALE_TOP_LEVEL_MP_TERM_ID + ":(\""
                + StringUtils.join(mpTermId, "\" OR \"") + "\") OR " + StatisticalResultDTO.FEMALE_MP_TERM_ID
                + ":(\"" + StringUtils.join(mpTermId, "\" OR \"") + "\") OR "
                + StatisticalResultDTO.FEMALE_INTERMEDIATE_MP_TERM_ID + ":(\""
                + StringUtils.join(mpTermId, "\" OR \"") + "\") OR "
                + StatisticalResultDTO.MALE_TOP_LEVEL_MP_TERM_ID + ":(\""
                + StringUtils.join(mpTermId, "\" OR \"") + "\") OR "
                + StatisticalResultDTO.MALE_INTERMEDIATE_MP_TERM_ID + ":(\""
                + StringUtils.join(mpTermId, "\" OR \"") + "\") OR " + StatisticalResultDTO.MALE_MP_TERM_ID
                + ":(\"" + StringUtils.join(mpTermId, "\" OR \"") + "\")");
    }
    if (pipelineName != null) {
        query.addFilterQuery(StatisticalResultDTO.PIPELINE_NAME + ":(\""
                + StringUtils.join(pipelineName, "\" OR \"") + "\")");
    }
    if (metadataGroup != null) {
        query.addFilterQuery(StatisticalResultDTO.METADATA_GROUP + ":" + metadataGroup);
    }
    if (alleleAccessionId != null) {
        query.addFilterQuery(StatisticalResultDTO.ALLELE_ACCESSION_ID + ":\"" + alleleAccessionId + "\"");
    }
    if (alleleSymbol != null) {
        query.addFilterQuery(StatisticalResultDTO.ALLELE_SYMBOL + ":(\""
                + StringUtils.join(alleleSymbol, "\" OR \"") + "\")");
    }
    if (procedureStableIds != null) {
        query.addFilterQuery(StatisticalResultDTO.PROCEDURE_STABLE_ID + ":("
                + StringUtils.join(procedureStableIds, " OR ") + ")");
    }
    if (procedureName != null) {
        query.addFilterQuery(StatisticalResultDTO.PROCEDURE_NAME + ":(\""
                + StringUtils.join(procedureName, "\" OR \"") + "\")");
    }
    if (resource != null) {
        query.addFilterQuery(
                StatisticalResultDTO.RESOURCE_NAME + ":(" + StringUtils.join(resource, " OR ") + ")");
    }
    if (pipelineStableId != null) {
        query.addFilterQuery(StatisticalResultDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId);
    }
    if (parameterStableId != null) {
        query.addFilterQuery(StatisticalResultDTO.PARAMETER_STABLE_ID + ":" + parameterStableId);
    }
    if (zygosities != null && zygosities.size() > 0 && zygosities.size() != 3) {
        if (zygosities.size() == 2) {
            query.addFilterQuery(StatisticalResultDTO.ZYGOSITY + ":(" + zygosities.get(0) + " OR "
                    + zygosities.get(1) + ")");
        } else {
            if (!zygosities.get(0).equalsIgnoreCase("null")) {
                query.addFilterQuery(StatisticalResultDTO.ZYGOSITY + ":" + zygosities.get(0));
            }
        }
    }

    if (sex != null && sex.size() > 0 && sex.size() != 3) {
        if (sex.size() == 2) {
            query.addFilterQuery(StatisticalResultDTO.SEX + ":(" + sex.get(0) + " OR " + sex.get(1) + ")");
        } else {
            if (!sex.get(0).equalsIgnoreCase("null")) {
                query.addFilterQuery(StatisticalResultDTO.SEX + ":" + sex.get(0));
            }
        }
    }

    if (strain != null) {
        query.addFilterQuery(ObservationDTO.STRAIN_ACCESSION_ID + ":" + strain.replace(":", "\\:"));
    }

    return query;

}

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

License:Apache License

/**
 * @author ilinca/*  w w w  .  ja  va 2 s .c  o m*/
 * @since 2016/07/07
 * @return CSV string of facet values (mp,gene,colony,phenCenter,sex,zyg,param,pVal). At the moment of writing used to compare calls from EBI to DCC
 * @throws SolrServerException, IOException
 * @throws URISyntaxException 
 * @throws IOException 
 * @throws MalformedURLException 
 */
public String getTabbedCallSummary() throws MalformedURLException, IOException, URISyntaxException {
    //   http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/genotype-phenotype/select?q=resource_name:IMPC&facet=true&facet.mincount=1&facet.pivot=mp_term_name,marker_symbol,colony_id,phenotyping_center,sex,zygosity,parameter_stable_id,p_value&facet.limit=-1&facet.mincount=1&wt=xslt&tr=pivot.xsl

    SolrQuery q = new SolrQuery();
    q.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":IMPC");
    q.addFilterQuery("-" + GenotypePhenotypeDTO.ASSERTION_TYPE + ":manual");
    q.setFacet(true);
    q.setFacetLimit(-1).setFacetMinCount(1)
            .addFacetPivotField(GenotypePhenotypeDTO.MP_TERM_ID + "," + GenotypePhenotypeDTO.MARKER_SYMBOL + ","
                    + GenotypePhenotypeDTO.COLONY_ID + "," + GenotypePhenotypeDTO.PHENOTYPING_CENTER + ","
                    + GenotypePhenotypeDTO.SEX + "," + GenotypePhenotypeDTO.ZYGOSITY + ","
                    + GenotypePhenotypeDTO.PARAMETER_STABLE_ID + "," + GenotypePhenotypeDTO.P_VALUE);
    q.set("wt", "xslt").set("tr", "pivot.xsl");

    HttpProxy proxy = new HttpProxy();
    System.out.println("Solr ULR for getTabbedCallSummary " + SolrUtils.getBaseURL(genotypePhenotypeCore)
            + "/select?" + q);

    String content = proxy.getContent(new URL(SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select?" + q));

    return content;
}

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

License:Apache License

public List<ImageSummary> getImageSummary(String markerAccessionId) throws SolrServerException, IOException {

    SolrQuery q = new SolrQuery();
    q.setQuery("*:*");
    q.setFilterQueries(ImageDTO.GENE_ACCESSION_ID + ":\"" + markerAccessionId + "\"");

    // TM decided only to display some procedures in the Summary
    q.addFilterQuery("(" + ImageDTO.PROCEDURE_STABLE_ID + ":IMPC_XRY* OR " + ImageDTO.PROCEDURE_STABLE_ID
            + ":IMPC_XRY* OR " + ImageDTO.PROCEDURE_STABLE_ID + ":IMPC_ALZ* OR " + ImageDTO.PROCEDURE_STABLE_ID
            + ":IMPC_PAT* OR " + ImageDTO.PROCEDURE_STABLE_ID + ":IMPC_EYE* OR " + ImageDTO.PROCEDURE_STABLE_ID
            + ":IMPC_HIS*" + ")");

    q.set("group", true);
    q.set("group.field", ImageDTO.PROCEDURE_NAME);
    q.set("group.limit", 1);
    q.set("group.sort", ImageDTO.DATE_OF_EXPERIMENT + " DESC");

    List<ImageSummary> res = new ArrayList<>();

    for (Group group : impcImagesCore.query(q).getGroupResponse().getValues().get(0).getValues()) {
        ImageSummary iSummary = new ImageSummary();
        iSummary.setNumberOfImages(group.getResult().getNumFound());
        iSummary.setProcedureId(/*from w ww  .j a  v  a2 s. c  om*/
                group.getResult().get(0).getFieldValue(ImageDTO.PROCEDURE_STABLE_ID).toString());
        iSummary.setProcedureName(group.getResult().get(0).getFieldValue(ImageDTO.PROCEDURE_NAME).toString());
        iSummary.setThumbnailUrl(group.getResult().get(0).getFieldValue(ImageDTO.JPEG_URL).toString()
                .replace("render_image", "render_thumbnail"));
        res.add(iSummary);
    }

    return res;
}

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

License:Apache License

public List<String[]> getLaczExpressionSpreadsheet(String imageCollectionLinkBase) {
    SolrQuery query = new SolrQuery();
    ArrayList<String[]> res = new ArrayList<>();
    String[] aux = new String[0];

    query.setQuery(ImageDTO.PROCEDURE_NAME + ":\"Adult LacZ\" AND " + ImageDTO.BIOLOGICAL_SAMPLE_GROUP
            + ":experimental");
    query.setRows(1000000);// w  w  w  . jav  a 2s  . c  o  m
    query.addField(ImageDTO.GENE_SYMBOL);
    query.addField(ImageDTO.GENE_ACCESSION_ID);
    query.addField(ImageDTO.ALLELE_SYMBOL);
    query.addField(ImageDTO.COLONY_ID);
    query.addField(ImageDTO.BIOLOGICAL_SAMPLE_ID);
    query.addField(ImageDTO.ZYGOSITY);
    query.addField(ImageDTO.SEX);
    query.addField(ImageDTO.PARAMETER_ASSOCIATION_NAME);
    query.addField(ImageDTO.PARAMETER_STABLE_ID);
    query.addField(ImageDTO.PARAMETER_ASSOCIATION_VALUE);
    query.addField(ImageDTO.GENE_ACCESSION_ID);
    query.addField(ImageDTO.PHENOTYPING_CENTER);
    query.setFacet(true);
    query.setFacetLimit(100);
    query.addFacetField(ImageDTO.PARAMETER_ASSOCIATION_NAME);
    query.set("group", true);
    query.set("group.limit", 100000);
    query.set("group.field", ImageDTO.BIOLOGICAL_SAMPLE_ID);

    try {
        QueryResponse solrResult = impcImagesCore.query(query);
        ArrayList<String> allParameters = new ArrayList<>();
        List<String> header = new ArrayList<>();
        header.add("Gene Symbol");
        header.add("MGI Gene Id");
        header.add("Allele Symbol");
        header.add("Colony Id");
        header.add("Biological Sample Id");
        header.add("Zygosity");
        header.add("Sex");
        header.add("Phenotyping Centre");

        logger.info(SolrUtils.getBaseURL(impcImagesCore) + "/select?" + query);

        // Get facets as we need to turn them into columns
        for (Count facet : solrResult.getFacetField(ImageDTO.PARAMETER_ASSOCIATION_NAME).getValues()) {
            allParameters.add(facet.getName());
            header.add(facet.getName());
        }
        header.add("image_collection_link");
        res.add(header.toArray(aux));
        for (Group group : solrResult.getGroupResponse().getValues().get(0).getValues()) {

            List<String> row = new ArrayList<>();
            ArrayList<String> params = new ArrayList<>();
            ArrayList<String> paramValues = new ArrayList<>();
            String urlToImagePicker = imageCollectionLinkBase + "/imageComparator?acc=";

            for (SolrDocument doc : group.getResult()) {
                if (row.size() == 0) {
                    row.add(doc.getFieldValues(ImageDTO.GENE_SYMBOL).iterator().next().toString());
                    row.add(doc.getFieldValues(ImageDTO.GENE_ACCESSION_ID).iterator().next().toString());
                    urlToImagePicker += doc.getFieldValue(ImageDTO.GENE_ACCESSION_ID) + "&parameter_stable_id=";
                    urlToImagePicker += doc.getFieldValue(ImageDTO.PARAMETER_STABLE_ID);
                    if (doc.getFieldValue(ImageDTO.ALLELE_SYMBOL) != null) {
                        row.add(doc.getFieldValue(ImageDTO.ALLELE_SYMBOL).toString());
                    }
                    row.add(doc.getFieldValue(ImageDTO.COLONY_ID).toString());
                    row.add(doc.getFieldValue(ImageDTO.BIOLOGICAL_SAMPLE_ID).toString());
                    if (doc.getFieldValue(ImageDTO.ZYGOSITY) != null) {
                        row.add(doc.getFieldValue(ImageDTO.ZYGOSITY).toString());
                    }
                    row.add(doc.getFieldValue(ImageDTO.SEX).toString());
                    row.add(doc.getFieldValue(ImageDTO.PHENOTYPING_CENTER).toString());
                }

                if (doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME) != null) {
                    for (int i = 0; i < doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME).size(); i++) {
                        params.add(doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME)
                                .toArray(new Object[0])[i].toString());

                        if (doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_VALUE) != null) {
                            paramValues.add(doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_VALUE)
                                    .toArray(new Object[0])[i].toString());
                        } else {
                            paramValues.add(Constants.NO_INFORMATION_AVAILABLE);
                        }
                    }
                }
            }

            for (String tissue : allParameters) {
                if (params.contains(tissue)) {
                    row.add(paramValues.get(params.indexOf(tissue)));
                } else {
                    row.add("");
                }
            }
            row.add(urlToImagePicker);
            res.add(row.toArray(aux));
        }

    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }
    return res;
}

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

License:Apache License

/**
 *
 * @param acc/*ww  w  .j a  v a2 s.  co m*/
 * @return a map containing the mp and colony_id combinations so that if we have these then we show an image link on the phenotype table on the gene page. Each row in table could have a different colony_id as well as mp id
 * @throws SolrServerException, IOException
 */

public Map<String, Set<String>> getImagePropertiesThatHaveMp(String acc)
        throws SolrServerException, IOException {
    //http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:1913955%22&fq=mp_id:*&facet=true&facet.mincount=1&facet.limit=-1&facet.field=colony_id&facet.field=mp_id&facet.field=mp_term&rows=0
    Map<String, Set<String>> mpToColony = new HashMap<>();
    SolrQuery query = new SolrQuery();

    query.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + acc + "\"").setRows(100000000);
    query.addFilterQuery(ImageDTO.MP_ID_TERM + ":*");
    query.setFacet(true);
    query.setFacetLimit(-1);
    query.setFacetMinCount(1);

    String pivotFacet = ImageDTO.MP_ID_TERM + "," + ImageDTO.COLONY_ID;
    query.set("facet.pivot", pivotFacet);
    query.addFacetField(ObservationDTO.COLONY_ID);
    logger.debug("solr query for images properties for mp = " + query);
    QueryResponse response = impcImagesCore.query(query);
    for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) {
        if (pivot.getPivot() != null) {
            //logger.info("pivot="+pivot.getValue());
            String mpIdAndName = pivot.getValue().toString();
            //logger.info("mpIdAndName" +mpIdAndName);
            String mpId = "";
            Set<String> colonIds = new TreeSet<>();
            if (mpIdAndName.contains("_")) {
                mpId = (mpIdAndName.split("_")[0]);
            }
            for (PivotField mp : pivot.getPivot()) {

                //logger.info("adding mp="+pivot.getValue()+" adding value="+mp.getValue());
                String colonyId = mp.getValue().toString();
                colonIds.add(colonyId);
            }
            mpToColony.put(mpId, colonIds);
        }

    }
    return mpToColony;

}

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

License:Apache License

/**
 * @since 2015/07/17// w ww  .j  ava2s . com
 * @author tudose
 * @return
 */

public List<ProcedureDTO> getProceduresByPipeline(String pipelineStableId) {

    List<ProcedureDTO> procedures = new ArrayList<>();

    try {
        SolrQuery query = new SolrQuery().setQuery(ImpressDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId)
                .addField(ImpressDTO.PROCEDURE_ID).addField(ImpressDTO.PROCEDURE_NAME)
                .addField(ImpressDTO.PROCEDURE_STABLE_ID).addField(ImpressDTO.PROCEDURE_STABLE_KEY);
        query.set("group", true);
        query.set("group.field", ImpressDTO.PROCEDURE_STABLE_ID);
        query.setRows(10000);
        query.set("group.limit", 1);

        System.out.println("URL for getProceduresByStableIdRegex " + SolrUtils.getBaseURL(pipelineCore)
                + "/select?" + query);

        QueryResponse response = pipelineCore.query(query);

        for (Group group : response.getGroupResponse().getValues().get(0).getValues()) {
            ProcedureDTO procedure = new ProcedureDTO(
                    Long.getLong(group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_ID).toString()),
                    Long.getLong(
                            group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_STABLE_KEY).toString()),
                    group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_STABLE_ID).toString(),
                    group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_NAME).toString());
            procedures.add(procedure);
        }

    } catch (SolrServerException | IOException | IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

    return procedures;
}

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

License:Apache License

/**
 * @author tudose/*w  w  w  . j a  va 2s  .c  o m*/
 * @since 2015/09/25
 * @return List< [(Procedure, parameter, observationNumber)]>
 */
public List<String[]> getProcedureParameterList() {

    List<String[]> result = new ArrayList<>();
    SolrQuery q = new SolrQuery();

    q.setQuery("*:*");
    q.setFacet(true);
    q.setFacetLimit(-1);
    q.setRows(0);

    String pivotFacet = ImpressDTO.PROCEDURE_STABLE_ID + "," + ImpressDTO.PARAMETER_STABLE_ID;
    q.set("facet.pivot", pivotFacet);

    try {
        QueryResponse res = pipelineCore.query(q);

        for (PivotField pivot : res.getFacetPivot().get(pivotFacet)) {
            if (pivot.getPivot() != null) {
                for (PivotField parameter : pivot.getPivot()) {
                    String[] row = { pivot.getValue().toString(), parameter.getValue().toString() };
                    result.add(row);
                }
            }
        }

    } catch (SolrServerException | IOException e) {
        e.printStackTrace();
    }

    return result;
}

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

License:Apache License

/**
 * @date 2015/07/08/*from   w w w  .j  a  va 2s.c  o  m*/
 * @author tudose
 * @return List of procedures in a pipeline
 */
public List<ProcedureDTO> getProcedures(String pipelineStableId) {

    List<ProcedureDTO> procedures = new ArrayList<>();

    try {
        SolrQuery query = new SolrQuery()
                .setQuery(ImpressDTO.PIPELINE_STABLE_ID + ":\"" + pipelineStableId + "\"")
                .addField(ImpressDTO.PROCEDURE_ID).addField(ImpressDTO.PROCEDURE_NAME)
                .addField(ImpressDTO.PROCEDURE_STABLE_ID).addField(ImpressDTO.PROCEDURE_STABLE_KEY)
                .addField(ImpressDTO.PARAMETER_ID).addField(ImpressDTO.PARAMETER_NAME)
                .addField(ImpressDTO.PARAMETER_STABLE_ID).addField(ImpressDTO.PARAMETER_STABLE_KEY);
        query.set("group", true);
        query.set("group.field", ImpressDTO.PROCEDURE_STABLE_ID);
        query.setRows(10000);
        query.set("group.limit", 10000);

        QueryResponse response = pipelineCore.query(query);

        for (Group group : response.getGroupResponse().getValues().get(0).getValues()) {

            ProcedureDTO procedure = new ProcedureDTO();
            procedure.setId(
                    Long.getLong(group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_ID).toString()));
            procedure.setName(group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_NAME).toString());
            procedure.setStableId(
                    group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_STABLE_ID).toString());
            procedure.setStableKey(Long.getLong(
                    group.getResult().get(0).getFirstValue(ImpressDTO.PROCEDURE_STABLE_KEY).toString()));

            for (SolrDocument doc : group.getResult()) {
                ParameterDTO parameter = new ParameterDTO();
                parameter.setId((Long) doc.getFirstValue(ImpressDTO.PARAMETER_ID));
                parameter.setStableKey(
                        Long.getLong(doc.getFirstValue(ImpressDTO.PARAMETER_STABLE_KEY).toString()));
                parameter.setStableId(doc.getFirstValue(ImpressDTO.PARAMETER_STABLE_ID).toString());
                parameter.setName(doc.getFirstValue(ImpressDTO.PARAMETER_NAME).toString());
                procedure.addParameter(parameter);
            }
        }

    } catch (SolrServerException | IOException | IndexOutOfBoundsException e) {
        e.printStackTrace();
    }

    return procedures;
}