Search in sources :

Example 1 with FacetedQueryRequest

use of ddf.catalog.operation.impl.FacetedQueryRequest in project ddf by codice.

the class SolrProviderQuery method testFacetedResponse.

@Test
public void testFacetedResponse() throws Exception {
    deleteAll(provider);
    List<Metacard> metacards = new ArrayList<>();
    for (int i = 0; i < 9; i++) {
        Metacard metacard = new MetacardImpl();
        metacard.setAttribute(new AttributeImpl(Metacard.DESCRIPTION, "Description " + i / 2));
        metacards.add(metacard);
    }
    create(metacards, provider);
    Filter filter = getFilterBuilder().attribute(Metacard.DESCRIPTION).is().like().fuzzyText("Description");
    Response response = provider.query(new FacetedQueryRequest(new QueryImpl(filter), ImmutableSet.of(Metacard.DESCRIPTION)));
    Serializable rawFacetResult = response.getPropertyValue(EXPERIMENTAL_FACET_RESULTS_KEY);
    assertThat(rawFacetResult, notNullValue());
    assertThat(rawFacetResult, instanceOf(List.class));
    List<FacetAttributeResult> facetResult = (List<FacetAttributeResult>) rawFacetResult;
    assertThat(facetResult.size(), is(1));
    FacetAttributeResult descriptionResult = facetResult.get(0);
    assertThat(descriptionResult.getAttributeName(), is(Metacard.DESCRIPTION));
    assertThat(descriptionResult.getFacetValues().size(), is(5));
    List<FacetValueCount> facetValueCounts = descriptionResult.getFacetValues();
    Map<String, Long> expectedResults = ImmutableMap.of("Description 0", 2L, "Description 1", 2L, "Description 2", 2L, "Description 3", 2L, "Description 4", 1L);
    facetValueCounts.forEach(fvc -> {
        Long count = expectedResults.get(fvc.getValue());
        assertThat(count, notNullValue());
        assertThat(fvc.getCount(), is(count));
    });
}
Also used : Serializable(java.io.Serializable) FacetedQueryRequest(ddf.catalog.operation.impl.FacetedQueryRequest) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) FacetAttributeResult(ddf.catalog.operation.FacetAttributeResult) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FacetValueCount(ddf.catalog.operation.FacetValueCount) Response(ddf.catalog.operation.Response) SourceResponse(ddf.catalog.operation.SourceResponse) Metacard(ddf.catalog.data.Metacard) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SolrProviderTest(ddf.catalog.source.solr.SolrProviderTest) Test(org.junit.Test)

Aggregations

Metacard (ddf.catalog.data.Metacard)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 FacetAttributeResult (ddf.catalog.operation.FacetAttributeResult)1 FacetValueCount (ddf.catalog.operation.FacetValueCount)1 Response (ddf.catalog.operation.Response)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 FacetedQueryRequest (ddf.catalog.operation.impl.FacetedQueryRequest)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 SolrProviderTest (ddf.catalog.source.solr.SolrProviderTest)1 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Test (org.junit.Test)1 Filter (org.opengis.filter.Filter)1