List of usage examples for org.apache.solr.client.solrj SolrQuery setRows
public SolrQuery setRows(Integer rows)
From source file:org.mousephenotype.cda.solr.service.GeneService.java
License:Apache License
/** * Get the mouse production status for gene (not allele) for geneHeatMap implementation for idg for each of 300 odd genes * @param geneIds/* w w w. j a v a 2s. co m*/ * @return * @throws SolrServerException, IOException */ public Map<String, GeneDTO> getHumanOrthologsForGeneSet(Set<String> geneIds) throws SolrServerException, IOException { Map<String, GeneDTO> geneToHumanOrthologMap = new HashMap<>(); SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.setFilterQueries( GeneDTO.MGI_ACCESSION_ID + ":(" + StringUtils.join(geneIds, " OR ").replace(":", "\\:") + ")"); solrQuery.setRows(100000); solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID, GeneDTO.HUMAN_GENE_SYMBOL, GeneDTO.DISEASE_ID, GeneDTO.LATEST_PHENOTYPE_STATUS); log.info("server query is: {}", solrQuery.toString()); QueryResponse rsp = geneCore.query(solrQuery); List<GeneDTO> genes = rsp.getBeans(GeneDTO.class); for (GeneDTO gene : genes) { geneToHumanOrthologMap.put(gene.getMgiAccessionId(), gene); } return geneToHumanOrthologMap; }
From source file:org.mousephenotype.cda.solr.service.GeneService.java
License:Apache License
public List<GeneDTO> getGenesSymbolsBy(String mpId) throws IOException, SolrServerException { if (mpId == null) { return null; }//w ww .j a v a 2s. c om SolrQuery query = new SolrQuery(); query.setQuery( "(" + GeneDTO.MP_ID + ":\"" + mpId + "\" OR " + GeneDTO.TOP_LEVEL_MP_ID + ":\"" + mpId + "\")"); query.setRows(Integer.MAX_VALUE); query.setFields(GeneDTO.MARKER_SYMBOL, GeneDTO.MGI_ACCESSION_ID, GeneDTO.HUMAN_GENE_SYMBOL, GeneDTO.MP_ID, GeneDTO.MP_TERM); QueryResponse rsp = geneCore.query(query); return rsp.getBeans(GeneDTO.class); }
From source file:org.mousephenotype.cda.solr.service.GeneService.java
License:Apache License
/** * * @param geneIds the input set of gene ids (e.g. idg genes) * @param statusField the status field//from w w w. j a v a 2s . co m * @return Number of genes (from the provided list) in each status of interest. */ public HashMap<String, Long> getStatusCount(Set<String> geneIds, String statusField) { HashMap<String, Long> res = new HashMap<>(); SolrQuery solrQuery = new SolrQuery(); QueryResponse solrResponse; if (geneIds != null) { String geneQuery = GeneDTO.MGI_ACCESSION_ID + ":(" + StringUtils.join(geneIds, " OR ").replace(":", "\\:") + ")"; solrQuery.setQuery(geneQuery); } else { solrQuery.setQuery("*:*"); } solrQuery.setRows(1); solrQuery.setFacet(true); solrQuery.setFacetLimit(-1); try { solrQuery.addFacetField(statusField); solrResponse = geneCore.query(solrQuery); for (Count c : solrResponse.getFacetField(statusField).getValues()) { res.put(c.getName(), c.getCount()); } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
From source file:org.mousephenotype.cda.solr.service.GeneService.java
License:Apache License
/** * Get the mouse project status for a set of genes (not alleles) for table implementation for cmg * * @param geneId//from w w w . j a va2s . com * @return * @throws SolrServerException, IOException */ public String getLatestProjectStatusForGeneSet(String geneId) throws SolrServerException, IOException { String latestProjectStatus = ""; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("*:*"); solrQuery.setFilterQueries(GeneDTO.MGI_ACCESSION_ID + ":(" + geneId.replace(":", "\\:") + ")"); solrQuery.setRows(100000); solrQuery.setFields(GeneDTO.MGI_ACCESSION_ID, GeneDTO.LATEST_PROJECT_STATUS); log.info("server query is: {}", solrQuery.toString()); QueryResponse rsp = geneCore.query(solrQuery); List<GeneDTO> genes = rsp.getBeans(GeneDTO.class); for (GeneDTO gene : genes) { latestProjectStatus = gene.getLatestProjectStatus(); } return latestProjectStatus; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
/** * @param zygosity - optional (pass null if not needed) * @return Map <String, Long> : <top_level_mp_name, number_of_annotations> * @author tudose// w w w . j a v a 2s. c om */ public TreeMap<String, Long> getDistributionOfAnnotationsByMPTopLevel(ZygosityType zygosity, String resourceName) { SolrQuery query = new SolrQuery(); if (zygosity != null) { query.setQuery(GenotypePhenotypeDTO.ZYGOSITY + ":" + zygosity.getName()); } else if (resourceName != null) { query.setFilterQueries(GenotypePhenotypeDTO.RESOURCE_NAME + ":" + resourceName); } else { query.setQuery("*:*"); } query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); query.setRows(0); query.addFacetField(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME); try { QueryResponse response = genotypePhenotypeCore.query(query); TreeMap<String, Long> res = new TreeMap<>(); res.putAll(getFacets(response).get(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME)); return res; } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
public long getNumberOfDocuments(List<String> resourceName) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setRows(0); if (resourceName != null) { query.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + GenotypePhenotypeDTO.RESOURCE_NAME + ":")); } else {/*from ww w . ja v a 2 s. c o m*/ query.setQuery("*:*"); } return genotypePhenotypeCore.query(query).getResults().getNumFound(); }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
/** * @since 2016/07/04/*from w w w . j av a 2 s . c om*/ * @author ilinca * @param anatomyId * @return * @throws SolrServerException, IOException */ public List<GenotypePhenotypeDTO> getPhenotypesForAnatomy(String anatomyId) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setRows(Integer.MAX_VALUE); query.setQuery(GenotypePhenotypeDTO.ANATOMY_TERM_ID + ":\"" + anatomyId + "\" OR " + GenotypePhenotypeDTO.INTERMEDIATE_ANATOMY_TERM_ID + ":\"" + anatomyId + "\" OR " + GenotypePhenotypeDTO.TOP_LEVEL_ANATOMY_TERM_ID + ":\"" + anatomyId + "\""); query.setFields(GenotypePhenotypeDTO.MP_TERM_ID, GenotypePhenotypeDTO.MP_TERM_NAME, GenotypePhenotypeDTO.P_VALUE, GenotypePhenotypeDTO.MARKER_ACCESSION_ID, GenotypePhenotypeDTO.MARKER_SYMBOL, GenotypePhenotypeDTO.SEX, GenotypePhenotypeDTO.ZYGOSITY); return genotypePhenotypeCore.query(query).getBeans(GenotypePhenotypeDTO.class); }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
public Map<String, Long> getHitsDistributionBySomethingNoIds(String fieldToDistributeBy, List<String> resourceName, ZygosityType zygosity, int facetMincount, Double maxPValue) throws SolrServerException, IOException, InterruptedException, ExecutionException { Map<String, Long> res = new HashMap<>(); Long time = System.currentTimeMillis(); SolrQuery q = new SolrQuery(); if (resourceName != null) { q.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + GenotypePhenotypeDTO.RESOURCE_NAME + ":")); } else {/*from ww w.j a v a2 s .co m*/ q.setQuery("*:*"); } if (zygosity != null) { q.addFilterQuery(GenotypePhenotypeDTO.ZYGOSITY + ":" + zygosity.name()); } if (maxPValue != null) { q.addFilterQuery(GenotypePhenotypeDTO.P_VALUE + ":[0 TO " + maxPValue + "]"); } q.addFacetField(fieldToDistributeBy); q.setFacetMinCount(facetMincount); q.setFacet(true); q.setRows(1); q.set("facet.limit", -1); logger.info("Solr url for getHitsDistributionByParameter " + SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select?" + q); QueryResponse response = genotypePhenotypeCore.query(q); for (Count facet : response.getFacetField(fieldToDistributeBy).getValues()) { String value = facet.getName(); long count = facet.getCount(); res.put(value, count); } logger.info("Done in " + (System.currentTimeMillis() - time)); return res; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
private List<String[]> getHitsDistributionBySomething(String field, List<String> resourceName) throws SolrServerException, IOException, InterruptedException, ExecutionException { List<String[]> res = new ArrayList<>(); Long time = System.currentTimeMillis(); String pivotFacet = ""; SolrQuery q = new SolrQuery(); if (field.equals(GenotypePhenotypeDTO.PARAMETER_STABLE_ID)) { pivotFacet = GenotypePhenotypeDTO.PARAMETER_STABLE_ID + "," + StatisticalResultDTO.PARAMETER_NAME; } else if (field.equals(GenotypePhenotypeDTO.PROCEDURE_STABLE_ID)) { pivotFacet = GenotypePhenotypeDTO.PROCEDURE_STABLE_ID + "," + StatisticalResultDTO.PROCEDURE_NAME; }/*from w w w .j a v a 2 s . c o m*/ if (resourceName != null) { q.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + GenotypePhenotypeDTO.RESOURCE_NAME + ":")); } else { q.setQuery("*:*"); } q.set("facet.pivot", pivotFacet); q.setFacet(true); q.setRows(1); q.set("facet.limit", -1); logger.info("Solr url for getHitsDistributionByParameter " + SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select?" + q); QueryResponse response = genotypePhenotypeCore.query(q); for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) { if (pivot.getPivot() != null) { String id = pivot.getValue().toString(); String name = pivot.getPivot().get(0).getValue().toString(); int count = pivot.getPivot().get(0).getCount(); String[] row = { id, name, Integer.toString(count) }; res.add(row); } } logger.info("Done in " + (System.currentTimeMillis() - time)); return res; }