List of usage examples for org.apache.solr.client.solrj SolrQuery setFacet
public SolrQuery setFacet(boolean b)
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 w w w. ja va 2 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.ExpressionService.java
License:Apache License
/** * @author ilinca//www .j a va 2 s . c o m * @since 2016/07/08 * @param anatomyId * @return List of gene ids with positive expression in given anatomy term. * @throws SolrServerException, IOException */ public List<String> getGenesWithExpression(String anatomyId) throws SolrServerException, IOException { List<String> geneIds = new ArrayList<>(); SolrQuery q = new SolrQuery(); q.setQuery(ObservationDTO.CATEGORY + ":\"expression\"") .addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":\"experimental\""); if (anatomyId != null) { q.setFilterQueries(ObservationDTO.ANATOMY_ID + ":\"" + anatomyId + "\" OR " + ObservationDTO.TOP_LEVEL_ANATOMY_ID + ":\"" + anatomyId + "\" OR " + ObservationDTO.INTERMEDIATE_ANATOMY_ID + ":\"" + anatomyId + "\""); } q.setFacet(true).setFacetMinCount(1).setFacetLimit(-1).addFacetField(ObservationDTO.GENE_ACCESSION_ID); for (Count value : experimentCore.query(q).getFacetFields().get(0).getValues()) { geneIds.add(value.getName()); } return geneIds; }
From source file:org.mousephenotype.cda.solr.service.ExpressionService.java
License:Apache License
public Map<String, Set<String>> getFacets(String anatomyId) throws SolrServerException, IOException { Map<String, Set<String>> res = new HashMap<>(); SolrQuery query = getBasicExpressionQuery(anatomyId); // only have expressed and // not expressed ingnore // ambiguous and no tissue //query.addFilterQuery("(" + ImageDTO.PARAMETER_ASSOCIATION_VALUE + ":\"no expression\" OR " + ImageDTO.PARAMETER_ASSOCIATION_VALUE // + ":\"expression\"" + ")"); query.setFacet(true); query.setFacetLimit(-1);//from w w w.ja v a 2 s. co m query.setFacetMinCount(1); query.addFacetField(ObservationDTO.ANATOMY_TERM); query.addFacetField(ObservationDTO.PHENOTYPING_CENTER); query.addFacetField(ObservationDTO.PROCEDURE_NAME); query.addFacetField(ObservationDTO.CATEGORY); QueryResponse response = experimentCore.query(query); for (FacetField facetField : response.getFacetFields()) { Set<String> filter = new TreeSet<>(); for (Count facet : facetField.getValues()) { filter.add(facet.getName()); } res.put(facetField.getName(), filter); } return res; }
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// w w w .j av a 2 s. c o 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.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/*from w w w. j a va 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 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 w w w .j a va 2 s.c o 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 a2s. c om*/ 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; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
public PhenotypeFacetResult getMPByGeneAccessionAndFilter(String accId, List<String> topLevelMpTermName, List<String> resourceFullname) throws IOException, URISyntaxException, JSONException { String solrUrl = SolrUtils.getBaseURL(genotypePhenotypeCore) + "/select?"; SolrQuery q = new SolrQuery(); q.setQuery(GenotypePhenotypeDTO.MARKER_ACCESSION_ID + ":\"" + accId + "\""); q.setRows(10000000);//from w ww . j av a 2s . com q.setFacet(true); q.setFacetMinCount(1); q.setFacetLimit(-1); q.addFacetField(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME); //q.addFacetField(GenotypePhenotypeDTO.RESOURCE_FULLNAME); q.set("wt", "json"); q.setSort(GenotypePhenotypeDTO.P_VALUE, ORDER.asc); if (topLevelMpTermName != null) { q.addFilterQuery(GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_NAME + ":(\"" + StringUtils.join(topLevelMpTermName, "\" OR \"") + "\")"); } solrUrl += q; return createPhenotypeResultFromSolrResponse(solrUrl); }
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 ww w . j av a2s . c o m 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// w w w.ja v a 2s . 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; }