List of usage examples for org.apache.solr.client.solrj SolrQuery addField
public SolrQuery addField(String field)
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
/** * Returns a <code>QueryResponse</code> of data found using the given resources, parameter stable ids, and category * comprising geneSymbol, geneAccessionId, colonyId, and category. * * @param resources/* w ww . j a v a2s . co m*/ * @param parameterStableIds A list of parameter stable ids that is "or'd" together to produce the result (e.g. IMPC_VIA_001_001) * @param categories A list of categories that is "or'd" together to produce the result (e.g. Viable, Lethal, Male, Fertile) * @return a <code>QueryResponse</code> of data found using the given resources, parameter stable ids, and category, * comprising geneSymbol, geneAccessionId, colonyId, and category. * @throws SolrServerException, IOException */ public QueryResponse getData(List<String> resources, List<String> parameterStableIds, List<String> categories) 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 ((categories != null) && (!categories.isEmpty())) { query.setFilterQueries(ObservationDTO.CATEGORY + ":" + StringUtils.join(categories, " OR " + ObservationDTO.CATEGORY + ":")); } if ((parameterStableIds != null) && (!parameterStableIds.isEmpty())) { query.setQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + StringUtils.join(parameterStableIds, " OR " + ObservationDTO.PARAMETER_STABLE_ID + ":")); } query.addField(ObservationDTO.GENE_SYMBOL); query.addField(ObservationDTO.GENE_ACCESSION_ID); query.addField(ObservationDTO.ALLELE_SYMBOL); query.addField(ObservationDTO.ALLELE_ACCESSION_ID); query.addField(ObservationDTO.PHENOTYPING_CENTER); query.addField(ObservationDTO.COLONY_ID); query.addField(ObservationDTO.CATEGORY); query.addField(ObservationDTO.SEX); query.addField(ObservationDTO.ZYGOSITY); query.setSort(ObservationDTO.ID, SolrQuery.ORDER.asc); query.setRows(1000000); logger.info("getData Url: " + SolrUtils.getBaseURL(experimentCore) + "/select?" + query); return experimentCore.query(query); }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
/** * * @param geneAccessionId//from w ww. ja v a 2 s .c o m * @return Basic information for allele pages in an AllelePageDTO */ public AllelePageDTO getAllelesInfo(String geneAccessionId, List<String> alleleSymbol, List<String> phenotypingCenter, List<String> pipelineName, List<String> procedureStableId, List<String> procedureName, List<String> mpTermIds, ArrayList<String> resource) { AllelePageDTO dto = new AllelePageDTO(); SolrQuery q = buildQuery(geneAccessionId, procedureName, alleleSymbol, phenotypingCenter, pipelineName, procedureStableId, resource, mpTermIds, null, null, null, null, null, null, null, null); q.addField(StatisticalResultDTO.MARKER_SYMBOL); q.addField(StatisticalResultDTO.MARKER_ACCESSION_ID); q.addFilterQuery(StatisticalResultDTO.P_VALUE + ":[* TO *]"); q.setFacet(true); q.setFacetLimit(-1); q.setFacetMinCount(1); q.addFacetField(StatisticalResultDTO.PHENOTYPING_CENTER); q.addFacetField(StatisticalResultDTO.PIPELINE_NAME); q.addFacetField(StatisticalResultDTO.ALLELE_SYMBOL); q.setRows(1); String pivotFacet = StatisticalResultDTO.PROCEDURE_NAME + "," + StatisticalResultDTO.PARAMETER_STABLE_ID; q.set("facet.pivot", pivotFacet); q.set("facet.pivot.mincount", 1); try { QueryResponse res = statisticalResultCore.query(q); FacetField phenotypingCenters = res.getFacetField(StatisticalResultDTO.PHENOTYPING_CENTER); for (Count facet : phenotypingCenters.getValues()) { dto.addPhenotypingCenter(facet.getName()); } FacetField alleles = statisticalResultCore.query(q).getFacetField(StatisticalResultDTO.ALLELE_SYMBOL); for (Count facet : alleles.getValues()) { dto.addAlleleSymbol(facet.getName()); } FacetField pipelines = statisticalResultCore.query(q).getFacetField(StatisticalResultDTO.PIPELINE_NAME); for (Count facet : pipelines.getValues()) { dto.addPipelineName(facet.getName()); } for (PivotField pivot : res.getFacetPivot().get(pivotFacet)) { if (pivot.getPivot() != null) { List<String> lst = new ArrayList<>(); for (PivotField gene : pivot.getPivot()) { lst.add(gene.getValue().toString()); } dto.addParametersByProcedure(pivot.getValue().toString(), new ArrayList<>(lst)); dto.addProcedureNames(pivot.getValue().toString()); } } SolrDocument doc = res.getResults().get(0); dto.setGeneSymbol(doc.getFieldValue(StatisticalResultDTO.MARKER_SYMBOL).toString()); dto.setGeneAccession(geneAccessionId); } catch (SolrServerException | IOException e) { e.printStackTrace(); } return dto; }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
public TreeMap<String, ParallelCoordinatesDTO> getGenotypeEffectFor(List<String> procedureStableId, List<String> phenotypingCenters, Boolean requiredParamsOnly, String baseUrl, List<String> genes, String topLevelMpId) throws SolrServerException, IOException, URISyntaxException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); if (procedureStableId != null) { query.addFilterQuery(StatisticalResultDTO.PROCEDURE_STABLE_ID + ":" + StringUtils.join(procedureStableId, "* OR " + StatisticalResultDTO.PROCEDURE_STABLE_ID + ":") + "*"); }/*w w w .j a va 2s . c om*/ query.addFilterQuery(StatisticalResultDTO.DATA_TYPE + ":unidimensional"); query.setFacet(true); query.setFacetMinCount(1); query.setFacetLimit(-1); query.addFacetField(StatisticalResultDTO.PARAMETER_STABLE_ID); query.addFacetField(StatisticalResultDTO.PARAMETER_NAME); if (phenotypingCenters != null && phenotypingCenters.size() > 0) { query.addFilterQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + StringUtils .join(phenotypingCenters, "\" OR " + StatisticalResultDTO.PHENOTYPING_CENTER + ":\"") + "\""); } List<String> parameterStableIds = new ArrayList<>(getFacets(statisticalResultCore.query(query)) .get(StatisticalResultDTO.PARAMETER_STABLE_ID).keySet()); TreeSet<ParameterDTO> parameterUniqueByStableId = new TreeSet<>(ParameterDTO.getComparatorByName()); for (ParameterDTO param : impressService.getParameters(procedureStableId, "unidimensional", topLevelMpId)) { if (parameterStableIds.contains(param.getStableId()) && (param.isRequired() || !requiredParamsOnly) && !parameterUniqueByStableId.contains(param)) { parameterUniqueByStableId.add(param); } } List<ParameterDTO> parameters = new ArrayList<>(parameterUniqueByStableId); Map<String, ParameterDTO> parameterMap = new HashMap<>(); for (ParameterDTO p : parameterUniqueByStableId) { parameterMap.put(p.getStableId(), p); } query = new SolrQuery(); query.setQuery("-" + StatisticalResultDTO.STATISTICAL_METHOD + ":Wilcoxon*"); // Decided to omit Wilcoxon because it does not adjust for batch or center effect and the value for genotyope effect does not have the same meaning as for the other values. query.addFilterQuery(StatisticalResultDTO.PARAMETER_STABLE_ID + ":\"" + StringUtils.join(parameters.stream().map(ParameterDTO::getStableId).collect(Collectors.toList()), "\" OR " + StatisticalResultDTO.PARAMETER_STABLE_ID + ":\"") + "\""); query.addFilterQuery(StatisticalResultDTO.STATUS + ":Success"); query.addField(StatisticalResultDTO.GENOTYPE_EFFECT_PARAMETER_ESTIMATE); query.addField(StatisticalResultDTO.MARKER_ACCESSION_ID); query.addField(StatisticalResultDTO.PARAMETER_STABLE_ID); query.addField(StatisticalResultDTO.FEMALE_KO_PARAMETER_ESTIMATE); query.addField(StatisticalResultDTO.MALE_KO_PARAMETER_ESTIMATE); query.addField(StatisticalResultDTO.PHENOTYPING_CENTER); query.addField(StatisticalResultDTO.PROCEDURE_NAME); query.addField(StatisticalResultDTO.MARKER_SYMBOL); query.addField(StatisticalResultDTO.SIGNIFICANT); query.setRows(Integer.MAX_VALUE); query.setSort(StatisticalResultDTO.DOCUMENT_ID, SolrQuery.ORDER.asc); if (phenotypingCenters != null && phenotypingCenters.size() > 0) { query.addFilterQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + StringUtils .join(phenotypingCenters, "\" OR " + StatisticalResultDTO.PHENOTYPING_CENTER + ":\"") + "\""); } if (genes != null) { query.addFilterQuery(StatisticalResultDTO.MARKER_SYMBOL + ":(\"" + genes.stream().collect(Collectors.joining("\" OR \"")) + "\")"); } List<StatisticalResultDTO> result = statisticalResultCore.query(query, SolrRequest.METHOD.POST) .getBeans(StatisticalResultDTO.class); TreeMap<String, ParallelCoordinatesDTO> row = addMaxGenotypeEffects(result, parameterMap, baseUrl); row = addMeanValues(row, parameters); row = addDefaultValues(row, parameters); // add normal/no effect values after mean so that they're not used in the computation return row; }
From source file:org.vroyer.hive.solr.SolrTableCursor.java
License:Open Source License
private void fetchNextDocumentChunk() throws IOException { SolrQuery query = new SolrQuery(); query.setStart(start);//from w ww . ja v a2s . c om if (table.facetType == null) { query.setRows(Math.min(count, this.solrSplitSize)); for (String s : table.fields) { // Don't push solr_query, this is an internal column when a cassandra table is indexed by SOLR. if (!s.equalsIgnoreCase("solr_query")) { query.addField(s); } } } else { query.setRows(0); } List<NameValuePair> params = URLEncodedUtils.parse(table.qs, Charset.forName("UTF-8")); for (NameValuePair nvp : params) { query.set(nvp.getName(), nvp.getValue()); } if (table.fq.length() > 0) { query.set("fq", table.fq.toString()); } if (table.q.length() > 0) { query.set("q", table.q.toString()); } if (query.get("q") == null) { query.set("q", "*:*"); } if (log.isInfoEnabled()) { StringBuffer sb = new StringBuffer(""); Map<String, String[]> map = query.toMultiMap(query.toNamedList()); for (String s : map.keySet()) { sb.append(s).append('=').append(Arrays.toString(map.get(s))).append(' '); } log.info("SOLR request: " + sb.toString()); } checkRequiredFilterFields(); QueryResponse response; try { response = server.query(query); } catch (SolrServerException e) { throw new IOException(e); } if (table.facetType != null) { if (table.facetType.equalsIgnoreCase("ranges")) { List<RangeFacet.Count> counts = response.getFacetRanges().get(0).getCounts(); for (RangeFacet.Count rfc : counts) { facets.add(new FacetEntry(rfc.getValue(), rfc.getCount())); } } else if (table.facetType.equalsIgnoreCase("fields")) { List<FacetField.Count> counts = response.getFacetFields().get(0).getValues(); for (FacetField.Count rfc : counts) { facets.add(new FacetEntry(rfc.getName(), rfc.getCount())); } } else if (table.facetType.equalsIgnoreCase("queries")) { Map<String, Integer> queries = response.getFacetQuery(); for (String k : queries.keySet()) { facets.add(new FacetEntry(k, queries.get(k))); } } } else { buffer = response.getResults(); numFound = buffer.getNumFound(); log.info("SOLR response numFound=" + buffer.getNumFound()); start += buffer.size(); count -= buffer.size(); } pos = 0; }
From source file:solrbook.ch11.solrj.cli.command.SearchCommand.java
License:Apache License
@Override public void mainProcess(Map<String, Object> parameters) throws Exception { try {/* ww w . ja v a 2 s. com*/ /* * SolrQuery ? */ SolrQuery solrQuery = new SolrQuery(queryString); /* * ?? */ solrQuery.setStart(start); solrQuery.setRows(rows); /* * ?????? */ if (StringUtils.isNotEmpty(sortField) && StringUtils.isNotEmpty(sortOrder)) { /* * ????? */ solrQuery.setSort(sortField, Enum.valueOf(org.apache.solr.client.solrj.SolrQuery.ORDER.class, sortOrder)); } /* * ????? */ for (String f : fieldList.split(",")) { if (StringUtils.isNotEmpty(f)) { solrQuery.addField(f.trim()); } } /* * SolrClient ?? */ QueryResponse queryResponse = solrClient.query(solrQuery); /* * ??????? List ? */ List<Map<String, Object>> documentList = new LinkedList<Map<String, Object>>(); /* * ??? */ SolrDocumentList solrDocumentList = queryResponse.getResults(); /* * ??? */ for (SolrDocument solrDocument : solrDocumentList) { /* * ???? Map ? */ Map<String, Object> documentMap = new HashMap<String, Object>(); /* * ??????? */ for (String fieldName : solrDocument.getFieldNames()) { /* * ??? Map ? */ Object fieldValue = solrDocument.getFieldValue(fieldName); documentMap.put(fieldName, fieldValue); } /* * ? Map ? */ documentMap.put("score", solrDocument.getFieldValue("score")); /* * ??? */ documentList.add(documentMap); } /* * ????? */ response.put("QTime", queryResponse.getQTime()); /* * ???? */ response.put("maxScore", solrDocumentList.getMaxScore()); /* * ???? */ response.put("numFound", solrDocumentList.getNumFound()); /* * ???? */ response.put("result", documentList); status = STATUS_SUCCESS; message = SUCCESS_MESSAGE; } catch (Exception e) { /* * ???? */ status = STATUS_ERROR; message = e.getMessage(); } }
From source file:uk.ac.ebi.phenodigm2.WebDaoSolrImpl.java
License:Apache License
@Override public List<DiseaseGeneAssociation> getDiseaseToGeneAssociations(String diseaseId) { String query = String.format("%s:\"%s\"", PhenodigmDTO.DISEASE_ID, diseaseId); SolrQuery solrQuery = new SolrQuery(query); solrQuery.addField(PhenodigmDTO.MARKER_SYMBOLS_WITHDRAWN).addField(PhenodigmDTO.HGNC_GENE_SYMBOLS_WITHDRAWN) .addField(PhenodigmDTO.HGNC_GENE_LOCUS); completeDiseaseGeneQuery(solrQuery); List<DiseaseGeneAssociation> genes = new ArrayList<>(); try {// ww w. j a v a2 s .c o m // to avoid transfering the same ids more than once, keep a hashset // duplicate ids can occur with many-to-one human-mouse gene mappings HashSet<String> seenIds = new HashSet(); List<PhenodigmDTO> results = phenodigmCore.query(solrQuery).getBeans(PhenodigmDTO.class); for (PhenodigmDTO phenodigm : results) { // set mouse genes (orthologs to human genes) String markerId = phenodigm.getMarkerId(); String markerSymbol = phenodigm.getMarkerSymbol(); if (markerId != null && !seenIds.contains(markerId)) { DiseaseGeneAssociation assoc = new DiseaseGeneAssociation(markerId, markerSymbol, diseaseId); assoc.setSymbolsWithdrawn(phenodigm.getMarkerSymbolsWithdrawn()); assoc.setByOrthology(true); genes.add(assoc); seenIds.add(markerId); } // set human genes (human annotations) String humanId = phenodigm.getHgncGeneId(); String humanSymbol = phenodigm.getHgncGeneSymbol(); if (humanId != null && !seenIds.contains(humanId)) { DiseaseGeneAssociation assoc = new DiseaseGeneAssociation(humanId, humanSymbol, diseaseId); assoc.setSymbolsWithdrawn(phenodigm.getHgncGeneSymbolsWithdrawn()); assoc.setLocus(phenodigm.getHgncGeneLocus()); assoc.setByOrthology(false); genes.add(assoc); seenIds.add(humanId); } } } catch (SolrServerException | IOException e) { LOGGER.error(e.getMessage()); } return genes; }
From source file:uk.ac.ebi.phenodigm2.WebDaoSolrImpl.java
License:Apache License
@Override public List<GeneDiseaseAssociation> getGeneToDiseaseAssociations(String geneId) { String query = String.format("%s:\"%s\" OR %s:\"%s\"", PhenodigmDTO.MARKER_ID, geneId, PhenodigmDTO.HGNC_GENE_ID, geneId); SolrQuery solrQuery = new SolrQuery(query); solrQuery.addField(PhenodigmDTO.DISEASE_ID).addField(PhenodigmDTO.DISEASE_TERM); completeDiseaseGeneQuery(solrQuery); List<GeneDiseaseAssociation> diseases = new ArrayList<>(); try {// w w w .j av a2s . com List<PhenodigmDTO> results = phenodigmCore.query(solrQuery).getBeans(PhenodigmDTO.class); for (PhenodigmDTO phenodigm : results) { GeneDiseaseAssociation assoc = new GeneDiseaseAssociation(phenodigm.getDiseaseId(), geneId); assoc.setTerm(phenodigm.getDiseaseTerm()); // set mouse genes (orthologs to human genes) String markerId = phenodigm.getMarkerId(); if (markerId != null && geneId.equals(markerId)) { assoc.setByOrthology(true); //LOGGER.info("Found an association: " + assoc.toString()); diseases.add(assoc); } // set human genes (human annotations) String humanId = phenodigm.getHgncGeneId(); if (humanId != null && geneId.equals(humanId)) { assoc.setByOrthology(false); //LOGGER.info("Found an association: " + assoc.toString()); diseases.add(assoc); } } } catch (SolrServerException | IOException e) { LOGGER.error(e.getMessage()); } return diseases; }
From source file:uk.ac.ebi.phenodigm2.WebDaoSolrImpl.java
License:Apache License
@Override public List<DiseaseModelAssociation> getDiseaseToModelModelAssociations(String diseaseId) { String query = String.format("%s:\"%s\"", PhenodigmDTO.DISEASE_ID, diseaseId); SolrQuery solrQuery = new SolrQuery(query); completeDiseaseModelQuery(solrQuery); // add more fields about the gene involved solrQuery.addField(PhenodigmDTO.MARKER_SYMBOL).addField(PhenodigmDTO.MARKER_NUM_MODELS); List<DiseaseModelAssociation> associations = new ArrayList<>(); try {/*from ww w . j av a 2 s .c o m*/ List<PhenodigmDTO> results = phenodigmCore.query(solrQuery).getBeans(PhenodigmDTO.class); for (PhenodigmDTO phenodigm : results) { DiseaseModelAssociation assoc = createBasicDMA(phenodigm); assoc.setMarkerId(phenodigm.getMarkerId()); assoc.setMarkerSymbol(phenodigm.getMarkerSymbol()); assoc.setMarkerNumModels(phenodigm.getMarkerNumModels()); associations.add(assoc); } } catch (SolrServerException | IOException e) { LOGGER.error(e.getMessage()); } return associations; }
From source file:uk.ac.ebi.phenodigm2.WebDaoSolrImpl.java
License:Apache License
@Override public List<DiseaseModelAssociation> getGeneToDiseaseModelAssociations(String markerId) { String query = String.format("%s:\"%s\"", PhenodigmDTO.MARKER_ID, markerId); SolrQuery solrQuery = new SolrQuery(query); completeDiseaseModelQuery(solrQuery); // add fields for details about the disease solrQuery.addField(PhenodigmDTO.DISEASE_TERM); List<DiseaseModelAssociation> associations = new ArrayList<>(); try {//from w ww.jav a 2 s. c o m List<PhenodigmDTO> results = phenodigmCore.query(solrQuery).getBeans(PhenodigmDTO.class); for (PhenodigmDTO phenodigm : results) { DiseaseModelAssociation assoc = createBasicDMA(phenodigm); assoc.setMarkerId(phenodigm.getMarkerId()); assoc.setDiseaseId(phenodigm.getDiseaseId()); assoc.setDiseaseTerm(phenodigm.getDiseaseTerm()); associations.add(assoc); } } catch (SolrServerException | IOException e) { LOGGER.error(e.getMessage()); } return associations; }
From source file:uk.ac.ebi.phenotype.service.ObservationService.java
License:Apache License
public QueryResponse getViabilityData(List<String> resources) throws SolrServerException { SolrQuery query = new SolrQuery(); if (resources != null) { query.setFilterQueries(ObservationDTO.DATASOURCE_NAME + ":" + StringUtils.join(resources, " OR " + ObservationDTO.DATASOURCE_NAME + ":")); }/*from ww w . java2 s .co m*/ query.setQuery(ObservationDTO.PARAMETER_STABLE_ID + ":IMPC_VIA_001_001"); query.addField(ObservationDTO.GENE_SYMBOL); query.addField(ObservationDTO.COLONY_ID); query.addField(ObservationDTO.CATEGORY); query.setRows(100000); System.out.println("getViabilityData Url" + solr.getBaseURL() + "/select?" + query); return solr.query(query); }