Search in sources :

Example 16 with FacetResult

use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.

the class DocValuesFacetsTest 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("doc_values_facet", result.getName());
    assertTrue(response.getDiagnostics().containsFacetTimeMs("doc_values_facet"));
    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 17 with FacetResult

use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.

the class TextFieldFacetsTest method testHierarchyWithPath.

@Test
public void testHierarchyWithPath() {
    SearchResponse response = getSearchResponse("hierarchy_facet_field", "home");
    List<FacetResult> facetResults = response.getFacetResultList();
    List<LabelAndValue> expectedLabelAndValues = new ArrayList<>();
    expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("mike").setValue(1.0).build());
    expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("john").setValue(1.0).build());
    // NOTE: total number of buckets/value returned by FastTaxonomyFacetCounts is -1 on multivalued
    // fields.
    assertFacetResult(facetResults.get(0), "hierarchy_facet_field", -1, 2L, expectedLabelAndValues, "home");
    response = getSearchResponse("hierarchy_facet_field", "home", "john");
    facetResults = response.getFacetResultList();
    expectedLabelAndValues = new ArrayList<>();
    expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("work").setValue(1.0).build());
    expectedLabelAndValues.add(LabelAndValue.newBuilder().setLabel("personal").setValue(1.0).build());
    // NOTE: total number of buckets/value returned by FastTaxonomyFacetCounts is -1 on multivalued
    // fields.
    assertFacetResult(facetResults.get(0), "hierarchy_facet_field", -1, 2L, expectedLabelAndValues, "home", "john");
}
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