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.GenotypePhenotypeService.java
License:Apache License
/** * @param mpTermName// ww w .java 2 s .c o m * @param resource * @return map <colony_id, occurences> */ public Map<String, Long> getAssociationsDistribution(String mpTermName, String resource) { String query = GenotypePhenotypeDTO.MP_TERM_NAME + ":\"" + mpTermName + "\""; if (resource != null) { query += " AND " + GenotypePhenotypeDTO.RESOURCE_NAME + ":" + resource; } SolrQuery q = new SolrQuery(); q.setQuery(query); q.setFacet(true); q.setFacetMinCount(1); q.addFacetField(GenotypePhenotypeDTO.COLONY_ID); try { return (getFacets(genotypePhenotypeCore.query(q))).get(GenotypePhenotypeDTO.COLONY_ID); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
public Set<String> getFertilityAssociatedMps() { SolrQuery q = new SolrQuery(); q.setQuery(GenotypePhenotypeDTO.PARAMETER_STABLE_ID + ":*_FER_*"); q.setFacet(true); q.setFacetMinCount(1);//from www .j av a2s . co m q.addFacetField(GenotypePhenotypeDTO.MP_TERM_NAME); try { return (getFacets(genotypePhenotypeCore.query(q))).get(GenotypePhenotypeDTO.MP_TERM_NAME).keySet(); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
/** * @author ilinca//from ww w . j a va 2s.co 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 w w w . ja v a 2 s . c om*/ 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<>(); }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
/** * * @param mpId/*from w w w . j av a 2 s . c o m*/ * @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 a v a 2 s .co m*/ 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 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);// w w w.j av a2 s . com solrQuery.setFacet(true); 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 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);//from www.ja v a 2 s .c om 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
public QueryResponse getParameterFacetsForGeneByProcedure(String acc, String procedureName, String controlOrExperimental) throws SolrServerException, IOException { // e.g.//from w w w .j a v a2s . c o m // 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//from w w w .j a va2 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; }