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.ImpressService.java
License:Apache License
/** * @author tudose/*from w w w .ja v a 2 s. co m*/ * @since 2015/09/25 * @return List< [(Procedure, parameter, observationNumber)]> */ public List<String[]> getProcedureParameterList() { List<String[]> result = new ArrayList<>(); SolrQuery q = new SolrQuery(); q.setQuery("*:*"); q.setFacet(true); q.setFacetLimit(-1); q.setRows(0); String pivotFacet = ImpressDTO.PROCEDURE_STABLE_ID + "," + ImpressDTO.PARAMETER_STABLE_ID; q.set("facet.pivot", pivotFacet); try { QueryResponse res = pipelineCore.query(q); for (PivotField pivot : res.getFacetPivot().get(pivotFacet)) { if (pivot.getPivot() != null) { for (PivotField parameter : pivot.getPivot()) { String[] row = { pivot.getValue().toString(), parameter.getValue().toString() }; result.add(row); } } } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return result; }
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 a va2 s .co m*/ 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// www . j a v a2 s . 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 w w w . j a v a2s.co 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
public Set<String> getAllGeneIdsByResource(List<String> resourceName, boolean experimentalOnly) { SolrQuery q = new SolrQuery(); q.setFacet(true); q.setFacetMinCount(1);//from www . j a va 2 s . c o m 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); q.setFacetMinCount(1);/*from w w w. j a va 2 s.c o m*/ 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.ObservationService.java
License:Apache License
public NamedList<List<PivotField>> getHistopathGeneParameterNameCategoryPivots() throws SolrServerException, IOException { //http://ves-hx-d1.ebi.ac.uk:8986/solr/experiment/select?q=*:*&rows=0&sort=id+asc&fq=parameter_stable_id:*HIS*&facet=true&facet.pivot=gene_symbol,category&facet.limit=-1 //we need the significance score only can't filter based on a parameter ids as all different for each anatomy but can do search for "Significance score " in parameter_name string SolrQuery q = new SolrQuery().setQuery("*:*").setRows(0)//we don't care about the observations themselfs so don't return them only which anatomy has significant Histopath data on which genes. .setSort(ObservationDTO.ID, SolrQuery.ORDER.asc) //.setFields(fields) .addFilterQuery("parameter_stable_id:*HIS*").addFilterQuery("parameter_name:*Significance*");//.addFilterQuery("gene_symbol:Prkab1"); //.addFilterQuery("category:Significant"); //.addFilterQuery("category:Significant");//otherwise query takes too long q.setFacet(true); String pivotFacet = ObservationDTO.GENE_SYMBOL + "," + ObservationDTO.PARAMETER_NAME + "," + ObservationDTO.CATEGORY;/*from w w w. j a va 2 s. c om*/ q.add("facet.pivot", pivotFacet); q.setFacetLimit(-1); System.out.println("solr query in getObservationByProcedureNameAndGene=" + q); return experimentCore.query(q).getFacetPivot(); }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public Set<String> getChartPivots(String baseUrl, String acc, ParameterDTO parameter, List<String> pipelineStableIds, List<String> zyList, List<String> phenotypingCentersList, List<String> strainsParams, List<String> metaDataGroup, List<String> alleleAccession) throws IOException, SolrServerException, URISyntaxException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); if (acc != null) { query.addFilterQuery("gene_accession_id" + ":\"" + acc + "\""); }//from w w w .ja v a 2 s. co m if (parameter != null) { query.addFilterQuery(StatisticalResultDTO.PARAMETER_STABLE_ID + ":" + parameter.getStableId()); } if (pipelineStableIds != null && pipelineStableIds.size() > 0) { query.addFilterQuery(pipelineStableIds.stream() .collect(Collectors.joining(" OR ", StatisticalResultDTO.PIPELINE_STABLE_ID + ":(", ")"))); } if (zyList != null && zyList.size() > 0) { query.addFilterQuery( zyList.stream().collect(Collectors.joining(" OR ", StatisticalResultDTO.ZYGOSITY + ":(", ")"))); } if (phenotypingCentersList != null && phenotypingCentersList.size() > 0) { query.addFilterQuery(phenotypingCentersList.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.PHENOTYPING_CENTER + ":(\"", "\")"))); } if (strainsParams != null && strainsParams.size() > 0) { query.addFilterQuery(strainsParams.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.STRAIN_ACCESSION_ID + ":(\"", "\")"))); } if (metaDataGroup != null && metaDataGroup.size() > 0) { query.addFilterQuery(metaDataGroup.stream() .collect(Collectors.joining("\" OR \"", StatisticalResultDTO.METADATA_GROUP + ":(\"", "\")"))); } if (alleleAccession != null && alleleAccession.size() > 0) { query.addFilterQuery(alleleAccession.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.ALLELE_ACCESSION_ID + ":(\"", "\")"))); } query.setFacet(true); // If you add/change order of pivots, make sure you do the same in the for loops below String pivotFacet = StatisticalResultDTO.PIPELINE_STABLE_ID + "," + StatisticalResultDTO.ZYGOSITY + "," + StatisticalResultDTO.PHENOTYPING_CENTER + "," + StatisticalResultDTO.STRAIN_ACCESSION_ID + "," + StatisticalResultDTO.ALLELE_ACCESSION_ID; if (metaDataGroup != null && metaDataGroup.size() > 0) { pivotFacet += "," + StatisticalResultDTO.METADATA_GROUP; } query.add("facet.pivot", pivotFacet); query.setFacetLimit(-1); Set<String> resultParametersForCharts = new HashSet<>(); NamedList<List<PivotField>> facetPivot = experimentCore.query(query).getFacetPivot(); for (PivotField pivot : facetPivot.get(pivotFacet)) { getParametersForChartFromPivot(pivot, baseUrl, resultParametersForCharts); } return resultParametersForCharts; }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
public Set<String> getChartPivots(String baseUrl, String acc, String parameterStableId, List<String> pipelineStableIds, List<String> zyList, List<String> phenotypingCentersList, List<String> strainsParams, List<String> metaDataGroup, List<String> alleleAccession) throws IOException, SolrServerException, URISyntaxException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); if (acc != null) { query.addFilterQuery(StatisticalResultDTO.MARKER_ACCESSION_ID + ":\"" + acc + "\""); }//from w w w .ja va 2 s .com if ((parameterStableId != null) && (!parameterStableId.trim().isEmpty())) { query.addFilterQuery(StatisticalResultDTO.PARAMETER_STABLE_ID + ":" + parameterStableId); } if (pipelineStableIds != null & pipelineStableIds.size() > 0) { query.addFilterQuery(pipelineStableIds.stream() .collect(Collectors.joining(" OR ", StatisticalResultDTO.PIPELINE_STABLE_ID + ":(", ")"))); } if (zyList != null && zyList.size() > 0) { query.addFilterQuery( zyList.stream().collect(Collectors.joining(" OR ", StatisticalResultDTO.ZYGOSITY + ":(", ")"))); } if (phenotypingCentersList != null && phenotypingCentersList.size() > 0) { query.addFilterQuery(phenotypingCentersList.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.PHENOTYPING_CENTER + ":(\"", "\")"))); } if (strainsParams != null && strainsParams.size() > 0) { query.addFilterQuery(strainsParams.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.STRAIN_ACCESSION_ID + ":(\"", "\")"))); } if (metaDataGroup != null && metaDataGroup.size() > 0) { query.addFilterQuery(metaDataGroup.stream() .collect(Collectors.joining("\" OR \"", StatisticalResultDTO.METADATA_GROUP + ":(\"", "\")"))); } if (alleleAccession != null && alleleAccession.size() > 0) { query.addFilterQuery(alleleAccession.stream().collect( Collectors.joining("\" OR \"", StatisticalResultDTO.ALLELE_ACCESSION_ID + ":(\"", "\")"))); } query.setFacet(true); // If you add/change order of pivots, make sure you do the same in the for loops below String pivotFacet = StatisticalResultDTO.PIPELINE_STABLE_ID + "," + StatisticalResultDTO.ZYGOSITY + "," + StatisticalResultDTO.PHENOTYPING_CENTER + "," + StatisticalResultDTO.STRAIN_ACCESSION_ID + "," + StatisticalResultDTO.ALLELE_ACCESSION_ID; //pivot needs to have metadata_group irrespective of if it's included in filter or not as we want seperate experiments based on the metadata pivotFacet += "," + StatisticalResultDTO.METADATA_GROUP; //} query.add("facet.pivot", pivotFacet); query.setFacetLimit(-1); Set<String> resultParametersForCharts = new HashSet<>(); System.out.println("SR facet pivot query=" + query); NamedList<List<PivotField>> facetPivot = statisticalResultCore.query(query).getFacetPivot(); for (PivotField pivot : facetPivot.get(pivotFacet)) { getParametersForChartFromPivot(pivot, baseUrl, resultParametersForCharts); } return resultParametersForCharts; }
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 {//from w w w . ja v a 2 s . co 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; }