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

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

Introduction

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

Prototype

public SolrQuery setFields(String... fields) 

Source Link

Usage

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

License:Apache License

private QueryResponse getAdultLaczImageFacetsForGene(String mgiAccession, String parameterStableId,
        String... fields) throws SolrServerException, IOException {

    //solrQuery.addFilterQuery(ImageDTO.PARAMETER_NAME + ":\"LacZ Images Section\" OR " + ImageDTO.PARAMETER_NAME
    //      + ":\"LacZ Images Wholemount\"");// reduce the number to image
    // e.g./*from   w w w.  j a  va2  s  .  com*/
    // http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:1920455%22&facet=true&facet.field=selected_top_level_ma_term&fq=(parameter_name:%22LacZ%20Images%20Section%22%20OR%20parameter_name:%22LacZ%20Images%20Wholemount%22)
    // for embryo data the fields would be like this
    // "parameter_name": "LacZ images section",
    // "procedure_name": "Embryo LacZ",

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + mgiAccession + "\"");
    if (!StringUtils.isEmpty(parameterStableId)) {
        solrQuery.addFilterQuery(ImageDTO.PARAMETER_STABLE_ID + ":" + parameterStableId);// reduce the number to image
        // parameters only as we are
        // talking about images not
        // expression data here
    }
    solrQuery.setFacetMinCount(1);
    solrQuery.setFacet(true);
    solrQuery.setFields(fields);
    solrQuery.addFacetField(ImageDTO.SELECTED_TOP_LEVEL_ANATOMY_TERM);
    solrQuery.setRows(Integer.MAX_VALUE);
    QueryResponse response = impcImagesCore.query(solrQuery);
    return response;
}

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

License:Apache License

public List<Count> getLaczCategoricalParametersForGene(String mgiAccession, String... fields)
        throws SolrServerException, IOException {
    // e.g./*from  w  w w.j a  va  2s. c o m*/
    // http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:1920455%22&facet=true&facet.field=selected_top_level_ma_term&fq=(parameter_name:%22LacZ%20Images%20Section%22%20OR%20parameter_name:%22LacZ%20Images%20Wholemount%22)
    // for embryo data the fields would be like this
    // "parameter_name": "LacZ images section",
    // "procedure_name": "Embryo LacZ",

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + mgiAccession + "\"");

    solrQuery.addFilterQuery(ImageDTO.PROCEDURE_NAME + ":\"Adult LacZ\"");
    solrQuery.addFilterQuery("-" + ImageDTO.PARAMETER_NAME + ":\"LacZ Images Section\"");
    solrQuery.addFilterQuery("-" + ImageDTO.PARAMETER_NAME + ":\"LacZ Images Wholemount\"");
    solrQuery.addFilterQuery(ObservationDTO.CATEGORY + ":\"expression\"");
    // only look for expresssion at the moment as that is all the anatamogram can  display
    solrQuery.setFacetMinCount(1);
    solrQuery.setFacet(true);
    solrQuery.setFields(fields);
    solrQuery.addFacetField(ImageDTO.PARAMETER_STABLE_ID);
    solrQuery.setRows(0);
    QueryResponse response = experimentCore.query(solrQuery);
    List<FacetField> categoryParameterFields = response.getFacetFields();

    return categoryParameterFields.get(0).getValues();
}

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

License:Apache License

