List of usage examples for org.apache.solr.client.solrj.response Group getGroupValue
public String getGroupValue()
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
License:Open Source License
/** * Perform grouped facet query.//from w w w .j a v a 2s .c o m * <p> * facets is the list of grouped facets required * flimit restricts the number of groups returned * pageSize restricts the number of docs in each group returned * fl is the list of fields in the returned docs */ public List<GroupFacetResultDTO> searchGroupedFacets(SpatialSearchRequestParams searchParams) throws Exception { queryFormatUtils.formatSearchQuery(searchParams); String queryString = searchParams.getFormattedQuery(); searchParams.setFacet(false); //get facet group counts SolrQuery query = initSolrQuery(searchParams, false, null); query.setQuery(queryString); query.setFields(null); //now use the supplied facets to add groups to the query query.add("group", "true"); query.add("group.ngroups", "true"); query.add("group.limit", String.valueOf(searchParams.getPageSize())); query.setRows(searchParams.getFlimit()); query.setFields(searchParams.getFl()); for (String facet : searchParams.getFacets()) { query.add("group.field", facet); } QueryResponse response = runSolrQuery(query, searchParams); GroupResponse groupResponse = response.getGroupResponse(); List<GroupFacetResultDTO> output = new ArrayList(); for (GroupCommand gc : groupResponse.getValues()) { List<GroupFieldResultDTO> list = new ArrayList<GroupFieldResultDTO>(); String facet = gc.getName(); for (Group v : gc.getValues()) { List<OccurrenceIndex> docs = (new DocumentObjectBinder()).getBeans(OccurrenceIndex.class, v.getResult()); //build facet displayName and fq String value = v.getGroupValue(); Long count = v.getResult() != null ? v.getResult().getNumFound() : 0L; if (value == null) { list.add(new GroupFieldResultDTO("", count, "-" + facet + ":*", docs)); } else { list.add(new GroupFieldResultDTO(getFacetValueDisplayName(facet, value), count, facet + ":\"" + value + "\"", docs)); } } output.add(new GroupFacetResultDTO(gc.getName(), list, gc.getNGroups())); } return output; }
From source file:com.frank.search.solr.core.ResultHelper.java
License:Apache License
static <T> Map<Object, GroupResult<T>> convertGroupQueryResponseToGroupResultMap(Query query, Map<String, Object> objectNames, QueryResponse response, SolrTemplate solrTemplate, Class<T> clazz) { GroupResponse groupResponse = response.getGroupResponse(); SolrDocumentList sdl = response.getResults(); if (groupResponse == null) { return Collections.emptyMap(); }//from w ww. j ava 2 s.c o m Map<Object, GroupResult<T>> result = new LinkedHashMap<Object, GroupResult<T>>(); List<GroupCommand> values = groupResponse.getValues(); for (GroupCommand groupCommand : values) { List<GroupEntry<T>> groupEntries = new ArrayList<GroupEntry<T>>(); for (Group group : groupCommand.getValues()) { SolrDocumentList documentList = group.getResult(); List<T> beans = solrTemplate.convertSolrDocumentListToBeans(documentList, clazz); Page<T> page = new PageImpl<T>(beans, query.getGroupOptions().getPageRequest(), documentList.getNumFound()); groupEntries.add(new SimpleGroupEntry<T>(group.getGroupValue(), page)); } int matches = groupCommand.getMatches(); Integer ngroups = groupCommand.getNGroups(); String name = groupCommand.getName(); PageImpl<GroupEntry<T>> page; if (ngroups != null) { page = new PageImpl<GroupEntry<T>>(groupEntries, query.getPageRequest(), ngroups.intValue()); } else { page = new PageImpl<GroupEntry<T>>(groupEntries); } SimpleGroupResult<T> groupResult = new SimpleGroupResult<T>(matches, ngroups, name, page); result.put(name, groupResult); if (objectNames.containsKey(name)) { result.put(objectNames.get(name), groupResult); } } return result; }
From source file:com.nridge.ds.solr.SolrResponseBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") private Document createGroupCollectionDocument(Group aGroup) { Logger appLogger = mAppMgr.getLogger(this, "createGroupCollectionDocument"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); Document groupCollectionDocument = createGroupCollection(); DataBag groupCollectionBag = groupCollectionDocument.getBag(); String groupName = aGroup.getGroupValue(); if (StringUtils.isNotEmpty(groupName)) groupCollectionBag.setValueByName("group_name", groupName); SolrDocumentList solrDocumentList = aGroup.getResult(); if (solrDocumentList != null) { groupCollectionBag.setValueByName("offset_start", solrDocumentList.getStart()); groupCollectionBag.setValueByName("total_count", solrDocumentList.getNumFound()); Document groupDocument = new Document(Solr.RESPONSE_GROUP_DOCUMENT, createDocumentTable()); populateDocument(groupDocument, solrDocumentList); groupCollectionDocument.addRelationship(groupDocument.getType(), groupDocument); }/* w w w. j a v a2s. c o m*/ appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); return groupCollectionDocument; }
From source file:edu.unc.lib.dl.search.solr.service.SolrSearchService.java
License:Apache License
/** * Executes a SolrQuery based off of a search state and stores the results as BriefObjectMetadataBeans. * //from ww w. ja va2s . c o m * @param query * the solr query to be executed * @param searchState * the search state used to generate this SolrQuery * @param isRetrieveFacetsRequest * indicates if facet results hould be returned * @param returnQuery * indicates whether to return the solr query object as part of the response. * @return * @throws SolrServerException */ @SuppressWarnings("unchecked") protected SearchResultResponse executeSearch(SolrQuery query, SearchState searchState, boolean isRetrieveFacetsRequest, boolean returnQuery) throws SolrServerException { QueryResponse queryResponse = server.query(query); GroupResponse groupResponse = queryResponse.getGroupResponse(); SearchResultResponse response = new SearchResultResponse(); if (groupResponse != null) { List<BriefObjectMetadata> groupResults = new ArrayList<BriefObjectMetadata>(); for (GroupCommand groupCmd : groupResponse.getValues()) { // response.setResultCount(groupCmd.getMatches()); response.setResultCount(groupCmd.getNGroups()); for (Group group : groupCmd.getValues()) { GroupedMetadataBean grouped = new GroupedMetadataBean(group.getGroupValue(), this.server.getBinder().getBeans(BriefObjectMetadataBean.class, group.getResult()), group.getResult().getNumFound()); groupResults.add(grouped); } } response.setResultList(groupResults); } else { List<?> results = queryResponse.getBeans(BriefObjectMetadataBean.class); response.setResultList((List<BriefObjectMetadata>) results); // Store the number of results response.setResultCount(queryResponse.getResults().getNumFound()); } if (isRetrieveFacetsRequest) { // Store facet results response.setFacetFields(facetFieldFactory.createFacetFieldList(queryResponse.getFacetFields())); // Add empty entries for any empty facets, then sort the list if (response.getFacetFields() != null) { if (searchState.getFacetsToRetrieve() != null && searchState.getFacetsToRetrieve().size() != response.getFacetFields().size()) { facetFieldFactory.addMissingFacetFieldObjects(response.getFacetFields(), searchState.getFacetsToRetrieve()); } } } else { response.setFacetFields(null); } // Set search state that generated this result response.setSearchState(searchState); // Add the query to the result if it was requested if (returnQuery) { response.setGeneratedQuery(query); } return response; }
From source file:org.mousephenotype.cda.solr.service.GenotypePhenotypeService.java
License:Apache License
public List<String> getGenesAssocByParamAndMp(String parameterStableId, String phenotype_id) throws SolrServerException, IOException { List<String> res = new ArrayList<String>(); SolrQuery query = new SolrQuery() .setQuery("(" + GenotypePhenotypeDTO.MP_TERM_ID + ":\"" + phenotype_id + "\" OR " + GenotypePhenotypeDTO.TOP_LEVEL_MP_TERM_ID + ":\"" + phenotype_id + "\" OR " + GenotypePhenotypeDTO.INTERMEDIATE_MP_TERM_ID + ":\"" + phenotype_id + "\") AND (" + GenotypePhenotypeDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(OverviewChartsConstants.B6N_STRAINS, "\" OR " + GenotypePhenotypeDTO.STRAIN_ACCESSION_ID + ":\"") + "\") AND " + GenotypePhenotypeDTO.PARAMETER_STABLE_ID + ":\"" + parameterStableId + "\"") .setRows(100000000);/*from w ww.java 2 s . c o m*/ query.set("group.field", GenotypePhenotypeDTO.MARKER_ACCESSION_ID); query.set("group", true); List<Group> groups = genotypePhenotypeCore.query(query).getGroupResponse().getValues().get(0).getValues(); for (Group gr : groups) { if (!res.contains((String) gr.getGroupValue())) { res.add((String) gr.getGroupValue()); } } return res; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public Map<String, List<DiscreteTimePoint>> getTimeSeriesMutantData(String parameter, List<String> genes, List<String> strains, String[] center, String[] sex) throws SolrServerException, IOException { Map<String, List<DiscreteTimePoint>> finalRes = new HashMap<String, List<DiscreteTimePoint>>(); // <allele_accession, // timeSeriesData> SolrQuery query = new SolrQuery().addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental") .addFilterQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + parameter); String q = (strains.size() > 1) ? "(" + ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(strains.toArray(), "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"") + "\")" : ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + strains.get(0) + "\""; if (genes != null && genes.size() > 0) { q += " AND ("; q += (genes.size() > 1) ? ObservationDTO.GENE_ACCESSION_ID + ":\"" + StringUtils.join(genes.toArray(), "\" OR " + ObservationDTO.GENE_ACCESSION_ID + ":\"") + "\"" : ObservationDTO.GENE_ACCESSION_ID + ":\"" + genes.get(0) + "\""; q += ")"; }//from ww w.j a va 2s . c o m if (center != null && center.length > 0) { q += " AND ("; q += (center.length > 1) ? ObservationDTO.PHENOTYPING_CENTER + ":\"" + StringUtils.join(center, "\" OR " + ObservationDTO.PHENOTYPING_CENTER + ":\"") + "\"" : ObservationDTO.PHENOTYPING_CENTER + ":\"" + center[0] + "\""; q += ")"; } if (sex != null && sex.length == 1) { q += " AND " + ObservationDTO.SEX + ":\"" + sex[0] + "\""; } query.setQuery(q); query.set("group.field", ObservationDTO.GENE_SYMBOL); query.set("group", true); query.set("fl", ObservationDTO.DATA_POINT + "," + ObservationDTO.DISCRETE_POINT); query.set("group.limit", 100000); // number of documents to be returned // per group query.set("group.sort", ObservationDTO.DISCRETE_POINT + " asc"); query.setRows(10000); // logger.info("+_+_+ " + SolrUtils.getBaseURL(experimentCore) + "/select?" + // query); List<Group> groups = experimentCore.query(query).getGroupResponse().getValues().get(0).getValues(); // for mutants it doesn't seem we need binning // groups are the alleles for (Group gr : groups) { SolrDocumentList resDocs = gr.getResult(); DescriptiveStatistics stats = new DescriptiveStatistics(); float discreteTime = (float) resDocs.get(0).getFieldValue(ObservationDTO.DISCRETE_POINT); List<DiscreteTimePoint> res = new ArrayList<DiscreteTimePoint>(); for (int i = 0; i < resDocs.getNumFound(); i++) { SolrDocument doc = resDocs.get(i); stats.addValue((float) doc.getFieldValue(ObservationDTO.DATA_POINT)); if (discreteTime != (float) doc.getFieldValue(ObservationDTO.DISCRETE_POINT) || i == resDocs.getNumFound() - 1) { // we // are // at // the // end // of // the // document // list // add to list float discreteDataPoint = (float) stats.getMean(); DiscreteTimePoint dp = new DiscreteTimePoint(discreteTime, discreteDataPoint, new Float(stats.getStandardDeviation())); List<Float> errorPair = new ArrayList<>(); Float lower = new Float(discreteDataPoint); Float higher = new Float(discreteDataPoint); errorPair.add(lower); errorPair.add(higher); dp.setErrorPair(errorPair); res.add(dp); // update discrete point discreteTime = Float.valueOf(doc.getFieldValue(ObservationDTO.DISCRETE_POINT).toString()); // update stats stats = new DescriptiveStatistics(); } } // add list finalRes.put(gr.getGroupValue(), res); } return finalRes; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public List<DiscreteTimePoint> getTimeSeriesControlData(String parameter, List<String> strains, String[] center, String[] sex) throws SolrServerException, IOException { List<DiscreteTimePoint> res = new ArrayList<DiscreteTimePoint>(); SolrQuery query = new SolrQuery().addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":control") .addFilterQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + parameter); String q = (strains.size() > 1) ? "(" + ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(strains.toArray(), "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"") + "\")" : ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + strains.get(0) + "\""; if (center != null && center.length > 0) { q += " AND ("; q += (center.length > 1)/*from w w w . j a v a 2s.co m*/ ? ObservationDTO.PHENOTYPING_CENTER + ":\"" + StringUtils.join(center, "\" OR " + ObservationDTO.PHENOTYPING_CENTER + ":\"") + "\"" : ObservationDTO.PHENOTYPING_CENTER + ":\"" + center[0] + "\""; q += ")"; } if (sex != null && sex.length == 1) { q += " AND " + ObservationDTO.SEX + ":\"" + sex[0] + "\""; } query.setQuery(q); query.set("group.field", ObservationDTO.DISCRETE_POINT); query.set("group", true); query.set("fl", ObservationDTO.DATA_POINT + "," + ObservationDTO.DISCRETE_POINT); query.set("group.limit", 100000); // number of documents to be returned // per group query.set("sort", ObservationDTO.DISCRETE_POINT + " asc"); query.setRows(10000); // logger.info("+_+_+ " + SolrUtils.getBaseURL(solr) + "/select?" + // query); List<Group> groups = experimentCore.query(query).getGroupResponse().getValues().get(0).getValues(); boolean rounding = false; // decide if binning is needed i.e. is the increment points are too // scattered, as for calorimetry if (groups.size() > 30) { // arbitrary value, just piced it because it // seems reasonable for the size of our // graphs if (Float.valueOf(groups.get(groups.size() - 1).getGroupValue()) - Float.valueOf(groups.get(0).getGroupValue()) <= 30) { // then // rounding // will // be // enough rounding = true; } } if (rounding) { int bin = Math.round(Float.valueOf(groups.get(0).getGroupValue())); for (Group gr : groups) { int discreteTime = Math.round(Float.valueOf(gr.getGroupValue())); // for calormetry ignore what's before -5 and after 16 if (parameter.startsWith("IMPC_CAL") || parameter.startsWith("ESLIM_003_001") || parameter.startsWith("M-G-P_003_001")) { if (discreteTime < -5) { continue; } else if (discreteTime > 16) { break; } } float sum = 0; SolrDocumentList resDocs = gr.getResult(); DescriptiveStatistics stats = new DescriptiveStatistics(); for (SolrDocument doc : resDocs) { sum += (float) doc.getFieldValue(ObservationDTO.DATA_POINT); stats.addValue((float) doc.getFieldValue(ObservationDTO.DATA_POINT)); } if (bin < discreteTime || groups.indexOf(gr) == groups.size() - 1) { // finished // the // groups // of // filled // the // bin float discreteDataPoint = sum / resDocs.getNumFound(); DiscreteTimePoint dp = new DiscreteTimePoint((float) discreteTime, discreteDataPoint, new Float(stats.getStandardDeviation())); List<Float> errorPair = new ArrayList<>(); double std = stats.getStandardDeviation(); Float lower = new Float(discreteDataPoint - std); Float higher = new Float(discreteDataPoint + std); errorPair.add(lower); errorPair.add(higher); dp.setErrorPair(errorPair); res.add(dp); bin = discreteTime; } } } else { for (Group gr : groups) { Float discreteTime = Float.valueOf(gr.getGroupValue()); float sum = 0; SolrDocumentList resDocs = gr.getResult(); DescriptiveStatistics stats = new DescriptiveStatistics(); for (SolrDocument doc : resDocs) { sum += (float) doc.getFieldValue(ObservationDTO.DATA_POINT); stats.addValue((float) doc.getFieldValue(ObservationDTO.DATA_POINT)); } float discreteDataPoint = sum / resDocs.getNumFound(); DiscreteTimePoint dp = new DiscreteTimePoint(discreteTime, discreteDataPoint, new Float(stats.getStandardDeviation())); List<Float> errorPair = new ArrayList<>(); double std = stats.getStandardDeviation(); Float lower = new Float(discreteDataPoint - std); Float higher = new Float(discreteDataPoint + std); errorPair.add(lower); errorPair.add(higher); dp.setErrorPair(errorPair); res.add(dp); } } return res; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
/** * * @param p/*from w ww . jav a2 s.c o m*/ * @param genes * @param strains * @param biologicalSample * @return list of centers and sexes for the given parameters * @throws SolrServerException, IOException */ public Set<String> getCenters(Parameter p, List<String> genes, List<String> strains, String biologicalSample) throws SolrServerException, IOException { Set<String> centers = new HashSet<String>(); SolrQuery query = new SolrQuery() .addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":" + biologicalSample) .addFilterQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + p.getStableId()); String q = (strains.size() > 1) ? "(" + ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(strains.toArray(), "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"") + "\")" : ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + strains.get(0) + "\""; String fq = ""; if (genes != null && genes.size() > 0) { fq += " ("; fq += (genes.size() > 1) ? ObservationDTO.GENE_ACCESSION_ID + ":\"" + StringUtils.join(genes.toArray(), "\" OR " + ObservationDTO.GENE_ACCESSION_ID + ":\"") + "\"" : ObservationDTO.GENE_ACCESSION_ID + ":\"" + genes.get(0) + "\""; fq += ")"; } query.addFilterQuery(fq); query.setQuery(q); query.setRows(100000000); query.setFields(ObservationDTO.GENE_ACCESSION_ID, ObservationDTO.DATA_POINT); query.set("group", true); query.set("group.field", ObservationDTO.PHENOTYPING_CENTER); query.setSort(ObservationDTO.ID, SolrQuery.ORDER.asc); List<Group> groups = experimentCore.query(query, METHOD.POST).getGroupResponse().getValues().get(0) .getValues(); for (Group gr : groups) { centers.add((String) gr.getGroupValue()); } return centers; }
From source file:org.mousephenotype.cda.solr.service.ObservationService.java
License:Apache License
public CategoricalSet getCategories(Parameter parameter, List<String> genes, String biologicalSampleGroup, List<String> strains, String[] center, String[] sex) throws SolrServerException, IOException, SQLException { CategoricalSet resSet = new CategoricalSet(); resSet.setName(biologicalSampleGroup); SolrQuery query = new SolrQuery() .addFilterQuery(ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":" + biologicalSampleGroup) .addFilterQuery(ObservationDTO.PARAMETER_STABLE_ID + ":" + parameter.getStableId()); String q = (strains.size() > 1) ? "(" + ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + StringUtils.join(strains.toArray(), "\" OR " + ObservationDTO.STRAIN_ACCESSION_ID + ":\"") + "\")" : ObservationDTO.STRAIN_ACCESSION_ID + ":\"" + strains.get(0) + "\""; if (genes != null && genes.size() > 0) { q += " AND ("; q += (genes.size() > 1) ? ObservationDTO.GENE_ACCESSION_ID + ":\"" + StringUtils.join(genes.toArray(), "\" OR " + ObservationDTO.GENE_ACCESSION_ID + ":\"") + "\"" : ObservationDTO.GENE_ACCESSION_ID + ":\"" + genes.get(0) + "\""; q += ")"; }/*from ww w.ja v a 2s . co m*/ if (center != null && center.length > 0) { q += " AND ("; q += (center.length > 1) ? ObservationDTO.PHENOTYPING_CENTER + ":\"" + StringUtils.join(center, "\" OR " + ObservationDTO.PHENOTYPING_CENTER + ":\"") + "\"" : ObservationDTO.PHENOTYPING_CENTER + ":\"" + center[0] + "\""; q += ")"; } if (sex != null && sex.length == 1) { q += " AND " + ObservationDTO.SEX + ":\"" + sex[0] + "\""; } query.setQuery(q); query.set("group.field", ObservationDTO.CATEGORY); query.set("group", true); query.setRows(100); query.setSort(ObservationDTO.ID, SolrQuery.ORDER.asc); logger.info("URL in getCategories " + SolrUtils.getBaseURL(experimentCore) + "/select?" + query); QueryResponse res = experimentCore.query(query, METHOD.POST); List<Group> groups = res.getGroupResponse().getValues().get(0).getValues(); for (Group gr : groups) { CategoricalDataObject catObj = new CategoricalDataObject(); catObj.setCount((long) gr.getResult().getNumFound()); String catLabel = gr.getGroupValue(); catObj.setCategory(catLabel); resSet.add(catObj); } return resSet; }
From source file:org.mousephenotype.cda.solr.service.PhenotypeCenterService.java
License:Apache License
public List<PhenotypeCenterServiceBean> getMutantStrainsForCenter(String center) throws SolrServerException, IOException { List<PhenotypeCenterServiceBean> strains = new ArrayList<>(); SolrQuery query = new SolrQuery() .setQuery(ObservationDTO.PHENOTYPING_CENTER + ":\"" + center + "\" AND " + ObservationDTO.BIOLOGICAL_SAMPLE_GROUP + ":experimental") .setFields(ObservationDTO.GENE_ACCESSION_ID, ObservationDTO.ALLELE_SYMBOL, ObservationDTO.GENE_SYMBOL, ObservationDTO.ZYGOSITY) .setRows(1000000);//from www.ja va2s .c o m query.set("group", true); query.set("group.field", ObservationDTO.COLONY_ID); query.set("group.limit", 1); if (SolrUtils.getBaseURL(experimentCore).endsWith("experiment")) { query.addFilterQuery(ObservationDTO.DATASOURCE_NAME + ":" + "\"" + datasourceName + "\""); } QueryResponse response = experimentCore.query(query); GroupResponse groups = response.getGroupResponse(); for (Group group : groups.getValues().get(0).getValues()) { PhenotypeCenterServiceBean strain = new PhenotypeCenterServiceBean(); String colonyId = group.getGroupValue(); if (colonyId != null && !colonyId.equalsIgnoreCase("null")) { strain.setColonyId(colonyId); SolrDocument doc = group.getResult().get(0); strain.setAllele((String) doc.get(ObservationDTO.ALLELE_SYMBOL)); strain.setGeneSymbol((String) doc.get(ObservationDTO.GENE_SYMBOL)); strain.setMgiAccession((String) doc.get(ObservationDTO.GENE_ACCESSION_ID)); strain.setZygosity((String) doc.get(ObservationDTO.ZYGOSITY)); strains.add(strain); } } logger.info("getStrainsForCenter -- " + SolrUtils.getBaseURL(experimentCore) + "/select?" + query); return strains; }