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.GenotypePhenotypeService.java

License:Apache License

/**
 * Returns a set of MP_TERM_ID strings of all phenotypes that have gene
 * associations./*  w  ww .  jav a 2s. c o m*/
 *
 * @return a set of MP_TERM_ID strings of all phenotypes that have gene
 * associations.
 * @throws SolrServerException, IOException
 */
public Set<String> getAllPhenotypesWithGeneAssociations() throws SolrServerException, IOException {

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

    return allPhenotypes;
}

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

License:Apache License

/**
 * Returns a set of MP_TERM_ID strings of all top-level phenotypes.
 *
 * @return a set of MP_TERM_ID strings of all top-level phenotypes.
 * @throws SolrServerException, IOException
 *///from  w ww. j  a  va  2 s . co  m
public Set<String> getAllTopLevelPhenotypes() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":*");
    solrQuery.setRows(1000000);
    solrQuery.setFields(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID);
    QueryResponse rsp = genotypePhenotypeCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allTopLevelPhenotypes = new HashSet<String>();
    for (SolrDocument doc : res) {
        List<String> ids = getListFromCollection(doc.getFieldValues(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID));
        for (String id : ids) {
            allTopLevelPhenotypes.add(id);
        }
    }

    return allTopLevelPhenotypes;
}

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

License:Apache License

/**
 * Returns a set of MP_TERM_ID strings of all intermediate-level phenotypes.
 *
 * @return a set of MP_TERM_ID strings of all intermediate-level phenotypes.
 * @throws SolrServerException, IOException
 *///from  ww w. ja  v a 2  s.  c o m
public Set<String> getAllIntermediateLevelPhenotypes() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":*");
    solrQuery.setRows(1000000);
    solrQuery.setFields(GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID);
    QueryResponse rsp = genotypePhenotypeCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    HashSet<String> allIntermediateLevelPhenotypes = new HashSet<String>();
    for (SolrDocument doc : res) {
        List<String> ids = getListFromCollection(
                doc.getFieldValues(GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID));
        for (String id : ids) {
            allIntermediateLevelPhenotypes.add(id);
        }
    }

    return allIntermediateLevelPhenotypes;
}

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

License:Apache License

public Set<String> getAllGenotypePhenotypesForGene(String markerAccession)
        throws SolrServerException, IOException {

    Set<String> alleles = new HashSet<>();
    SolrQuery query = new SolrQuery().setRows(Integer.MAX_VALUE);
    query.setQuery(GenotypePhenotypeDTO.MARKER_ACCESSION_ID + ":\"" + markerAccession + "\"");
    query.setFields(GenotypePhenotypeDTO.ALLELE_ACCESSION_ID);
    List<GenotypePhenotypeDTO> results = genotypePhenotypeCore.query(query)
            .getBeans(GenotypePhenotypeDTO.class);

    for (GenotypePhenotypeDTO doc : results) {
        alleles.add(doc.getAlleleAccessionId());
    }/*from  w  w w.j  av  a  2 s.c  o  m*/

    return alleles;
}

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   w w w .  j  av a2  s  .  com*/
 * @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.ImpressService.java

License:Apache License

/**
 * Return an ImpressDTO object representing the IMPReSS parameter requested with the stableId parameter
 * The ImpressDTO object with bew populated with only those attributes specified in the "fields" parameter, or
 * if "fields" is null, the whold object will be populated
 *
 * see https://www.mousephenotype.org/impress
 *
 * @param stableId the IMPReSS ID of the parameter to return
 *                 @param fields List of ImpressDTO
 *
 * @return parameterDTO object populated with the attributes indicated by the "fields" parameter, or all attributes if "fields" is null
 *
 * @throws SolrServerException, IOException
 *
 *///from   ww  w.  jav  a  2s .co m
public ImpressDTO getParameterByStableIdSpecifyFields(String stableId, List<String> fields)
        throws SolrServerException, IOException {

    SolrQuery query = new SolrQuery().setQuery(ImpressDTO.PARAMETER_STABLE_ID + ":" + stableId).setRows(1);

    // Specify fields if set
    if (fields != null) {
        query.setFields(fields.toArray(new String[] {}));
    }

    List<ImpressDTO> parameters = pipelineCore.query(query).getBeans(ImpressDTO.class);
    return (parameters.size() > 0) ? parameters.get(0) : null;
}

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

License:Apache License

/**
 * Return all phenotypes from the mp core.
 *
 * @return all genes from the gene core.
 * @throws SolrServerException, IOException
 *///from ww  w  .  j  a v  a 2s  .  c  om
public Set<String> getAllPhenotypes() throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(MpDTO.MP_ID + ":*");
    solrQuery.setFields(MpDTO.MP_ID);
    solrQuery.setRows(1000000);
    QueryResponse rsp;
    rsp = mpCore.query(solrQuery);
    List<MpDTO> mps = rsp.getBeans(MpDTO.class);
    Set<String> allPhenotypes = new HashSet<String>();

    for (MpDTO mp : mps) {
        allPhenotypes.add(mp.getMpId());
    }

    return allPhenotypes;
}

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

