List of usage examples for org.apache.solr.client.solrj SolrQuery addFacetField
public SolrQuery addFacetField(String... fields)
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);// w w w . j ava2s .c om 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 a v a2 s . 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; }
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 w w .j ava 2 s. c om 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; }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
/** * * @param geneAccessionId/*from w w w . jav a 2s .com*/ * @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 av a 2s. com 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.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
/** * @return Map <String, Long> : <top_level_mp_name, number_of_annotations> * @author tudose//from w w w . j a v a 2 s .co m */ public TreeMap<String, Long> getDistributionOfAnnotationsByMPTopLevel(List<String> resourceName, Float pValueThreshold) { SolrQuery query = new SolrQuery(); if (resourceName != null) { query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":")); } else { query.setQuery("*:*"); } if (pValueThreshold != null) { query.setFilterQueries(StatisticalResultDTO.P_VALUE + ":[0 TO " + pValueThreshold + "]"); } query.setFacet(true); query.setFacetLimit(-1); query.setFacetMinCount(1); query.setRows(0); query.addFacetField(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME); try { QueryResponse response = statisticalResultCore.query(query); TreeMap<String, Long> res = new TreeMap<>(); res.putAll(getFacets(response).get(StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME)); return res; } catch (SolrServerException | IOException e) { e.printStackTrace(); } return null; }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
public PhenotypeFacetResult getPhenotypeFacetResultByPhenotypingCenterAndPipeline(String phenotypingCenter, String pipelineStableId) throws IOException, URISyntaxException, JSONException { SolrQuery query = new SolrQuery(); query.setQuery(StatisticalResultDTO.PHENOTYPING_CENTER + ":\"" + phenotypingCenter); query.addFilterQuery(StatisticalResultDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId); query.setFacet(true);// w ww .j av a2 s .com query.addFacetField(StatisticalResultDTO.RESOURCE_FULLNAME); query.addFacetField(StatisticalResultDTO.PROCEDURE_NAME); query.addFacetField(StatisticalResultDTO.MARKER_SYMBOL); query.addFacetField(StatisticalResultDTO.MP_TERM_NAME); query.setSort(StatisticalResultDTO.P_VALUE, SolrQuery.ORDER.asc); query.setRows(10000000); query.set("wt", "json"); query.set("version", "2.2"); String solrUrl = SolrUtils.getBaseURL(statisticalResultCore) + "/select?" + query; return createPhenotypeResultFromSolrResponse(solrUrl); }
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
public Set<String> getAccessionsByResourceName(String resourceName) { Set<String> res = new HashSet<>(); SolrQuery query = new SolrQuery().setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName); query.setFacet(true);/*from w ww. j a va2 s. c o m*/ query.addFacetField(StatisticalResultDTO.MARKER_ACCESSION_ID); query.setFacetLimit(10000000); query.setFacetMinCount(1); query.setRows(0); QueryResponse response; try { response = statisticalResultCore.query(query); for (Count id : response.getFacetField(StatisticalResultDTO.MARKER_ACCESSION_ID).getValues()) { res.add(id.getName()); } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
From source file:org.mule.modules.SolrConnector.java
License:Apache License
private void applyFacetingLogic(SolrQuery query, List<String> facetFields, int facetLimit, int facetMinCount) { if (facetFields == null || facetFields.isEmpty()) { logger.debug("Faceting is disabled for this query..."); return;//from w ww. j a v a 2 s .c o m } query.setFacet(true); query.setFacetLimit(facetLimit); query.setFacetMinCount(facetMinCount); query.addFacetField(facetFields.toArray(EMPTY_STRING_ARRAY)); }
From source file:org.ofbiz.solr.SolrProductSearch.java
License:Apache License
/** * Runs a query on the Solr Search Engine and returns the results. * <p>/*ww w. j av a 2s.c o m*/ * This function only returns an object of type QueryResponse, so it is probably not a good idea to call it directly from within the * groovy files (As a decent example on how to use it, however, use keywordSearch instead). */ public static Map<String, Object> runSolrQuery(DispatchContext dctx, Map<String, Object> context) { // get Connection HttpSolrServer server = null; Map<String, Object> result; Integer viewIndex = (Integer) context.get("viewIndex"); Integer viewSize = (Integer) context.get("viewSize"); if (viewIndex < 1) { viewIndex = 1; } try { server = new HttpSolrServer(SolrUtil.solrUrl); // create Query Object SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery((String) context.get("query")); // solrQuery.setQueryType("dismax"); boolean faceted = (Boolean) context.get("facet"); if (faceted) { solrQuery.setFacet(faceted); //solrQuery.addFacetField("manu"); solrQuery.addFacetField("features"); solrQuery.addFacetField("cat"); solrQuery.setFacetMinCount(1); solrQuery.setFacetLimit(8); solrQuery.addFacetQuery("listPrice:[0 TO 50]"); solrQuery.addFacetQuery("listPrice:[50 TO 100]"); solrQuery.addFacetQuery("listPrice:[100 TO 250]"); solrQuery.addFacetQuery("listPrice:[250 TO 500]"); solrQuery.addFacetQuery("listPrice:[500 TO 1000]"); solrQuery.addFacetQuery("listPrice:[1000 TO 2500]"); solrQuery.addFacetQuery("listPrice:[2500 TO 5000]"); solrQuery.addFacetQuery("listPrice:[5000 TO 10000]"); solrQuery.addFacetQuery("listPrice:[10000 TO 50000]"); solrQuery.addFacetQuery("listPrice:[50000 TO *]"); } boolean spellCheck = (Boolean) context.get("spellcheck"); if (spellCheck) { solrQuery.setParam("spellcheck", spellCheck); } boolean highLight = (Boolean) context.get("highlight"); if (highLight) { solrQuery.setHighlight(highLight); solrQuery.setHighlightSimplePre("<span class=\"highlight\">"); solrQuery.addHighlightField("description"); solrQuery.setHighlightSimplePost("</span>"); solrQuery.setHighlightSnippets(2); } // Set additional Parameter // SolrQuery.ORDER order = SolrQuery.ORDER.desc; if (viewIndex != null && viewIndex > 0) { solrQuery.setStart((viewIndex - 1) * viewSize); } if (viewSize != null && viewSize > 0) { solrQuery.setRows(viewSize); } // if ((List) context.get("queryFilter") != null && ((ArrayList<SolrDocument>) context.get("queryFilter")).size() > 0) { // List filter = (List) context.get("queryFilter"); // String[] tn = new String[filter.size()]; // Iterator it = filter.iterator(); // for (int i = 0; i < filter.size(); i++) { // tn[i] = (String) filter.get(i); // } // solrQuery.setFilterQueries(tn); // } String queryFilter = (String) context.get("queryFilter"); if (UtilValidate.isNotEmpty(queryFilter)) solrQuery.setFilterQueries(queryFilter.split(" ")); if ((String) context.get("returnFields") != null) { solrQuery.setFields((String) context.get("returnFields")); } // if((Boolean)context.get("sortByReverse"))order.reverse(); if ((String) context.get("sortBy") != null && ((String) context.get("sortBy")).length() > 0) { SolrQuery.ORDER order; if (!((Boolean) context.get("sortByReverse"))) order = SolrQuery.ORDER.asc; else order = SolrQuery.ORDER.desc; solrQuery.setSort(((String) context.get("sortBy")).replaceFirst("-", ""), order); } if ((String) context.get("facetQuery") != null) { solrQuery.addFacetQuery((String) context.get("facetQuery")); } QueryResponse rsp = server.query(solrQuery); result = ServiceUtil.returnSuccess(); result.put("queryResult", rsp); } catch (Exception e) { Debug.logError(e, e.getMessage(), module); result = ServiceUtil.returnError(e.toString()); } return result; }