private QueryResponse getEmbryoLaczImageFacetsForGene(String mgiAccession, String parameterStableId,
        String... fields) throws SolrServerException, IOException {
    //solrQuery.addFilterQuery(ImageDTO.PARAMETER_STABLE_ID + ":IMPC_ELZ_064_001" + " OR "
    //+ ImageDTO.PARAMETER_STABLE_ID + ":IMPC_ELZ_063_001");
    // e.g.//from www .j a v  a2 s  .  c  o m
    // http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:1920455%22&facet=true&facet.field=selected_top_level_ma_term&fq=(parameter_name:%22LacZ%20Images%20Section%22%20OR%20parameter_name:%22LacZ%20Images%20Wholemount%22)
    // for embryo data the fields would be like this
    // "parameter_name": "LacZ images section",
    // "procedure_name": "Embryo LacZ",

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + mgiAccession + "\"");
    solrQuery.addFilterQuery(ImageDTO.PARAMETER_STABLE_ID + ":" + parameterStableId);// reduce
    // the number to image parameters only as we are talking about images not expression data here
    solrQuery.setFacetMinCount(1);
    solrQuery.setFacet(true);
    solrQuery.setFields(fields);
    solrQuery.addFacetField(ImageDTO.SELECTED_TOP_LEVEL_ANATOMY_TERM);
    solrQuery.setRows(Integer.MAX_VALUE);
    solrQuery.setSort(ObservationDTO.ID, SolrQuery.ORDER.asc);
    QueryResponse response = impcImagesCore.query(solrQuery);
    return response;
}

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

License:Apache License

/**
 * Return all genes in the gene core matching latestPhenotypeStatus and
 * latestProductionCentre./*from   w w  w . ja va  2 s.co m*/
 * 
 * @param latestPhenotypeStatus
 *            latest phenotype status (i.e. most advanced along the pipeline)
 * @param latestProductionCentre
 *            latest production centre (i.e. most advanced along the pipeline)
 * @return all genes in the gene core matching phenotypeStatus and
 *         productionCentre.
 * @throws SolrServerException, IOException
 */
public Set<String> getGenesByLatestPhenotypeStatusAndProductionCentre(String latestPhenotypeStatus,
        String latestProductionCentre) throws SolrServerException, IOException {
    SolrQuery solrQuery = new SolrQuery();
    String queryString = "(" + GeneDTO.LATEST_PHENOTYPE_STATUS + ":\"" + latestPhenotypeStatus + "\") AND ("
            + GeneDTO.LATEST_PRODUCTION_CENTRE + ":\"" + latestProductionCentre + "\")";
    solrQuery.setQuery(queryString);
    solrQuery.setRows(1000000);
    solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID);
    QueryResponse rsp = null;
    rsp = geneCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allGenes = new HashSet<String>();
    for (SolrDocument doc : res) {
        allGenes.add((String) doc.getFieldValue(GeneDTO.MGI_ACCESSION_ID));
    }

    log.debug("getGenesByLatestPhenotypeStatusAndProductionCentre: solrQuery = " + queryString);
    return allGenes;
}

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

License:Apache License

/**
 * Return all genes in the gene core matching latestPhenotypeStatus and
 * latestPhenotypeCentre.//from www.j a v a 2 s.c o m
 * 
 * @param latestPhenotypeStatus
 *            latest phenotype status (i.e. most advanced along the pipeline)
 * @param latestPhenotypeCentre
 *            latest phenotype centre (i.e. most advanced along the pipeline)
 * @return all genes in the gene core matching phenotypeStatus and
 *         productionCentre.
 * @throws SolrServerException, IOException
 */
public Set<String> getGenesByLatestPhenotypeStatusAndPhenotypeCentre(String latestPhenotypeStatus,
        String latestPhenotypeCentre) throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    String queryString = "(" + GeneDTO.LATEST_PHENOTYPE_STATUS + ":\"" + latestPhenotypeStatus + "\") AND ("
            + GeneDTO.LATEST_PHENOTYPING_CENTRE + ":\"" + latestPhenotypeCentre + "\")";
    solrQuery.setQuery(queryString);
    solrQuery.setRows(1000000);
    solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID);
    QueryResponse rsp = null;
    rsp = geneCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allGenes = new HashSet<String>();
    for (SolrDocument doc : res) {
        allGenes.add((String) doc.getFieldValue(GeneDTO.MGI_ACCESSION_ID));
    }

    log.debug("getGenesByLatestPhenotypeStatusAndPhenotypeCentre: solrQuery = " + queryString);
    return allGenes;
}

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

License:Apache License

/**
 * Return all gene MGI IDs from the gene core.
 * //from w w w. ja  va2  s.  c  om
 * @return all genes from the gene core.
 * @throws SolrServerException, IOException
 */
