public Map<String, List<FacetTopic>> getFacets() { Map<String, List<FacetTopic>> result = new HashMap<String, List<FacetTopic>>(); for (String facetName : topic.keySet()) { List<FacetTopic> list = new ArrayList<FacetTopic>(); Multiset b = topic.get(facetName); for (Object topicName : b.elementSet()) { int count = b.count(topicName); // pour ajouter le topic il faut un minimum indique dans la query if (count >= query.getFacetMinCount()) { FacetTopic ft = new FacetTopic(facetName, String.valueOf(topicName), count); list.add(ft); } } // on re-tri si besoin, sinon l'ordre par defaut est sur la valeur des topics if (query.getFacetSort() == FacetSortType.count) { Collections.sort(list, query.getFacetSort().compartor); } // ... et on en prend que le nombre demande if (list.size() > query.getFacetLimit()) { list = list.subList(0, query.getFacetLimit()); } result.put(facetName, list); } return result; }
querySolr.setFacet(true); querySolr.setFacetMinCount(queryWithoutSelect.getFacetMinCount()); querySolr.setFacetLimit(queryWithoutSelect.getFacetLimit()); querySolr.setFacetSort(queryWithoutSelect.getFacetSort().solrValue);
@Override public boolean equals(Object o) { boolean result; if (o == null) { result = false; } else if (ObjectUtils.equals(this.getClass(), o.getClass())) { WikittyQuery other = (WikittyQuery)o; result = ObjectUtils.equals(this.getName(), other.getName()) && ObjectUtils.equals(this.getOffset(), other.getOffset()) && ObjectUtils.equals(this.getLimit(), other.getLimit()) && ObjectUtils.equals(this.isFacetExtension(), other.isFacetExtension()) && ObjectUtils.equals(this.getFacetField(), other.getFacetField()) && ObjectUtils.equals(this.getSortAscending(), other.getSortAscending()) && ObjectUtils.equals(this.getSortDescending(), other.getSortDescending()) && ObjectUtils.equals(this.getFacetLimit(), other.getFacetLimit()) && ObjectUtils.equals(this.getFacetSort(), other.getFacetSort()) && ObjectUtils.equals(this.getFacetMinCount(), other.getFacetMinCount()) && ObjectUtils.equals(this.getFacetQuery(), other.getFacetQuery()) && ObjectUtils.equals(this.getCondition(), other.getCondition()) && ObjectUtils.equals(this.getWikittyFieldSearchDepth(), other.getWikittyFieldSearchDepth()); } else { result = false; } return result; }
@Override public boolean visitEnter(WikittyQuery o) { WikittyQuery q = getQuery(); q.setFacetExtension(q.isFacetExtension()); q.setFacetField(new ArrayList<Element>(o.getFacetField())); q.setFacetLimit(o.getFacetLimit()); q.setFacetMinCount(o.getFacetMinCount()); q.setOffset(o.getOffset()); q.setLimit(o.getLimit()); q.setFacetSort(o.getFacetSort()); q.setName(o.getName()); q.setSortAscending(new ArrayList<Element>(o.getSortAscending())); q.setSortDescending(new ArrayList<Element>(o.getSortDescending())); q.setWikittyFieldSearchDepth(o.getWikittyFieldSearchDepth()); for (FacetQuery c : o.getFacetQuery()) { WikittyQueryVisitorCopy v = new WikittyQueryVisitorCopy(); c.getCondition().accept(v); Condition condition = v.getCondition(); q.addFacetQuery(c.getName(), condition); } return true; }