List of usage examples for org.apache.solr.client.solrj.response PivotField getValue
public Object getValue()
From source file:au.org.ala.biocache.dao.SearchDAOImpl.java
License:Open Source License
/** * Read nested pivot results.//from w w w . j a v a 2 s. com * * @param pfl * @return */ private List<FacetPivotResultDTO> getFacetPivotResults(List<PivotField> pfl) { if (pfl == null || pfl.size() == 0) { return null; } List<FacetPivotResultDTO> list = new ArrayList<FacetPivotResultDTO>(); for (PivotField pf : pfl) { String value = pf.getValue() != null ? pf.getValue().toString() : null; if (pf.getPivot() == null || pf.getPivot().size() == 0) { list.add(new FacetPivotResultDTO(null, null, value, pf.getCount())); } else { list.add(new FacetPivotResultDTO(pf.getPivot().get(0).getField(), getFacetPivotResults(pf.getPivot()), value, pf.getCount())); } } return list; }
From source file:com.frank.search.solr.core.ResultHelper.java
License:Apache License
private static List<FacetPivotFieldEntry> convertPivotResult(List<PivotField> pivotResult) { if (CollectionUtils.isEmpty(pivotResult)) { return Collections.emptyList(); }/*from w w w . j a va2 s . c om*/ ArrayList<FacetPivotFieldEntry> pivotFieldEntries = new ArrayList<FacetPivotFieldEntry>(); for (PivotField pivotField : pivotResult) { SimpleFacetPivotEntry pivotFieldEntry = new SimpleFacetPivotEntry( new SimpleField(pivotField.getField()), String.valueOf(pivotField.getValue()), pivotField.getCount()); List<PivotField> pivot = pivotField.getPivot(); if (pivot != null) { pivotFieldEntry.setPivot(convertPivotResult(pivot)); } pivotFieldEntries.add(pivotFieldEntry); } return pivotFieldEntries; }
From source file:com.nridge.ds.solr.SolrResponseBuilder.java
License:Open Source License
private int populateFacetPivot(DataTable aTable, String[] aFacetNames, int aRowId, int aParentId, PivotField aPivotField) { Object facetValue;/* w w w.ja v a 2 s . com*/ FieldRow fieldRow; String fieldName, facetName, facetNameCount; Logger appLogger = mAppMgr.getLogger(this, "populateFacetPivot"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); if (aPivotField != null) { fieldName = aPivotField.getField(); facetValue = aPivotField.getValue(); if (facetValue == null) facetNameCount = String.format("Unassigned (%s)", aPivotField.getCount()); else { facetName = aPivotField.getValue().toString(); facetNameCount = String.format("%s (%s)", facetName, aPivotField.getCount()); } ArrayList<String> facetValues = null; if (StringUtils.equals(fieldName, aFacetNames[0])) aParentId = 0; else { int rowCount = aTable.rowCount(); if (rowCount > 0) { fieldRow = aTable.getRow(rowCount - 1); facetValues = aTable.getValuesByName(fieldRow, fieldName); if (facetValues != null) { if (facetValues.size() == 0) facetValues = null; else facetValues.add(facetNameCount); } } } if (facetValues == null) { fieldRow = aTable.newRow(); aTable.setValueByName(fieldRow, "id", aRowId + 1); aTable.setValueByName(fieldRow, "parent_id", aParentId); facetValues = aTable.getValuesByName(fieldRow, fieldName); if (facetValues != null) { facetValues.add(facetNameCount); if (facetValues.size() == 1) { aTable.addRow(fieldRow); aRowId = aTable.rowCount(); aParentId = aRowId; } } } if (aPivotField.getPivot() != null) { for (PivotField pivotField : aPivotField.getPivot()) aRowId = populateFacetPivot(aTable, aFacetNames, aRowId, aParentId, pivotField); } } appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); return aRowId; }
From source file:ddf.catalog.source.solr.SolrCatalogProvider.java
License:Open Source License
@Override public Set<ContentType> getContentTypes() { Set<ContentType> finalSet = new HashSet<>(); String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeFormat.STRING, true); String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeFormat.STRING, true);//from w ww. ja v a 2 s. co m /* * If we didn't find the field, it most likely means it does not exist. If it does not * exist, then we can safely say that no content types are in this catalog provider */ if (contentTypeField == null || contentTypeVersionField == null) { return finalSet; } SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]"); query.setFacet(true); query.addFacetField(contentTypeField); query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField); try { QueryResponse solrResponse = server.query(query, METHOD.POST); List<FacetField> facetFields = solrResponse.getFacetFields(); for (Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) { // if no content types have an associated version, the list of pivot fields will be // empty. // however, the content type names can still be obtained via the facet fields. if (CollectionUtils.isEmpty(entry.getValue())) { LOGGER.debug("No content type versions found associated with any available content types."); if (CollectionUtils.isNotEmpty(facetFields)) { // Only one facet field was added. That facet field may contain multiple // values (content type names). for (FacetField.Count currContentType : facetFields.get(0).getValues()) { // unknown version, so setting it to null ContentTypeImpl contentType = new ContentTypeImpl(currContentType.getName(), null); finalSet.add(contentType); } } } else { for (PivotField pf : entry.getValue()) { String contentTypeName = pf.getValue().toString(); LOGGER.debug("contentTypeName:{}", contentTypeName); if (CollectionUtils.isEmpty(pf.getPivot())) { // if there are no sub-pivots, that means that there are no content type // versions // associated with this content type name LOGGER.debug("Content type does not have associated contentTypeVersion: {}", contentTypeName); ContentTypeImpl contentType = new ContentTypeImpl(contentTypeName, null); finalSet.add(contentType); } else { for (PivotField innerPf : pf.getPivot()) { LOGGER.debug("contentTypeVersion:{}. For contentTypeName: {}", innerPf.getValue(), contentTypeName); ContentTypeImpl contentType = new ContentTypeImpl(contentTypeName, innerPf.getValue().toString()); finalSet.add(contentType); } } } } } } catch (SolrServerException e) { LOGGER.info("SOLR server exception getting content types", e); } return finalSet; }
From source file:ddf.catalog.source.solr.SolrMetacardClientImpl.java
License:Open Source License
@Override public Set<ContentType> getContentTypes() { Set<ContentType> finalSet = new HashSet<>(); String contentTypeField = resolver.getField(Metacard.CONTENT_TYPE, AttributeType.AttributeFormat.STRING, true);//from w ww . j av a 2s . c o m String contentTypeVersionField = resolver.getField(Metacard.CONTENT_TYPE_VERSION, AttributeType.AttributeFormat.STRING, true); /* * If we didn't find the field, it most likely means it does not exist. If it does not * exist, then we can safely say that no content types are in this catalog provider */ if (contentTypeField == null || contentTypeVersionField == null) { return finalSet; } SolrQuery query = new SolrQuery(contentTypeField + ":[* TO *]"); query.setFacet(true); query.addFacetField(contentTypeField); query.addFacetPivotField(contentTypeField + "," + contentTypeVersionField); try { QueryResponse solrResponse = client.query(query, SolrRequest.METHOD.POST); List<FacetField> facetFields = solrResponse.getFacetFields(); for (Map.Entry<String, List<PivotField>> entry : solrResponse.getFacetPivot()) { // if no content types have an associated version, the list of pivot fields will be // empty. // however, the content type names can still be obtained via the facet fields. if (CollectionUtils.isEmpty(entry.getValue())) { LOGGER.debug("No content type versions found associated with any available content types."); if (CollectionUtils.isNotEmpty(facetFields)) { // Only one facet field was added. That facet field may contain multiple // values (content type names). for (FacetField.Count currContentType : facetFields.get(0).getValues()) { // unknown version, so setting it to null ContentType contentType = new ContentTypeImpl(currContentType.getName(), null); finalSet.add(contentType); } } } else { for (PivotField pf : entry.getValue()) { String contentTypeName = pf.getValue().toString(); LOGGER.debug("contentTypeName: {}", contentTypeName); if (CollectionUtils.isEmpty(pf.getPivot())) { // if there are no sub-pivots, that means that there are no content type // versions // associated with this content type name LOGGER.debug("Content type does not have associated contentTypeVersion: {}", contentTypeName); ContentType contentType = new ContentTypeImpl(contentTypeName, null); finalSet.add(contentType); } else { for (PivotField innerPf : pf.getPivot()) { LOGGER.debug("contentTypeVersion: {}. For contentTypeName: {}", innerPf.getValue(), contentTypeName); ContentType contentType = new ContentTypeImpl(contentTypeName, innerPf.getValue().toString()); finalSet.add(contentType); } } } } } } catch (SolrServerException | IOException e) { LOGGER.info("Solr exception getting content types", e); } return finalSet; }
From source file:fr.cnes.sitools.metacatalogue.representation.GeoJsonMDEORepresentation.java
License:Open Source License
private void writeFacetPivots(JsonGenerator jGenerator, List<PivotField> pivotFields) throws JsonGenerationException, IOException { if (pivotFields == null) { return;/*from w w w . ja v a 2 s . c om*/ } jGenerator.writeStartArray(); for (PivotField field : pivotFields) { jGenerator.writeStartObject(); jGenerator.writeStringField("field", field.getField()); jGenerator.writeStringField("value", getValue(field.getField(), field.getValue().toString())); jGenerator.writeNumberField("count", field.getCount()); if (field.getPivot() != null) { jGenerator.writeFieldName("pivot"); writeFacetPivots(jGenerator, field.getPivot()); } jGenerator.writeEndObject(); } jGenerator.writeEndArray(); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFacetingTest.java
License:Open Source License
@Test public void pivotFaceting_mincountMissing_shouldReturnFacetsMincountOne() throws Exception { String jsonQuery = "{\"query\":\"(suggest:a)\",\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}"; putHandleDefaults();// ww w.j a v a 2 s .co m QueryResponse queryResponse = query(getDefaultTestClient(), true, jsonQuery, params("qt", "/afts", "shards.qt", "/afts", "start", "0", "rows", "0", "fl", "score,id", "facet", "true", "facet.pivot", "{http://www.alfresco.org/model/content/1.0}content,{http://www.alfresco.org/model/content/1.0}name")); NamedList<List<PivotField>> facetPivot = queryResponse.getFacetPivot(); List<PivotField> firstLevelValues = facetPivot.getVal(0); Assert.assertThat(firstLevelValues.size(), is(2)); PivotField firstLevelPivot0 = firstLevelValues.get(0); Assert.assertThat(firstLevelPivot0.getValue(), is("contenttwo")); Assert.assertThat(firstLevelPivot0.getCount(), is(4)); List<PivotField> firstLevelPivot0Children = firstLevelPivot0.getPivot(); Assert.assertThat(firstLevelPivot0Children.size(), is(1)); PivotField secondLevelPivot0 = firstLevelPivot0Children.get(0); Assert.assertThat(secondLevelPivot0.getValue(), is("nametwo")); Assert.assertThat(secondLevelPivot0.getCount(), is(4)); PivotField firstLevelPivot1 = firstLevelValues.get(1); Assert.assertThat(firstLevelPivot1.getValue(), is("contentone")); Assert.assertThat(firstLevelPivot1.getCount(), is(1)); List<PivotField> firstLevelPivot1Children = firstLevelPivot1.getPivot(); Assert.assertThat(firstLevelPivot1Children.size(), is(1)); PivotField secondLevelPivot1 = firstLevelPivot1Children.get(0); Assert.assertThat(secondLevelPivot1.getValue(), is("nameone")); Assert.assertThat(secondLevelPivot1.getCount(), is(1)); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFacetingTest.java
License:Open Source License
@Test public void pivotFaceting_mincountSetZero_shouldReturnFacetsMincountOne() throws Exception { String jsonQuery = "{\"query\":\"(suggest:a)\",\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}"; putHandleDefaults();//from w ww .j a v a2s . c om QueryResponse queryResponse = query(getDefaultTestClient(), true, jsonQuery, params("qt", "/afts", "shards.qt", "/afts", "start", "0", "rows", "0", "fl", "score,id", "facet", "true", "facet.pivot", "{http://www.alfresco.org/model/content/1.0}content,{http://www.alfresco.org/model/content/1.0}name", "facet.pivot.mincount", "0")); NamedList<List<PivotField>> facetPivot = queryResponse.getFacetPivot(); List<PivotField> firstLevelValues = facetPivot.getVal(0); Assert.assertThat(firstLevelValues.size(), is(2)); PivotField firstLevelPivot0 = firstLevelValues.get(0); Assert.assertThat(firstLevelPivot0.getValue(), is("contenttwo")); Assert.assertThat(firstLevelPivot0.getCount(), is(4)); List<PivotField> firstLevelPivot0Children = firstLevelPivot0.getPivot(); Assert.assertThat(firstLevelPivot0Children.size(), is(1)); PivotField secondLevelPivot0 = firstLevelPivot0Children.get(0); Assert.assertThat(secondLevelPivot0.getValue(), is("nametwo")); Assert.assertThat(secondLevelPivot0.getCount(), is(4)); PivotField firstLevelPivot1 = firstLevelValues.get(1); Assert.assertThat(firstLevelPivot1.getValue(), is("contentone")); Assert.assertThat(firstLevelPivot1.getCount(), is(1)); List<PivotField> firstLevelPivot1Children = firstLevelPivot1.getPivot(); Assert.assertThat(firstLevelPivot1Children.size(), is(1)); PivotField secondLevelPivot1 = firstLevelPivot1Children.get(0); Assert.assertThat(secondLevelPivot1.getValue(), is("nameone")); Assert.assertThat(secondLevelPivot1.getCount(), is(1)); }
From source file:org.alfresco.solr.query.DistributedAlfrescoSolrFacetingTest.java
License:Open Source License
@Test public void pivotFaceting_mincountSetTwo_shouldReturnFacetsOriginalMincount() throws Exception { String jsonQuery = "{\"query\":\"(suggest:a)\",\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [\"joel\"], \"tenants\": []}"; putHandleDefaults();/*from ww w . j a v a 2s. c o m*/ QueryResponse queryResponse = query(getDefaultTestClient(), true, jsonQuery, params("qt", "/afts", "shards.qt", "/afts", "start", "0", "rows", "0", "fl", "score,id", "facet", "true", "facet.pivot", "{http://www.alfresco.org/model/content/1.0}content,{http://www.alfresco.org/model/content/1.0}name", "facet.pivot.mincount", "2")); NamedList<List<PivotField>> facetPivot = queryResponse.getFacetPivot(); List<PivotField> firstLevelValues = facetPivot.getVal(0); Assert.assertThat(firstLevelValues.size(), is(1)); PivotField firstLevelPivot0 = firstLevelValues.get(0); Assert.assertThat(firstLevelPivot0.getValue(), is("contenttwo")); Assert.assertThat(firstLevelPivot0.getCount(), is(4)); List<PivotField> firstLevelPivot0Children = firstLevelPivot0.getPivot(); Assert.assertThat(firstLevelPivot0Children.size(), is(1)); PivotField secondLevelPivot0 = firstLevelPivot0Children.get(0); Assert.assertThat(secondLevelPivot0.getValue(), is("nametwo")); Assert.assertThat(secondLevelPivot0.getCount(), is(4)); }
From source file:org.apache.drill.exec.store.solr.SolrRecordReader.java
License:Apache License
private int processFacetPivotResponse(List<PivotField> facetPivots) { SolrFacetPivot2ResultSet oSolrFacetPivot2ResultSet = new SolrFacetPivot2ResultSet(); oSolrFacetPivot2ResultSet.build(facetPivots); int resultSeek = 0; int leafNodesSeek = 0; while (!oSolrFacetPivot2ResultSet.isEmpty()) { SolrFacetPivotRecord oSolrFacetPivotRecord = (SolrFacetPivotRecord) oSolrFacetPivot2ResultSet.pop(); PivotField pivotField = oSolrFacetPivotRecord.getPivotField(); String fieldName = pivotField.getField(); Object fieldValue = pivotField.getValue(); ValueVector vv = vectors.get(fieldName); if (oSolrFacetPivotRecord.getPivotSize() == 0) { Map<String, FieldStatsInfo> fieldStatsInfo = pivotField.getFieldStatsInfo(); processRecord(vv, fieldValue, leafNodesSeek); int statsCounter = 0; if (isCountOnlyQuery()) { processCountQuery(vectors.get(String.valueOf(statsCounter)), Long.valueOf(pivotField.getCount()), statsCounter, leafNodesSeek); statsCounter++;//w w w. ja v a2 s. c om } else { for (SolrAggrParam solrAggrParam : solrAggrParams) { FieldStatsInfo fieldStats = fieldStatsInfo.get(getSolrField(solrAggrParam.getFieldName(), solrScanSpec.getCvSchema().getUniqueKey())); String functionName = solrAggrParam.getFunctionName(); if (fieldStats != null) { processStatsRecord(fieldStats, functionName, statsCounter, leafNodesSeek, solrScanSpec.isGroup()); statsCounter++; if (statsCounter == solrScanSpec.getProjectFieldNames().size()) { break; } } } } leafNodesSeek++; } else { int start = (leafNodesSeek == oSolrFacetPivotRecord.getPivotSize()) ? 0 : Math.abs((leafNodesSeek - oSolrFacetPivotRecord.getPivotSize())); int end = (start == 0) ? leafNodesSeek : (start + oSolrFacetPivotRecord.getPivotSize()); SolrRecordReader.logger.info("Start is : " + start + " End is : " + end); for (int i = start; i < end; i++) { processRecord(vv, fieldValue, i); } resultSeek += oSolrFacetPivotRecord.getPivotSize(); } } return (resultSeek == 0) ? leafNodesSeek : resultSeek; }