Search in sources :

Example 1 with ToneFacetArray

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);
}
Also used : ToneFacet(com.linkedin.restli.examples.greetings.api.ToneFacet) Greeting(com.linkedin.restli.examples.greetings.api.Greeting) CollectionResult(com.linkedin.restli.server.CollectionResult) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Tone(com.linkedin.restli.examples.greetings.api.Tone) ToneFacetArray(com.linkedin.restli.examples.greetings.api.ToneFacetArray) SearchMetadata(com.linkedin.restli.examples.greetings.api.SearchMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EmptyMap(com.linkedin.restli.examples.greetings.api.EmptyMap) Map(java.util.Map) StringMap(com.linkedin.data.template.StringMap) Finder(com.linkedin.restli.server.annotations.Finder)

Aggregations

StringMap (com.linkedin.data.template.StringMap)1 EmptyMap (com.linkedin.restli.examples.greetings.api.EmptyMap)1 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)1 SearchMetadata (com.linkedin.restli.examples.greetings.api.SearchMetadata)1 Tone (com.linkedin.restli.examples.greetings.api.Tone)1 ToneFacet (com.linkedin.restli.examples.greetings.api.ToneFacet)1 ToneFacetArray (com.linkedin.restli.examples.greetings.api.ToneFacetArray)1 CollectionResult (com.linkedin.restli.server.CollectionResult)1 Finder (com.linkedin.restli.server.annotations.Finder)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1