Search in sources :

Example 41 with Facet

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

Example 42 with Facet

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

Example 43 with Facet

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);
    }
}
Also used : Facets(org.apache.lucene.facet.Facets) HashMap(java.util.HashMap) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) FacetsCollector(org.apache.lucene.facet.FacetsCollector) Facet(com.yelp.nrtsearch.server.grpc.Facet)

Aggregations

Facet (com.yelp.nrtsearch.server.grpc.Facet)43 Test (org.junit.Test)41 SearchResponse (com.yelp.nrtsearch.server.grpc.SearchResponse)29 HashSet (java.util.HashSet)28 FacetResult (com.yelp.nrtsearch.server.grpc.FacetResult)3 ArrayList (java.util.ArrayList)3 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)2 HashMap (java.util.HashMap)2 NumericRangeType (com.yelp.nrtsearch.server.grpc.NumericRangeType)1 Diagnostics (com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics)1 LoadedDocValues (com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues)1 FieldDef (com.yelp.nrtsearch.server.luceneserver.field.FieldDef)1 IndexableFieldDef (com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef)1 IOException (java.io.IOException)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Facets (org.apache.lucene.facet.Facets)1 FacetsCollector (org.apache.lucene.facet.FacetsCollector)1