public Set<String> getAllGenes() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(GeneDTO.MGI_ACCESSION_ID + ":*");
    solrQuery.setRows(1000000);
    solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID);
    QueryResponse rsp = null;
    rsp = geneCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allGenes = new HashSet<String>();
    for (SolrDocument doc : res) {
        allGenes.add((String) doc.getFieldValue(GeneDTO.MGI_ACCESSION_ID));
    }
    return allGenes;
}

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

License:Apache License

/**
 * Return all genes from the gene core whose MGI_ACCESSION_ID does not start
 * with 'MGI'.//from w ww  .ja  v a 2  s .c  o m
 * 
 * @return all genes from the gene core whose MGI_ACCESSION_ID does not
 *         start with 'MGI'.
 * @throws SolrServerException, IOException
 */
public Set<String> getAllNonConformingGenes() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery("-" + GeneDTO.MGI_ACCESSION_ID + ":MGI*");
    solrQuery.setRows(1000000);
    solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID);
    QueryResponse rsp = null;
    rsp = geneCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allGenes = new HashSet<String>();

    for (SolrDocument doc : res) {
        allGenes.add((String) doc.getFieldValue(GeneDTO.MGI_ACCESSION_ID));
    }

    return allGenes;
}

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

License:Apache License

public GeneDTO getGeneById(String mgiId, String... fields) throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery().setQuery(GeneDTO.MGI_ACCESSION_ID + ":\"" + mgiId + "\"").setRows(1);
    if (fields != null) {
        solrQuery.setFields(fields);
    }/*w w w  .jav a  2s  . c o m*/

    QueryResponse rsp = geneCore.query(solrQuery);
    if (rsp.getResults().getNumFound() > 0) {
        return rsp.getBeans(GeneDTO.class).get(0);
    }
    return null;
}

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

License:Apache License

/**
 * Return a list of gene DTOs cooresponding to the
 * @param mgiIds//from   w ww.  jav a  2 s.  c  om
 * @param fields (Optional) list of fields
 * @return
 * @throws SolrServerException
 * @throws IOException
 */
public List<GeneDTO> getGenesByMgiIds(List<String> mgiIds, String... fields)
        throws SolrServerException, IOException {

    if (mgiIds == null)
        return new ArrayList<>();
    List<String> quotedMgiIds = mgiIds.stream().map(x -> String.format("\"%s\"", x))
            .collect(Collectors.toList());

    SolrQuery query = new SolrQuery()
            .setQuery(GeneDTO.MGI_ACCESSION_ID + ":(" + StringUtils.join(quotedMgiIds, ",") + ")")
            .setRows(mgiIds.size());

    if (fields != null) {
        query.setFields(fields);
    }

    QueryResponse response = geneCore.query(query, METHOD.POST);

    List<GeneDTO> genes = new ArrayList<>();
    if (response.getResults().getNumFound() > 0) {
        genes = response.getBeans(GeneDTO.class);
    }

    return genes;
}

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

License:Apache License

/**
 * Returns a set of MARKER_ACCESSION_ID strings of all genes that have
 * phenotype associations./*from   w  w  w . j a v a2 s  . c  o  m*/
 *
 * @return a set of MARKER_ACCESSION_ID strings of all genes that have
 * phenotype associations.
 * @throws SolrServerException, IOException
 */
public Set<String> getAllGenesWithPhenotypeAssociations() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(GenotypePhenotypeDTO.MARKER_ACCESSION_ID + ":*");
    solrQuery.setRows(1000000);
    solrQuery.setFields(GenotypePhenotypeDTO.MARKER_ACCESSION_ID);
    QueryResponse rsp = null;
    rsp = genotypePhenotypeCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allGenes = new HashSet<String>();
    for (SolrDocument doc : res) {
        allGenes.add((String) doc.getFieldValue(GenotypePhenotypeDTO.MARKER_ACCESSION_ID));
    }
    return allGenes;
}