use of com.linkedin.restli.examples.greetings.api.SearchMetadata 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);
}
use of com.linkedin.restli.examples.greetings.api.SearchMetadata in project rest.li by linkedin.
the class TestCompressionServer method testSearchFacets.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "clientsCompressedResponsesBuilderDataProvider")
public void testSearchFacets(RestClient client, String operationsForCompression, RootBuilderWrapper<Long, Greeting> builders, ProtocolVersion protocolVersion) throws RemoteInvocationException {
Request<CollectionResponse<Greeting>> req = builders.findBy("SearchWithFacets").setQueryParam("tone", Tone.SINCERE).build();
ResponseFuture<CollectionResponse<Greeting>> future = client.sendRequest(req);
Response<CollectionResponse<Greeting>> response = future.getResponse();
checkHeaderForCompression(response, operationsForCompression, "finder:" + req.getMethodName());
SearchMetadata metadata = new SearchMetadata(response.getEntity().getMetadataRaw());
Assert.assertTrue(metadata.getFacets().size() > 0);
// "randomly" generated data is guaranteed to have positive number of each tone
}
use of com.linkedin.restli.examples.greetings.api.SearchMetadata in project rest.li by linkedin.
the class TestGreetingsClient method testSearchFacets.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "requestBuilderDataProvider")
public void testSearchFacets(RootBuilderWrapper<Long, Greeting> builders) throws RemoteInvocationException {
Request<CollectionResponse<Greeting>> req = builders.findBy("SearchWithFacets").setQueryParam("tone", Tone.SINCERE).build();
ResponseFuture<CollectionResponse<Greeting>> future = getClient().sendRequest(req);
Response<CollectionResponse<Greeting>> response = future.getResponse();
SearchMetadata metadata = new SearchMetadata(response.getEntity().getMetadataRaw());
Assert.assertTrue(metadata.getFacets().size() > 0);
// "randomly" generated data is guaranteed to have positive number of each tone
}
Aggregations