Search in sources :

Example 1 with FacetResult

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());
}
Also used : FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) Facet(com.yelp.nrtsearch.server.grpc.Facet) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Example 2 with FacetResult

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);
    }
}
Also used : FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) HashSet(java.util.HashSet)

Example 3 with FacetResult

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);
    }
}
Also used : FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult)

Example 4 with FacetResult

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);
}
Also used : NumericRangeType(com.yelp.nrtsearch.server.grpc.NumericRangeType) ArrayList(java.util.ArrayList) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) LabelAndValue(com.yelp.nrtsearch.server.grpc.LabelAndValue) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse)

Example 5 with FacetResult

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);
}
Also used : ArrayList(java.util.ArrayList) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) LabelAndValue(com.yelp.nrtsearch.server.grpc.LabelAndValue) SearchResponse(com.yelp.nrtsearch.server.grpc.SearchResponse) Test(org.junit.Test)

Aggregations

FacetResult (com.yelp.nrtsearch.server.grpc.FacetResult)17 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)11 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 LabelAndValue (com.yelp.nrtsearch.server.grpc.LabelAndValue)8 Facet (com.yelp.nrtsearch.server.grpc.Facet)4 NumericRangeType (com.yelp.nrtsearch.server.grpc.NumericRangeType)3 HashSet (java.util.HashSet)3 IOException (java.io.IOException)2 TopDocs (org.apache.lucene.search.TopDocs)2 ProfileResult (com.yelp.nrtsearch.server.grpc.ProfileResult)1 Diagnostics (com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics)1 SearchState (com.yelp.nrtsearch.server.grpc.SearchResponse.SearchState)1 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)1 LoadedDocValues (com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues)1 DrillSidewaysImpl (com.yelp.nrtsearch.server.luceneserver.facet.DrillSidewaysImpl)1 FacetTopDocs (com.yelp.nrtsearch.server.luceneserver.facet.FacetTopDocs)1 NumberFieldFacetsTest.assertFacetResult (com.yelp.nrtsearch.server.luceneserver.facet.NumberFieldFacetsTest.assertFacetResult)1 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)1 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)1