Search in sources :

Example 1 with SearchMetadata

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);
}
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)

Example 2 with SearchMetadata

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
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) SearchMetadata(com.linkedin.restli.examples.greetings.api.SearchMetadata) Test(org.testng.annotations.Test)

Example 3 with SearchMetadata

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
}
Also used : CollectionResponse(com.linkedin.restli.common.CollectionResponse) SearchMetadata(com.linkedin.restli.examples.greetings.api.SearchMetadata) Test(org.testng.annotations.Test)

Aggregations

SearchMetadata (com.linkedin.restli.examples.greetings.api.SearchMetadata)3 CollectionResponse (com.linkedin.restli.common.CollectionResponse)2 Test (org.testng.annotations.Test)2 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 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