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.GenotypePhenotypeService.java
License:Apache License
/** * * @param mpId//from w w w. j av a 2 s .com * @param filterOnAccessions list of marker accessions to restrict the results by e.g. for the hearing page we only want results for the 67 genes for the paper * @return * @throws JSONException */ public JSONArray getTopLevelPhenotypeIntersection(String mpId, Set<String> filterOnAccessions) throws JSONException { String pivot = GenotypePhenotypeDTO.MARKER_ACCESSION_ID + "," + GenotypePhenotypeDTO.MARKER_SYMBOL; SolrQuery query = new SolrQuery(); query.setQuery(mpId == null ? "*:*" : GenotypePhenotypeDTO.MP_TERM_ID + ":\"" + mpId + "\" OR " + GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + mpId + "\" OR " + GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + mpId + "\""); query.setRows(0); query.setFacet(true); query.addFacetField(GenotypePhenotypeDTO.MARKER_ACCESSION_ID); query.setFacetLimit(-1); query.setFacetMinCount(1); query.add("facet.pivot", pivot); try { QueryResponse response = genotypePhenotypeCore.query(query); Map<String, Long> countByGene = getFacets(response).get(GenotypePhenotypeDTO.MARKER_ACCESSION_ID); Map<String, List<String>> geneAccSymbol = getFacetPivotResults(response, pivot); Set<String> jitter = new HashSet<>(); JSONArray array = new JSONArray(); for (String markerAcc : countByGene.keySet()) { JSONObject obj = new JSONObject(); Double y = new Double(countByGene.get(markerAcc)); Double x = (getDocumentCountByMgiGeneAccessionId().get(markerAcc) - y); obj = addJitter(x, y, jitter, obj); obj.accumulate("markerAcc", markerAcc); obj.accumulate("markerSymbol", geneAccSymbol.get(markerAcc).get(0)); if (filterOnAccessions != null && filterOnAccessions.contains(markerAcc)) { array.put(obj); } else if (filterOnAccessions == null) { array.put(obj); } } return array; } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
public Map<String, Set<String>> getFacets(String anatomyId) throws SolrServerException, IOException { Map<String, Set<String>> res = new HashMap<>(); SolrQuery query = new SolrQuery(); query.setQuery(ImageDTO.PROCEDURE_NAME + ":*LacZ"); if (anatomyId != null) { query.addFilterQuery("(" + ImageDTO.ANATOMY_ID + ":\"" + anatomyId + "\" OR " + ImageDTO.INTERMEDIATE_ANATOMY_ID + ":\"" + anatomyId + "\" OR " + ImageDTO.SELECTED_TOP_LEVEL_ANATOMY_ID + ":\"" + anatomyId + "\")"); }/*from w w w.j ava 2 s .c om*/ query.addFilterQuery(ImageDTO.BIOLOGICAL_SAMPLE_GROUP + ":\"experimental\"") .addFilterQuery("(" + ImageDTO.PARAMETER_ASSOCIATION_VALUE + ":\"no expression\" OR " + ObservationDTO.PARAMETER_ASSOCIATION_VALUE + ":\"expression\"" + ")"); // only have expressed and // not expressed ingnore // ambiguous and no tissue query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); query.addFacetField(ImageDTO.ANATOMY_TERM); query.addFacetField(ImageDTO.PHENOTYPING_CENTER); query.addFacetField(ImageDTO.PROCEDURE_NAME); query.addFacetField(ImageDTO.PARAMETER_ASSOCIATION_VALUE); QueryResponse response = impcImagesCore.query(query); for (FacetField facetField : response.getFacetFields()) { Set<String> filter = new TreeSet<>(); for (Count facet : facetField.getValues()) { if (!facet.getName().equals("tissue not available") && !facet.getName().equals("ambiguous")) { filter.add(facet.getName()); } } res.put(facetField.getName(), filter); } return res; }
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
public List<String[]> getLaczExpressionSpreadsheet(String imageCollectionLinkBase) { SolrQuery query = new SolrQuery(); ArrayList<String[]> res = new ArrayList<>(); String[] aux = new String[0]; query.setQuery(ImageDTO.PROCEDURE_NAME + ":\"Adult LacZ\" AND " + ImageDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental"); query.setRows(1000000);// w w w .j a v a 2 s. com query.addField(ImageDTO.GENE_SYMBOL); query.addField(ImageDTO.GENE_ACCESSION_ID); query.addField(ImageDTO.ALLELE_SYMBOL); query.addField(ImageDTO.COLONY_ID); query.addField(ImageDTO.BIOLOGICAL_SAMPLE_ID); query.addField(ImageDTO.ZYGOSITY); query.addField(ImageDTO.SEX); query.addField(ImageDTO.PARAMETER_ASSOCIATION_NAME); query.addField(ImageDTO.PARAMETER_STABLE_ID); query.addField(ImageDTO.PARAMETER_ASSOCIATION_VALUE); query.addField(ImageDTO.GENE_ACCESSION_ID); query.addField(ImageDTO.PHENOTYPING_CENTER); query.setFacet(true); query.setFacetLimit(100); query.addFacetField(ImageDTO.PARAMETER_ASSOCIATION_NAME); query.set("group", true); query.set("group.limit", 100000); query.set("group.field", ImageDTO.BIOLOGICAL_SAMPLE_ID); try { QueryResponse solrResult = impcImagesCore.query(query); ArrayList<String> allParameters = new ArrayList<>(); List<String> header = new ArrayList<>(); header.add("Gene Symbol"); header.add("MGI Gene Id"); header.add("Allele Symbol"); header.add("Colony Id"); header.add("Biological Sample Id"); header.add("Zygosity"); header.add("Sex"); header.add("Phenotyping Centre"); logger.info(SolrUtils.getBaseURL(impcImagesCore) + "/select?" + query); // Get facets as we need to turn them into columns for (Count facet : solrResult.getFacetField(ImageDTO.PARAMETER_ASSOCIATION_NAME).getValues()) { allParameters.add(facet.getName()); header.add(facet.getName()); } header.add("image_collection_link"); res.add(header.toArray(aux)); for (Group group : solrResult.getGroupResponse().getValues().get(0).getValues()) { List<String> row = new ArrayList<>(); ArrayList<String> params = new ArrayList<>(); ArrayList<String> paramValues = new ArrayList<>(); String urlToImagePicker = imageCollectionLinkBase + "/imageComparator?acc="; for (SolrDocument doc : group.getResult()) { if (row.size() == 0) { row.add(doc.getFieldValues(ImageDTO.GENE_SYMBOL).iterator().next().toString()); row.add(doc.getFieldValues(ImageDTO.GENE_ACCESSION_ID).iterator().next().toString()); urlToImagePicker += doc.getFieldValue(ImageDTO.GENE_ACCESSION_ID) + "¶meter_stable_id="; urlToImagePicker += doc.getFieldValue(ImageDTO.PARAMETER_STABLE_ID); if (doc.getFieldValue(ImageDTO.ALLELE_SYMBOL) != null) { row.add(doc.getFieldValue(ImageDTO.ALLELE_SYMBOL).toString()); } row.add(doc.getFieldValue(ImageDTO.COLONY_ID).toString()); row.add(doc.getFieldValue(ImageDTO.BIOLOGICAL_SAMPLE_ID).toString()); if (doc.getFieldValue(ImageDTO.ZYGOSITY) != null) { row.add(doc.getFieldValue(ImageDTO.ZYGOSITY).toString()); } row.add(doc.getFieldValue(ImageDTO.SEX).toString()); row.add(doc.getFieldValue(ImageDTO.PHENOTYPING_CENTER).toString()); } if (doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME) != null) { for (int i = 0; i < doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME).size(); i++) { params.add(doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_NAME) .toArray(new Object[0])[i].toString()); if (doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_VALUE) != null) { paramValues.add(doc.getFieldValues(ImageDTO.PARAMETER_ASSOCIATION_VALUE) .toArray(new Object[0])[i].toString()); } else { paramValues.add(Constants.NO_INFORMATION_AVAILABLE); } } } } for (String tissue : allParameters) { if (params.contains(tissue)) { row.add(paramValues.get(params.indexOf(tissue))); } else { row.add(""); } } row.add(urlToImagePicker); res.add(row.toArray(aux)); } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
From source file:org.mousephenotype.cda.solr.service.ImageService.java
License:Apache License
/** * * @param acc/*w w w . j av a2 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.ImpressService.java
License:Apache License
/** * @author tudose/*from ww w.j a v a2s. c o 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
/** * Returns a map of categories, faceted by the given pivot, indexed by category, comprising # Genes and Gene Symbols * * @param resources/*w ww .j a v a 2 s .co 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 av a 2 s . c om 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. ja v a2s .co 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 ww.j a v a2 s .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);/*w w w . j a v a 2s .c om*/ 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; }