List of usage examples for org.apache.solr.client.solrj SolrQuery setFacetMinCount
public SolrQuery setFacetMinCount(int cnt)
From source file:org.mousephenotype.cda.solr.service.StatisticalResultService.java
License:Apache License
/** * * @param geneAccessionId//w ww .j a va 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
/** * @author tudose/* w w w . jav a2 s . c o m*/ * @since 2015/07/21 * @return List<ProcedureBean> */ public List<ImpressBaseDTO> getProcedures(String pipelineStableId, String observationType, String resource, Integer minParameterNumber, List<String> proceduresToSkip, String status, boolean includeWilcoxon) { List<ImpressBaseDTO> procedures = new ArrayList<>(); try { SolrQuery query = new SolrQuery().setQuery("*:*").addField(StatisticalResultDTO.PROCEDURE_ID) .addField(StatisticalResultDTO.PROCEDURE_NAME) .addField(StatisticalResultDTO.PROCEDURE_STABLE_ID); query.set("group", true); query.set("group.field", StatisticalResultDTO.PROCEDURE_NAME); query.setRows(10000); query.setSort(StatisticalResultDTO.DOCUMENT_ID, SolrQuery.ORDER.asc); query.set("group.limit", 1); if (!includeWilcoxon) { query.addFilterQuery("-" + StatisticalResultDTO.STATISTICAL_METHOD + ":Wilcoxon*"); } if (pipelineStableId != null) { query.addFilterQuery(StatisticalResultDTO.PIPELINE_STABLE_ID + ":" + pipelineStableId); } if (observationType != null) { query.addFilterQuery(StatisticalResultDTO.DATA_TYPE + ":" + observationType); } if (resource != null) { query.addFilterQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resource); } if (status != null) { query.addFilterQuery(StatisticalResultDTO.STATUS + ":" + status); } String pivotField = StatisticalResultDTO.PROCEDURE_NAME + "," + StatisticalResultDTO.PARAMETER_NAME; if (minParameterNumber != null && minParameterNumber > 0) { query.setFacet(true); query.setFacetMinCount(1); query.set("facet.pivot.mincount", minParameterNumber); query.set("facet.pivot", pivotField); } QueryResponse response = statisticalResultCore.query(query); for (Group group : response.getGroupResponse().getValues().get(0).getValues()) { ImpressBaseDTO procedure = new ImpressBaseDTO( Long.getLong(group.getResult().get(0).getFirstValue(StatisticalResultDTO.PROCEDURE_ID) .toString()), null, group.getResult().get(0).getFirstValue(StatisticalResultDTO.PROCEDURE_STABLE_ID).toString(), group.getResult().get(0).getFirstValue(StatisticalResultDTO.PROCEDURE_NAME).toString()); procedures.add(procedure); } if (minParameterNumber != null && minParameterNumber > 0) { // get procedureList with more than minParameterNumber // remove from procedures the ones not in procedureList List<Map<String, String>> res = getFacetPivotResults(response, false); HashSet<String> proceduresWithMinCount = new HashSet<>(); for (Map<String, String> pivot : res) { proceduresWithMinCount.addAll(pivot.values()); } List<ImpressBaseDTO> proceduresToReturn = new ArrayList<>(); for (ImpressBaseDTO proc : procedures) { if (proceduresWithMinCount.contains(proc.getName())) { if (proceduresToSkip != null && !proceduresToSkip.contains(proc.getStableId()) || proceduresToSkip == null) { proceduresToReturn.add(proc); } } } procedures = proceduresToReturn; } } catch (SolrServerException | IOException | IndexOutOfBoundsException e) { e.printStackTrace(); } return procedures; }
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 + ":") + "*"); }/*from w ww.j a v a 2 s . c o m*/ 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
public Map<String, List<String>> getDistributionOfLinesByMPTopLevel(List<String> resourceName, Float pValueThreshold)/* ww w.j av a 2 s . c o m*/ throws SolrServerException, IOException, InterruptedException, ExecutionException { Map<String, List<String>> res = new ConcurrentHashMap<>(); //<parameter, <genes>> String pivotFacet = StatisticalResultDTO.TOP_LEVEL_MP_TERM_NAME + "," + StatisticalResultDTO.COLONY_ID; SolrQuery q = new SolrQuery(); if (resourceName != null) { q.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + StringUtils.join(resourceName, " OR " + StatisticalResultDTO.RESOURCE_NAME + ":")); } else { q.setQuery("*:*"); } if (pValueThreshold != null) { q.setFilterQueries(StatisticalResultDTO.P_VALUE + ":[0 TO " + pValueThreshold + "]"); } q.set("facet.pivot", pivotFacet); q.setFacet(true); q.setFacetMinCount(1); q.setRows(1); q.set("facet.limit", -1); logger.info("Solr url for getDistributionOfLinesByMPTopLevel " + SolrUtils.getBaseURL(statisticalResultCore) + "/select?" + q); QueryResponse response = statisticalResultCore.query(q); for (PivotField pivot : response.getFacetPivot().get(pivotFacet)) { if (pivot.getPivot() != null) { List<String> colonies = new ArrayList<>(); for (PivotField colony : pivot.getPivot()) { colonies.add(colony.getValue().toString()); } res.put(pivot.getValue().toString(), new ArrayList<String>(colonies)); } } return res; }
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 ww w . j a v a2 s. c o 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 Map<String, Set<String>> getAccessionProceduresMap(String resourceName) { SolrQuery query = new SolrQuery(); Map<String, Set<String>> res = new HashMap<>(); NamedList<List<PivotField>> response; if (resourceName == null) { query.setQuery("*:*"); } else {/*ww w . j a va 2 s . c o m*/ query.setQuery(StatisticalResultDTO.RESOURCE_NAME + ":" + resourceName); } query.setFacet(true); query.addFacetPivotField( StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID); query.setFacetLimit(-1); query.setFacetMinCount(1); query.setRows(0); try { response = statisticalResultCore.query(query).getFacetPivot(); for (PivotField genePivot : response.get( StatisticalResultDTO.MARKER_ACCESSION_ID + "," + StatisticalResultDTO.PROCEDURE_STABLE_ID)) { if (genePivot.getPivot() != null) { String geneName = genePivot.getValue().toString(); Set<String> procedures = new HashSet<>(); for (PivotField f : genePivot.getPivot()) { procedures.add(f.getValue().toString()); } res.put(geneName, procedures); } } } catch (SolrServerException | IOException e) { e.printStackTrace(); } return res; }
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 w w . ja va 2 s. com 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.ja v a2s . com } 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>/*from w ww . j a va2 s. c om*/ * 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; }
From source file:org.ofbiz.solr.SolrUtil.java
License:Apache License
public static Map<String, Object> categoriesAvailable(String catalogId, String categoryId, String productId, String facetPrefix, boolean displayproducts, int viewIndex, int viewSize) { // create the data model Map<String, Object> result = FastMap.newInstance(); HttpSolrServer server = null;/* w ww. j av a 2s . c o m*/ QueryResponse returnMap = new QueryResponse(); try { // do the basic query server = new HttpSolrServer(solrUrl); // create Query Object String query = "inStock[1 TO *]"; if (categoryId != null) query += " +cat:" + categoryId; else if (productId != null) query += " +productId:" + productId; SolrQuery solrQuery = new SolrQuery(); solrQuery.setQuery(query); if (catalogId != null) solrQuery.setFilterQueries("catalog:" + catalogId); if (displayproducts) { if (viewSize > -1) { solrQuery.setRows(viewSize); } else solrQuery.setRows(50000); if (viewIndex > -1) { solrQuery.setStart(viewIndex); } } else { solrQuery.setFields("cat"); solrQuery.setRows(0); } if (UtilValidate.isNotEmpty(facetPrefix)) { solrQuery.setFacetPrefix(facetPrefix); } solrQuery.setFacetMinCount(0); solrQuery.setFacet(true); solrQuery.addFacetField("cat"); solrQuery.setFacetLimit(-1); Debug.logVerbose("solr: solrQuery: " + solrQuery, module); returnMap = server.query(solrQuery, METHOD.POST); result.put("rows", returnMap); result.put("numFound", returnMap.getResults().getNumFound()); } catch (Exception e) { Debug.logError(e.getMessage(), module); } return result; }