writer.beginObject(); writer.name("facet").value(count.getName()); writer.name("count").value(count.getCount()); writer.endObject();
SearchFacetResultDTO resultDTO = new SearchFacetResultDTO(); resultDTO.setFacet(facetDTO.getFacet()); resultDTO.setQuantity(new Long(value.getCount()).intValue()); resultDTO.setValue(value.getName()); facetDTO.getFacetValues().add(resultDTO);
protected Map<String, Map<String, Long>> getFacetCounts(List<String> fields, QueryResponse solrResponse) { Map<String, Map<String, Long>> fieldCounts = new HashMap<>(); for (String field : fields) { Map<String, Long> valueCounts = new HashMap<>(); FacetField facetField = solrResponse.getFacetField(field); for (Count facetCount : facetField.getValues()) { valueCounts.put(facetCount.getName(), facetCount.getCount()); } fieldCounts.put(field, valueCounts); } return fieldCounts; }
if (count.getCount() == 0) { continue;
@Override public ObjectCount[] queryFacetDate(String query, String filterQuery, int max, String dateType, String dateStart, String dateEnd, boolean showTotal, Context context) throws SolrServerException { QueryResponse queryResponse = query(query, filterQuery, null, 0, max, dateType, dateStart, dateEnd, null, null, false); if (queryResponse == null) { return new ObjectCount[0]; } FacetField dateFacet = queryResponse.getFacetDate("time"); // TODO: check if this cannot crash I checked it, it crashed!!! // Create an array for our result ObjectCount[] result = new ObjectCount[dateFacet.getValueCount() + (showTotal ? 1 : 0)]; // Run over our datefacet & store all the values for (int i = 0; i < dateFacet.getValues().size(); i++) { FacetField.Count dateCount = dateFacet.getValues().get(i); result[i] = new ObjectCount(); result[i].setCount(dateCount.getCount()); result[i].setValue(getDateView(dateCount.getName(), dateType, context)); } if (showTotal) { result[result.length - 1] = new ObjectCount(); result[result.length - 1].setCount(queryResponse.getResults() .getNumFound()); // TODO: Make sure that this total is gotten out of the msgs.xml result[result.length - 1].setValue("total"); } return result; }
if (count.getCount() == 0) { continue;
public Multimap<String,InteractorIdCount> searchInteractors(SolrQuery originalQuery, String[] interactorTypeMis) throws IntactSolrException { SolrQuery query = originalQuery.getCopy(); query.setRows(0); query.setFacet(true); query.setFacetMinCount(1); query.setFacetLimit(Integer.MAX_VALUE); query.setFacetSort(FacetParams.FACET_SORT_COUNT); Multimap<String,InteractorIdCount> interactors = HashMultimap.create(); Map<String,String> fieldNameToTypeMap = new HashMap<String,String>(interactorTypeMis.length); for (String mi : interactorTypeMis) { final String fieldName = createFieldName(mi); query.addFacetField(fieldName); fieldNameToTypeMap.put(fieldName, mi); } QueryResponse queryResponse = executeQuery(query); for (Map.Entry<String,String> entry : fieldNameToTypeMap.entrySet()) { FacetField ff = queryResponse.getFacetField(entry.getKey()); if (ff != null && ff.getValues() != null) { for (FacetField.Count c : ff.getValues()) { interactors.put(entry.getValue(), new InteractorIdCount(c.getName(), c.getCount())); } } } return interactors; }
private void filterFacet(SolrDocument doc, FacetField facetField) { // facet filtering by value requires that the facet values match the stored values // a *_facet field must exist, stored (or /w docValues) to be used for faceting and at filtering time if (doc.getFieldNames().contains(facetField.getName())) { // decrease facet value Collection<Object> docFieldValues = doc.getFieldValues(facetField.getName()); if (docFieldValues != null) { for (Object docFieldValue : docFieldValues) { String valueString = String.valueOf(docFieldValue); List<FacetField.Count> toRemove = new LinkedList<FacetField.Count>(); for (FacetField.Count count : facetField.getValues()) { long existingCount = count.getCount(); if (valueString.equals(count.getName())) { if (existingCount > 1) { // decrease the count count.setCount(existingCount - 1); } else { // remove the entire entry toRemove.add(count); } } } for (FacetField.Count f : toRemove) { assert facetField.getValues().remove(f); } } } } }
private void filterFacet(SolrDocument doc, FacetField facetField) { // facet filtering by value requires that the facet values match the stored values // a *_facet field must exist, stored (or /w docValues) to be used for faceting and at filtering time if (doc.getFieldNames().contains(facetField.getName())) { // decrease facet value Collection<Object> docFieldValues = doc.getFieldValues(facetField.getName()); if (docFieldValues != null) { for (Object docFieldValue : docFieldValues) { String valueString = String.valueOf(docFieldValue); List<FacetField.Count> toRemove = new LinkedList<FacetField.Count>(); for (FacetField.Count count : facetField.getValues()) { long existingCount = count.getCount(); if (valueString.equals(count.getName())) { if (existingCount > 1) { // decrease the count count.setCount(existingCount - 1); } else { // remove the entire entry toRemove.add(count); } } } for (FacetField.Count f : toRemove) { assert facetField.getValues().remove(f); } } } } }
/** * Map facet field. * * @param facetField the facet field * @return the field facet result */ private static FieldFacetResult mapFacetField(final FacetField facetField) { final String fieldName = getReverseFacetFieldName(facetField.getName()); final FieldFacetResult result = new FieldFacetResult(fieldName); if (facetField.getValueCount() > 0) { for (final FacetField.Count count : facetField.getValues()) { if (count.getName() == null) { // missing count result.setMissingCount(count.getCount()); } else { result.addValue(count.getName(), count.getCount()); } } } return result; }
private void collectFacetCountsFor(Collection<FieldCount> facetFieldCounts, List<FacetField.Count> facetCounts, String searchFieldName, String[] prefixes) { if (facetCounts != null && !facetCounts.isEmpty()){ for (FacetField.Count count : facetCounts){ if (prefixes == null){ FieldCount fieldCount = new FieldCount(count.getName(), count.getCount(), searchFieldName); facetFieldCounts.add(fieldCount); } else { for (String prefix : prefixes){ if (prefix != null && count.getName().startsWith(prefix+":")){ FieldCount fieldCount = new FieldCount(count.getName(), count.getCount(), searchFieldName); facetFieldCounts.add(fieldCount); break; } } } } } }
public <T> List<T> getObjects() { Map<String, FacetField.Count> index = new HashMap<String, FacetField.Count>(); List<String> ids = new ArrayList<String>(); for (FacetField.Count c : this.field.getValues()) { index.put(c.getName(), c); ids.add(c.getName()); } @SuppressWarnings("unchecked") List<T> objects = (List<T>) (this.klass == null || this.klass == Query.class ? Query.fromAll().where("id = ?", ids).selectAll() : Query.from(this.klass).where("id = ?", ids).selectAll()); if (objects != null) { for (Object o : objects) { Record record = (Record) o; FacetField.Count c = index.get(record.getId().toString()); record.getState().getExtras().put("count", Long.valueOf(c.getCount())); } } return objects; } }
private static List<FacetFieldResult> processFacetFields(Facets facets, List<FacetField> facetFields) { List<FacetFieldResult> ret = new ArrayList<>(); FacetFieldResult facetResult; if (facetFields != null) { for (FacetField facet : facetFields) { LOGGER.trace("facet:{} count:{}", facet.getName(), facet.getValueCount()); facetResult = new FacetFieldResult(facet.getName(), facet.getValueCount(), facets.getParameters().get(facet.getName()).getValues()); for (Count count : facet.getValues()) { LOGGER.trace(" value:{} value:{}", count.getName(), count.getCount()); facetResult.addFacetValue(count.getName(), count.getName(), count.getCount()); } ret.add(facetResult); } } return ret; }
private SearchResultsBean searchTermsInternal(String searchQuery, String facetField, Map<String, String> attributes, UserRegistry registry) throws IndexerException, RegistryException { SearchResultsBean resultsBean = new SearchResultsBean(); SolrClient client = SolrClient.getInstance(); //authenticate required attribute is not used, since we are going to authorize each time and not depends on this flag. attributes.remove(IndexingConstants.AUTH_REQUIRED); List<FacetField.Count> results = (searchQuery == null) ? client.facetQuery(registry.getTenantId(), attributes) : client.facetQuery(searchQuery, facetField, registry.getTenantId()); if (log.isDebugEnabled()) { log.debug("result for the term search: " + results); } List<TermData> termDataList = new ArrayList<>(); for (FacetField.Count count : results) { termDataList.add(new TermData(count.getName(), count.getCount())); } resultsBean.setTermDataList(termDataList.toArray(new TermData[termDataList.size()])); return resultsBean; }
private static void facetFieldToXML(FacetField facet, XMLWriter xml) throws IOException { xml.openElement("facet"); xml.attribute("name", facet.getName()); xml.attribute("count", facet.getValueCount()); for (Count count : facet.getValues()) { xml.openElement("term"); xml.attribute("field", facet.getName()); xml.attribute("text", count.getName()); xml.attribute("cardinality", String.valueOf(count.getCount())); xml.closeElement(); } xml.closeElement(); } }
private static List<BaseCount> convertToSearchFacetFieldCounts( List<FacetField.Count> solrCounts) { List<BaseCount> searchCounts = new ArrayList<>(); if (solrCounts != null) { for (FacetField.Count solrCount : solrCounts) { searchCounts.add(new BaseCount(solrCount.getName(), solrCount .getCount())); } } return searchCounts; }
private void setFacets(List<FacetField> facetFields) { if(facetFields == null) { return; } DefaultListModel model = new DefaultListModel(); int i = 0; for(FacetField facet:facetFields) { for(Count count:facet.getValues()) { model.add(i++, facet.getName() + ":" + count.getName() + "(" + count.getCount() + ")"); } } jListFacets.setModel(model); }
private void collectFacetCountsFor(Collection<FieldCount> facetFieldCounts, List<FacetField.Count> facetCounts, String searchFieldName, String prefix) { if (facetCounts != null && !facetCounts.isEmpty()){ for (FacetField.Count count : facetCounts){ if (prefix == null || (prefix != null && count.getName().startsWith(prefix+":"))){ FieldCount fieldCount = new FieldCount(count.getName(), count.getCount(), searchFieldName); facetFieldCounts.add(fieldCount); } } } }
private void setFacetFieldCounts(FacetField facetField, Map<String, Long> countMap){ if ((facetField ==null)||(countMap==null)){ return; } for (FacetField.Count fcnt : facetField.getValues()){ countMap.put(fcnt.getName().toLowerCase().replace(" ", "_") + "_count", fcnt.getCount()); } }
private void collectFacetCountsFor(Collection<FieldCount> facetFieldCounts, List<FacetField.Count> facetCounts, String searchFieldName) { if (facetCounts != null && !facetCounts.isEmpty()){ for (FacetField.Count count : facetCounts){ FieldCount fieldCount = new FieldCount(count.getName(), count.getCount(), searchFieldName); facetFieldCounts.add(fieldCount); } } }