use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FacetScriptFacetsTest method testNullValue.
@Test
public void testNullValue() {
Facet facet = Facet.newBuilder().setScript(Script.newBuilder().setLang("test_lang").setSource("null").build()).setTopN(10).build();
SearchResponse response = doQuery(facet);
assertEquals(1, response.getFacetResultCount());
FacetResult result = response.getFacetResult(0);
assertEquals(100, result.getValue(), 0);
assertEquals(0, result.getChildCount());
assertEquals(0, result.getLabelValuesCount());
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FacetScriptFacetsTest method assertResponse.
private void assertResponse(SearchResponse response, double value, int childCount, int valuesCount, ExpectedValues... expectedValues) {
assertEquals(1, response.getFacetResultCount());
FacetResult result = response.getFacetResult(0);
assertEquals(value, result.getValue(), 0);
assertEquals(childCount, result.getChildCount());
assertEquals(valuesCount, result.getLabelValuesCount());
int sum = 0;
for (ExpectedValues v : expectedValues) {
sum += v.labels.size();
}
assertEquals(sum, valuesCount);
int valuesIndex = 0;
for (ExpectedValues v : expectedValues) {
Set<String> valueSet = new HashSet<>();
for (int i = 0; i < v.labels.size(); ++i) {
valueSet.add(result.getLabelValues(valuesIndex).getLabel());
assertEquals(v.count, result.getLabelValues(valuesIndex).getValue(), 0);
valuesIndex++;
}
assertEquals(v.labels, valueSet);
}
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FilteredSSDVFacetCountsTest method assertResponse.
private void assertResponse(SearchResponse response, int childCount, LabelAndValue... expectedValues) {
assertEquals(1, response.getFacetResultCount());
FacetResult result = response.getFacetResult(0);
assertEquals("test_facet", result.getName());
assertTrue(response.getDiagnostics().containsFacetTimeMs("test_facet"));
assertEquals(childCount, result.getChildCount());
assertEquals(expectedValues.length, result.getLabelValuesCount());
for (int i = 0; i < expectedValues.length; ++i) {
assertEquals(expectedValues[i].getLabel(), result.getLabelValues(i).getLabel());
assertEquals(expectedValues[i].getValue(), result.getLabelValues(i).getValue(), 0);
}
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class NumberFieldFacetsTest method assertNumericRangeFacet.
private void assertNumericRangeFacet(String fieldName) {
List<NumericRangeType> numericRangeTypes = new ArrayList<>();
numericRangeTypes.add(NumericRangeType.newBuilder().setLabel("1-10").setMin(1L).setMinInclusive(true).setMax(10L).setMaxInclusive(true).build());
numericRangeTypes.add(NumericRangeType.newBuilder().setLabel("11-20").setMin(11L).setMinInclusive(true).setMax(20L).setMaxInclusive(true).build());
SearchResponse response = getSearchResponse(fieldName, false, numericRangeTypes);
assertEquals(1, response.getFacetResultCount());
List<FacetResult> facetResults = response.getFacetResultList();
List<LabelAndValue> expectedLabelAndValues = new ArrayList<>();
expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("1-10").setValue(2.0).build());
expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("11-20").setValue(1.0).build());
assertFacetResult(facetResults.get(0), fieldName, 3, 2L, expectedLabelAndValues);
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class TextFieldFacetsTest method testFlatSingleValued.
@Test
public void testFlatSingleValued() {
SearchResponse response = getSearchResponse("flat_facet_field_single_valued");
assertEquals(1, response.getFacetResultCount());
List<FacetResult> facetResults = response.getFacetResultList();
List<LabelAndValue> expectedLabelAndValues = new ArrayList<>();
expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("John").setValue(3.0).build());
assertFacetResult(facetResults.get(0), "flat_facet_field_single_valued", 3, 1L, expectedLabelAndValues);
}
Aggregations