use of com.yelp.nrtsearch.server.grpc.Facet in project nrtsearch by Yelp.
the class FacetTopHitsTest method testFacetTopHitsSortField.
@Test
public void testFacetTopHitsSortField() {
Facet facet = Facet.newBuilder().setName("top_hits_facet").setDim("long_field").setSampleTopDocs(100).setTopN(20).build();
SearchResponse response = doSortQuery(facet, 100);
assertEquals(100, response.getHitsCount());
assertResponse(response, 100, 10, 10, new ExpectedValues(new HashSet<>(Arrays.asList("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")), 10));
facet = Facet.newBuilder().setName("top_hits_facet").setDim("long_field").setSampleTopDocs(9).setTopN(20).build();
response = doSortQuery(facet, 100);
assertEquals(100, response.getHitsCount());
assertResponse(response, 9, 2, 2, new ExpectedValues(new HashSet<>(Collections.singletonList("7")), 5), new ExpectedValues(new HashSet<>(Collections.singletonList("6")), 4));
facet = Facet.newBuilder().setName("top_hits_facet").setDim("long_field").setSampleTopDocs(31).setTopN(20).build();
response = doSortQuery(facet, 100);
assertEquals(100, response.getHitsCount());
assertResponse(response, 31, 4, 4, new ExpectedValues(new HashSet<>(Arrays.asList("6", "5")), 10), new ExpectedValues(new HashSet<>(Collections.singletonList("4")), 6), new ExpectedValues(new HashSet<>(Collections.singletonList("7")), 5));
facet = Facet.newBuilder().setName("top_hits_facet").setDim("long_field").setSampleTopDocs(66).setTopN(20).build();
response = doSortQuery(facet, 100);
assertEquals(100, response.getHitsCount());
assertResponse(response, 66, 8, 8, new ExpectedValues(new HashSet<>(Arrays.asList("1", "2", "3", "4", "5", "6")), 10), new ExpectedValues(new HashSet<>(Collections.singletonList("7")), 5), new ExpectedValues(new HashSet<>(Collections.singletonList("0")), 1));
}
use of com.yelp.nrtsearch.server.grpc.Facet in project nrtsearch by Yelp.
the class FacetTopHitsTest method testFieldNoDocValues.
@Test(expected = StatusRuntimeException.class)
public void testFieldNoDocValues() {
Facet facet = Facet.newBuilder().setName("top_hits_facet").setDim("no_doc_values").setSampleTopDocs(9).setTopN(1).build();
doQuery(facet, 10);
}
use of com.yelp.nrtsearch.server.grpc.Facet in project nrtsearch by Yelp.
the class DrillSidewaysImpl method fillFacetResults.
static void fillFacetResults(FacetsCollector drillDowns, FacetsCollector[] drillSideways, String[] drillSidewaysDims, ShardState shardState, List<Facet> grpcFacets, Map<String, FieldDef> dynamicFields, SearcherTaxonomyManager.SearcherAndTaxonomy searcherAndTaxonomyManager, List<com.yelp.nrtsearch.server.grpc.FacetResult> grpcFacetResults, Diagnostics.Builder diagnostics) throws IOException {
IndexState indexState = shardState.indexState;
Map<String, FacetsCollector> dsDimMap = new HashMap<String, FacetsCollector>();
if (drillSidewaysDims != null) {
for (int i = 0; i < drillSidewaysDims.length; i++) {
dsDimMap.put(drillSidewaysDims[i], drillSideways[i]);
}
}
// Holds already computed Facets, since more
// than one dimension can share a single
// index field name. We need one map for "normal" and
// another for SSDV facets because an app can index both
// into the same Lucene field (this is the default):
Map<String, Facets> indexFieldNameToFacets = new HashMap<String, Facets>();
Map<String, Facets> indexFieldNameToSSDVFacets = new HashMap<String, Facets>();
for (Facet facet : grpcFacets) {
// these facets will be created from the top docs
if (facet.getSampleTopDocs() != 0) {
continue;
}
long startNS = System.nanoTime();
com.yelp.nrtsearch.server.grpc.FacetResult facetResult;
if (facet.hasScript()) {
// this facet is a FacetScript, run script against all matching documents
facetResult = getScriptFacetResult(facet, drillDowns, indexState);
} else {
facetResult = getFieldFacetResult(drillDowns, dsDimMap, shardState, facet, dynamicFields, searcherAndTaxonomyManager, indexFieldNameToFacets);
}
if (facetResult != null) {
grpcFacetResults.add(facetResult);
}
long endNS = System.nanoTime();
diagnostics.putFacetTimeMs(facet.getName(), (endNS - startNS) / 1000000.0);
}
}
Aggregations