License:Apache License

public ArrayList<String> getChildrenFor(String mpId) throws SolrServerException, IOException {

    SolrQuery solrQuery = new SolrQuery();
    solrQuery.setQuery(MpDTO.MP_ID + ":\"" + mpId + "\"");
    solrQuery.setFields(MpDTO.CHILD_MP_ID);
    QueryResponse rsp = mpCore.query(solrQuery);
    SolrDocumentList res = rsp.getResults();
    ArrayList<String> children = new ArrayList<String>();

    for (SolrDocument doc : res) {
        if (doc.containsKey(MpDTO.CHILD_MP_ID)) {
            for (Object child : doc.getFieldValues(MpDTO.CHILD_MP_ID)) {
                children.add((String) child);
            }//from   w  ww .  java 2  s.c  o  m
        }
    }
    return children;
}

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

License:Apache License

public Set<PhenotypeCenterAllServiceBean> getDataByCenter(String center)
        throws SolrServerException, IOException {

    final String[] fields = {

            StatisticalResultDTO.PHENOTYPING_CENTER, StatisticalResultDTO.COLONY_ID,
            StatisticalResultDTO.MARKER_ACCESSION_ID, StatisticalResultDTO.MARKER_SYMBOL,
            StatisticalResultDTO.ALLELE_ACCESSION_ID, StatisticalResultDTO.ALLELE_SYMBOL,
            StatisticalResultDTO.PROCEDURE_STABLE_ID, StatisticalResultDTO.PROCEDURE_NAME,
            StatisticalResultDTO.PARAMETER_STABLE_ID, StatisticalResultDTO.PARAMETER_NAME,
            StatisticalResultDTO.TOP_LEVEL_MP_TERM_ID, StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME,
            StatisticalResultDTO.MP_TERM_ID, StatisticalResultDTO.MP_TERM_NAME, StatisticalResultDTO.ZYGOSITY,
            StatisticalResultDTO.LIFE_STAGE_NAME, StatisticalResultDTO.STATUS

    };/*from  w  w  w  .  java  2s.c om*/
    ;
    SolrQuery query = new SolrQuery();

    query.setQuery("*:*");
    query.setFilterQueries(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + center + "\"");
    query.setFields(fields);
    query.setRows(1000000);
    QueryResponse response = statisticalResultCore.query(query);

    List<StatisticalResultDTO> dtos = response.getBeans(StatisticalResultDTO.class);

    HashSet<PhenotypeCenterAllServiceBean> data = new HashSet<>();
    for (StatisticalResultDTO dto : dtos) {

        // Add a separate row for every topLevelMpTermId
        PhenotypeCenterAllServiceBean bean = new PhenotypeCenterAllServiceBean();

        bean.setColonyId(dto.getColonyId());
        bean.setZygosity(dto.getZygosity());
        bean.setGeneAccessionId(dto.getMarkerAccessionId());
        bean.setGeneSymbol(dto.getMarkerSymbol());
        bean.setAlleleAccessionId(dto.getAlleleAccessionId());
        bean.setAlleleSymbol(dto.getAlleleSymbol());
        bean.setProcedureStableId(dto.getProcedureStableId());
        bean.setParameterStableId(dto.getParameterStableId());
        bean.setTopLevelMpTermId(dto.getTopLevelMpTermId());
        bean.setMpTermId(dto.getMpTermId());
        bean.setLifeStageName(dto.getLifeStageName());
        bean.setStatus(dto.getStatus());

        data.add(bean);
    }

    return data;
}

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

License:Apache License

public List<String> fetchQueryIdsFromChrRange(String chr, String chrStart, String chrEnd, String mode)
        throws IOException, SolrServerException {
    List<String> queryIds = new ArrayList<>();

    SolrClient server = null;//from   w w  w . j  a va 2  s.c  o m
    server = getSolrServer("gene");

    SolrQuery query = new SolrQuery();
    query.setQuery("*:*");
    query.setFilterQueries("seq_region_id:" + chr + " AND seq_region_start:[" + chrStart + " TO " + chrEnd + "]"
            + " AND seq_region_end:[" + chrStart + " TO " + chrEnd + "]");
    query.setFields("mgi_accession_id");

    System.out.println("Query: " + query);
    QueryResponse response = null;
    if (!mode.equals("export")) {
        query.setRows(10); // default, display only a max of 10 records on batchQuery page
        response = server.query(query, METHOD.POST);
    } else {
        query.setRows(0);
        response = server.query(query, METHOD.POST);
        int rows = (int) response.getResults().getNumFound(); // need to figure out how many docs found for full export
        query.setRows(rows); // default
        response = server.query(query, METHOD.POST);
    }

    System.out.println("Found " + response.getResults().getNumFound() + " gene(s) in range");
    for (SolrDocument doc : response.getResults()) {
        queryIds.add(doc.get("mgi_accession_id").toString());
    }
    return queryIds;
}