Search in sources :

Example 11 with FacetResult

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;
}
Also used : Diagnostics(com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics) ReaderUtil(org.apache.lucene.index.ReaderUtil) TopDocs(org.apache.lucene.search.TopDocs) IOException(java.io.IOException) HashMap(java.util.HashMap) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) IndexState(com.yelp.nrtsearch.server.luceneserver.IndexState) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) List(java.util.List) IndexableFieldDef(com.yelp.nrtsearch.server.luceneserver.field.IndexableFieldDef) Map(java.util.Map) LeafReaderContext(org.apache.lucene.index.LeafReaderContext) Collections(java.util.Collections) Facet(com.yelp.nrtsearch.server.grpc.Facet) LoadedDocValues(com.yelp.nrtsearch.server.luceneserver.doc.LoadedDocValues) FieldDef(com.yelp.nrtsearch.server.luceneserver.field.FieldDef) IndexSearcher(org.apache.lucene.search.IndexSearcher) ArrayList(java.util.ArrayList) FacetResult(com.yelp.nrtsearch.server.grpc.FacetResult) Facet(com.yelp.nrtsearch.server.grpc.Facet)

Example 12 with FacetResult

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

Example 13 with FacetResult

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

Example 14 with FacetResult

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);
}
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)

Example 15 with FacetResult

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());
}
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)

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