use of com.linkedin.restli.examples.greetings.api.ToneFacetArray in project rest.li by linkedin.
the class GreetingsResourceImpl method searchWithFacets.
@Finder("searchWithFacets")
public CollectionResult<Greeting, SearchMetadata> searchWithFacets(@PagingContextParam PagingContext ctx, @QueryParam("tone") @Optional Tone tone) {
List<Greeting> greetings = search(ctx, tone);
Map<Tone, Integer> toneCounts = new HashMap<Tone, Integer>();
for (Greeting g : greetings) {
if (!toneCounts.containsKey(g.getTone())) {
toneCounts.put(g.getTone(), 0);
}
toneCounts.put(g.getTone(), toneCounts.get(g.getTone()) + 1);
}
SearchMetadata metadata = new SearchMetadata();
metadata.setFacets(new ToneFacetArray());
for (Map.Entry<Tone, Integer> entry : toneCounts.entrySet()) {
ToneFacet f = new ToneFacet();
f.setTone(entry.getKey());
f.setCount(entry.getValue());
metadata.getFacets().add(f);
}
return new CollectionResult<Greeting, SearchMetadata>(greetings, null, metadata);
}
Aggregations