Search in sources :

Example 1 with Diagnostics

use of com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics 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)

Aggregations

Facet (com.yelp.nrtsearch.server.grpc.Facet)1 FacetResult (com.yelp.nrtsearch.server.grpc.FacetResult)1 Diagnostics (com.yelp.nrtsearch.server.grpc.SearchResponse.Diagnostics)1 IndexState (com.yelp.nrtsearch.server.luceneserver.IndexState)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 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 LeafReaderContext (org.apache.lucene.index.LeafReaderContext)1 ReaderUtil (org.apache.lucene.index.ReaderUtil)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 TopDocs (org.apache.lucene.search.TopDocs)1