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