List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetLimit
public SolrQuery setFacetLimit(int lim)
From source file:org.mousephenotype.cda.solr.service.AlleleService.java
License:Apache License
public TreeMap<String, Long> getStatusCountByProductionCenter(String center, String statusField) { TreeMap<String, Long> res = new TreeMap<>(new ProductionStatusComparator()); SolrQuery solrQuery = new SolrQuery(); QueryResponse solrResponse;/*ww w .ja v a 2 s . c o m*/ if (center != null) { String geneQuery = AlleleDTO.LATEST_PRODUCTION_CENTRE + ":\"" + center + "\""; solrQuery.setQuery(geneQuery); } else { solrQuery.setQuery("*:*"); } solrQuery.setRows(1); solrQuery.setFacet(true); solrQuery.setFacetLimit(-1); try { solrQuery.addFacetField(statusField); solrResponse = alleleCore.query(solrQuery); for (Count c : solrResponse.getFacetField(statusField).getValues()) { // We don't want to show everything if (!c.getName().equals("")) { res.put(c.getName(), c.getCount()); } } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
From source file:org.mousephenotype.cda.solr.service.AlleleService.java
License:Apache License
public Set<String> getFacets(String field) { SolrQuery solrQuery = new SolrQuery(); QueryResponse solrResponse;//from w ww . j a va 2 s . c o m Set<String> res = new HashSet<>(); solrQuery.setQuery("*:*"); solrQuery.setFacet(true); solrQuery.setFacetLimit(-1); solrQuery.addFacetField(field); logger.info(this.getClass().getEnclosingMethod() + " " + SolrUtils.getBaseURL(alleleCore) + "/select?" + solrQuery); try { solrResponse = alleleCore.query(solrQuery); for (Count c : solrResponse.getFacetField(field).getValues()) { res.add(c.getName()); } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
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);/*from www. j ava2 s .com*/ query.setFacetLimit(-1); 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/*from w ww .j a va 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 v a 2 s .com*/ */ 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 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);/* w w w.java 2 s.c om*/ 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);/*ww w. j a v a 2 s .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 .j a v a2 s .co m * @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
/** * @author ilinca/*from w ww . j a v a2 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.GenotypePhenotypeService.java
License:Apache License
Map<String, Long> getDocumentCountByMgiGeneAccessionId() { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(0);/*from ww w . jav a 2s . c o m*/ query.setFacet(true); query.addFacetField(GenotypePhenotypeDTO.MARKER_ACCESSION_ID); query.setFacetLimit(-1); query.setFacetMinCount(1); try { return getFacets(genotypePhenotypeCore.query(query)).get(GenotypePhenotypeDTO.MARKER_ACCESSION_ID); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return new HashMap<>(); }