List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetMinCount
public SolrQuery setFacetMinCount(int cnt)
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
public QueryResponse getProcedureFacetsForGeneByProcedure(String mgiAccession, String experimentOrControl) throws SolrServerException, IOException { // Map<String, ResponseWrapper<ImageDTO>> map=new HashMap<String, // ResponseWrapper<ImageDTO>>(); // String queryString = "q=gene_accession_id:\"" + mgiAccession + // "\"&fq=" + ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":" + // experimentOrControl+"&facet=true&facet.field=procedure_name&facet.mincount=1"; // log.debug("queryString in ImageService getFacets=" + queryString); // make a facet request first to get the procedures and then reuturn // make requests for each procedure // http://wwwdev.ebi.ac.uk/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:2384986%22&&fq=biological_sample_group:experimental&facet=true&facet.field=procedure_name SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + mgiAccession + "\""); solrQuery.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":" + experimentOrControl); solrQuery.setFacetMinCount(1); solrQuery.setFacet(true);//from w w w. ja v a2 s . c om solrQuery.addFacetField("procedure_name"); // solrQuery.setRows(0); QueryResponse response = impcImagesCore.query(solrQuery); return response; }
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
public QueryResponse getParameterFacetsForGeneByProcedure(String acc, String procedureName, String controlOrExperimental) throws SolrServerException, IOException { // e.g./*from w w w . jav a 2s. com*/ // http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/query?q=gene_accession_id:%22MGI:2384986%22&fq=biological_sample_group:experimental&fq=procedure_name:X-ray&facet=true&facet.field=parameter_stable_id SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery("gene_accession_id:\"" + acc + "\""); solrQuery.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":" + controlOrExperimental); solrQuery.setFacetMinCount(1); solrQuery.setFacet(true); solrQuery.addFilterQuery(ObservationDTO.PROCEDURE_NAME + ":\"" + procedureName + "\""); solrQuery.addFacetField(ObservationDTO.PARAMETER_STABLE_ID); // solrQuery.setRows(0); QueryResponse response = impcImagesCore.query(solrQuery); return response; }
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
/** * * @param acc//w w w . j a va 2 s. c om * @return a map containing the mp and colony_id combinations so that if we have these then we show an image link on the phenotype table on the gene page. Each row in table could have a different colony_id as well as mp id * @throws SolrServerException, IOException */ public Map<String, Set<String>> getImagePropertiesThatHaveMp(String acc) throws SolrServerException, IOException { //http://ves-ebi-d0.ebi.ac.uk:8090/mi/impc/dev/solr/impc_images/select?q=gene_accession_id:%22MGI:1913955%22&fq=mp_id:*&facet=true&facet.mincount=1&facet.limit=-1&facet.field=colony_id&facet.field=mp_id&facet.field=mp_term&rows=0 Map<String, Set<String>> mpToColony = new HashMap<>(); SolrQuery query = new SolrQuery(); query.setQuery(ImageDTO.GENE_ACCESSION_ID + ":\"" + acc + "\"").setRows(100000000); query.addFilterQuery(ImageDTO.MP_ID_TERM + ":*"); query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); String pivotFacet = ImageDTO.MP_ID_TERM + "," + ImageDTO.COLONY_ID; query.set("facet.pivot", pivotFacet); query.addFacetField(ObservationDTO.COLONY_ID); logger.debug("solr query for images properties for mp = " + query); QueryResponse response = impcImagesCore.query(query); for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) { if (pivot.getPivot() != null) { //logger.info("pivot="+pivot.getValue()); String mpIdAndName = pivot.getValue().toString(); //logger.info("mpIdAndName" +mpIdAndName); String mpId = ""; Set<String> colonIds = new TreeSet<>(); if (mpIdAndName.contains("_")) { mpId = (mpIdAndName.split("_")[0]); } for (PivotField mp : pivot.getPivot()) { //logger.info("adding mp="+pivot.getValue()+" adding value="+mp.getValue()); String colonyId = mp.getValue().toString(); colonIds.add(colonyId); } mpToColony.put(mpId, colonIds); } } return mpToColony; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public List<String> getGenesWithMoreProcedures(int n, List<String> resourceName) throws SolrServerException, IOException, InterruptedException, ExecutionException { List<String> genes = new ArrayList<>(); SolrQuery q = new SolrQuery(); if (resourceName != null) { q.setQuery(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); } else {/*from w w w.j ava2s. com*/ q.setQuery("*:*"); } String geneProcedurePivot = ObservationDTO.GENE_SYMBOL + "," + ObservationDTO.PROCEDURE_NAME; q.add("facet.pivot", geneProcedurePivot); q.setFacet(true); q.setRows(1); q.setFacetMinCount(1); q.set("facet.limit", -1); logger.info("Solr url for getOverviewGenesWithMoreProceduresThan " + SolrUtils.getBaseURL(experimentCore) + "/select?" + q); QueryResponse response = experimentCore.query(q); for (PivotField pivot : response.getFacetPivot().get(geneProcedurePivot)) { if (pivot.getPivot() != null) { if (pivot.getPivot().size() >= n) { genes.add(pivot.getValue().toString()); } } } return genes; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
/** * Returns a map of categories, faceted by the given pivot, indexed by category, comprising # Genes and Gene Symbols * * @param resources/*from w w w.j ava 2s . c o m*/ * @param parameterStableIds A list of parameter_stable_id values (e.g. IMPC_VIA_001_001) * @param pivot A comma-separated string of solr fields to pivot the facet by (e.g. category,gene_symbol) * @return a map of categories, faceted by the given pivot, indexed by category, comprising # Genes and Gene Symbols * @throws SolrServerException, IOException */ public List<Map<String, String>> getCategories(List<String> resources, List<String> parameterStableIds, String pivot) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); if ((resources != null) && (!resources.isEmpty())) { query.setFilterQueries(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resources, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); } if ((parameterStableIds != null) && (!parameterStableIds.isEmpty())) { query.setQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + StringUtils.join(parameterStableIds, " OR " + ObservationDTO.PARAMETER_STABLE_ID + ":")); } query.setRows(0); query.setFacet(true); query.setFacetMinCount(1); query.setFacetLimit(-1); query.set("facet.pivot", pivot); logger.info("getCategories Url: " + SolrUtils.getBaseURL(experimentCore) + "/select?" + query); return getFacetPivotResults(experimentCore.query(query), false); }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public Map<String, Set<String>> getColoniesByPhenotypingCenter(List<String> resourceName, ZygosityType zygosity) throws SolrServerException, IOException, InterruptedException { Map<String, Set<String>> res = new HashMap<>(); SolrQuery q = new SolrQuery(); String pivotFacet = ObservationDTO.PHENOTYPING_CENTER + "," + ObservationDTO.COLONY_ID; NamedList<List<PivotField>> response; if (resourceName != null) { q.setQuery(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); } else {//from www.jav a 2s . c o m q.setQuery("*:*"); } if (zygosity != null) { q.addFilterQuery(ObservationDTO.ZYGOSITY + ":" + zygosity.name()); } q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental"); q.addFacetPivotField(pivotFacet); q.setFacet(true); q.setFacetLimit(-1); q.setFacetMinCount(1); q.setRows(0); try { response = experimentCore.query(q).getFacetPivot(); for (PivotField genePivot : response.get(pivotFacet)) { if (genePivot.getPivot() != null) { String center = genePivot.getValue().toString(); HashSet<String> colonies = new HashSet<>(); for (PivotField f : genePivot.getPivot()) { colonies.add(f.getValue().toString()); } res.put(center, colonies); } } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
/** * Returns a collection of biological sample ids for all mice matching the PROCEDURE_STABLE_ID. * * @param procedureStableId the procedure stable id (e.g. "IMPC_CAL_*" or "IMPC_IPG_*") * * @return a collection of biological sample ids for all mice matching the PROCEDURE_STABLE_ID * * @throws SolrServerException, IOException */// w w w. j av a2 s . c o m public Collection<String> getMetabolismReportBiologicalSampleIds(String procedureStableId) throws SolrServerException, IOException { SolrQuery query = new SolrQuery(); query.setQuery(String.format("%s:%s", ObservationDTO.PROCEDURE_STABLE_ID, procedureStableId)); query.setRows(0); query.setFacetMinCount(1); query.setFacetLimit(100000); query.addFacetField(ObservationDTO.BIOLOGICAL_SAMPLE_ID); logger.info(SolrUtils.getBaseURL(experimentCore) + "/select?" + query); return getFacets(experimentCore.query(query)).get(ObservationDTO.BIOLOGICAL_SAMPLE_ID).keySet(); }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public Set<String> getAllGeneIdsByResource(List<String> resourceName, boolean experimentalOnly) { SolrQuery q = new SolrQuery(); q.setFacet(true);/*from w w w. j av a 2s.c o m*/ q.setFacetMinCount(1); q.setFacetLimit(-1); q.setRows(0); q.addFacetField(ObservationDTO.GENE_ACCESSION_ID); if (resourceName != null) { q.setQuery(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); } else { q.setQuery("*:*"); } if (experimentalOnly) { q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental"); } logger.info("Solr URL getAllGeneIdsByResource " + SolrUtils.getBaseURL(experimentCore) + "/select?" + q); try { return getFacets(experimentCore.query(q)).get(ObservationDTO.GENE_ACCESSION_ID).keySet(); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public Set<String> getAllColonyIdsByResource(List<String> resourceName, boolean experimentalOnly) { SolrQuery q = new SolrQuery(); q.setFacet(true);//from w w w . j ava 2 s. co m q.setFacetMinCount(1); q.setFacetLimit(-1); q.setRows(0); q.addFacetField(ObservationDTO.COLONY_ID); if (resourceName != null) { q.setQuery(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); } else { q.setQuery("*:*"); } if (experimentalOnly) { q.addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental"); } logger.info("Solr URL getAllColonyIdsByResource " + SolrUtils.getBaseURL(experimentCore) + "/select?" + q); try { return getFacets(experimentCore.query(q)).get(ObservationDTO.COLONY_ID).keySet(); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
public Map<String, Long> getColoniesNoMPHit(List<String> resourceName, ZygosityType zygosity) throws SolrServerException, IOException { Map<String, Long> res = new HashMap<>(); SolrQuery q = new SolrQuery(); if (resourceName != null) { q.setQuery(GenotypePhenotypeDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + GenotypePhenotypeDTO.RESOURCE_NAME + ":")); } else {/* w ww.jav a 2 s. c o m*/ q.setQuery("*:*"); } if (zygosity != null) { q.addFilterQuery(GenotypePhenotypeDTO.ZYGOSITY + ":" + zygosity.name()); } q.addFilterQuery( GenotypePhenotypeDTO.P_VALUE + ":[" + StatisticalResultService.P_VALUE_THRESHOLD + " TO 1]"); q.addFacetField(StatisticalResultDTO.COLONY_ID); q.setFacetMinCount(1); q.setFacet(true); q.setRows(1); q.set("facet.limit", -1); logger.info( "Solr url for getColoniesNoMPHit " + SolrUtils.getBaseURL(statisticalResultCore) + "/select?" + q); QueryResponse response = statisticalResultCore.query(q); for (Count facet : response.getFacetField(StatisticalResultDTO.COLONY_ID).getValues()) { res.put(facet.getName(), facet.getCount()); } return res; }