use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FacetTopDocs method facetTopDocsSample.
/**
* Compute facet aggregations based on a sample of the query's top ranked documents. Only
* processes facets that have sampleTopDocs set to a value greater than zero.
*
* @param topDocs top documents from query
* @param facets facet definition grpc messages
* @param indexState state for index
* @param searcher searcher for query
* @param diagnostics diagnostics builder for storing facet timing
* @return results for facets over top docs
* @throws IOException if error reading doc values
* @throws IllegalArgumentException if top docs facet field is not indexable or does not have doc
* values enabled
*/
public static Iterable<FacetResult> facetTopDocsSample(TopDocs topDocs, List<Facet> facets, IndexState indexState, IndexSearcher searcher, Diagnostics.Builder diagnostics) throws IOException {
List<Facet> sampleFacets = facets.stream().filter(facet -> facet.getSampleTopDocs() > 0).collect(Collectors.toList());
if (sampleFacets.isEmpty()) {
return Collections.emptyList();
}
List<FacetResult> facetResults = new ArrayList<>(sampleFacets.size());
for (Facet facet : sampleFacets) {
long startNS = System.nanoTime();
facetResults.add(facetFromTopDocs(topDocs, facet, indexState, searcher));
long endNS = System.nanoTime();
diagnostics.putFacetTimeMs(facet.getName(), (endNS - startNS) / 1000000.0);
}
return facetResults;
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FacetTopHitsTest method assertResponse.
private void assertResponse(SearchResponse response, double value, int childCount, int valuesCount, ExpectedValues... expectedValues) {
assertEquals(1, response.getFacetResultCount());
FacetResult result = response.getFacetResult(0);
assertTrue(response.getDiagnostics().containsFacetTimeMs("top_hits_facet"));
assertFacetResult(result, "top_hits_facet", value, childCount, valuesCount, expectedValues);
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class FacetTopHitsTest method testWithNonTopDocsFacet.
@Test
public void testWithNonTopDocsFacet() {
List<Facet> facetList = new ArrayList<>();
Facet facet = Facet.newBuilder().setName("top_hits_facet_100").setDim("long_field").setSampleTopDocs(100).setTopN(20).build();
facetList.add(facet);
List<NumericRangeType> numericRangeTypes = new ArrayList<>();
numericRangeTypes.add(NumericRangeType.newBuilder().setLabel("0-7").setMin(0L).setMinInclusive(true).setMax(7L).setMaxInclusive(true).build());
numericRangeTypes.add(NumericRangeType.newBuilder().setLabel("8-9").setMin(8L).setMinInclusive(true).setMax(9L).setMaxInclusive(true).build());
facet = Facet.newBuilder().setName("numeric_range").setDim("long_field").setUseOrdsCache(false).addAllNumericRange(numericRangeTypes).setTopN(20).build();
facetList.add(facet);
SearchResponse response = doQueryMulti(facetList, 10);
assertEquals(facetList.size(), response.getFacetResultCount());
FacetResult facetResult = response.getFacetResult(0);
assertEquals("numeric_range", facetResult.getName());
assertEquals(100, facetResult.getValue(), 0);
assertEquals(2, facetResult.getChildCount());
assertEquals(2, facetResult.getLabelValuesCount());
assertEquals("0-7", facetResult.getLabelValues(0).getLabel());
assertEquals(80.0, facetResult.getLabelValues(0).getValue(), 0);
assertEquals("8-9", facetResult.getLabelValues(1).getLabel());
assertEquals(20.0, facetResult.getLabelValues(1).getValue(), 0);
assertFacetResult(response.getFacetResult(1), "top_hits_facet_100", 100, 10, 10, new ExpectedValues(new HashSet<>(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")), 10));
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class TextFieldFacetsTest method testSortedDocValuesSingleValued.
@Test
public void testSortedDocValuesSingleValued() {
SearchResponse response = getSearchResponse("sorted_doc_values_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), "sorted_doc_values_facet_field_single_valued", 3, 1L, expectedLabelAndValues);
}
use of com.yelp.nrtsearch.server.grpc.FacetResult in project nrtsearch by Yelp.
the class TextFieldFacetsTest method testSortedDocValuesEmpty.
@Test
public void testSortedDocValuesEmpty() {
Facet.Builder facetBuilder = Facet.newBuilder().setName("test_name").setDim("sorted_doc_values_facet_field").setTopN(10);
SearchResponse response = getGrpcServer().getBlockingStub().search(SearchRequest.newBuilder().setIndexName(DEFAULT_TEST_INDEX).setTopHits(10).addFacets(facetBuilder.build()).setQuery(Query.newBuilder().setTermQuery(TermQuery.newBuilder().setField("sorted_doc_values_facet_field").setTextValue("unknown").build()).build()).build());
assertEquals(1, response.getFacetResultCount());
FacetResult result = response.getFacetResult(0);
assertEquals("test_name", result.getName());
assertEquals(0, result.getLabelValuesCount());
}
Aggregations