code: func (e *executor) executeTopN(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) ([]Pair, error) {
  	span, ctx := tracing.StartSpanFromContext(ctx, "Executor.executeTopN")
  	defer span.Finish()
  
  	idsArg, _, err := c.UintSliceArg("ids")
  	if err != nil {
  		return nil, fmt.Errorf("executeTopN: %v", err)
  	}
  	n, _, err := c.UintArg("n")
  	if err != nil {
  		return nil, fmt.Errorf("executeTopN: %v", err)
  	}
  
  	// Execute original query.
  	pairs, err := e.executeTopNShards(ctx, index, c, shards, opt)
  	if err != nil {
  		return nil, errors.Wrap(err, "finding top results")
  	}
  
  	// If this call is against specific ids, or we didn't get results,
  	// or we are part of a larger distributed query then don't refetch.
  	if len(pairs) == 0 || len(idsArg) > 0 || opt.Remote {
  		return pairs, nil
  	}
  	// Only the original caller should refetch the full counts.
  	other := c.Clone()
  
  	ids := Pairs(pairs).Keys()
  	sort.Sort(uint64Slice(ids))
  	other.Args["ids"] = ids
  
  	trimmedList, err := e.executeTopNShards(ctx, index, other, shards, opt)
  	if err != nil {
  		return nil, errors.Wrap(err, "retrieving full counts")
  	}
  
  	if n != 0 && int(n) < len(trimmedList) {
  		trimmedList = trimmedList[0:n]
  	}
  	return trimmedList, nil
  }
docs: // executeTopN executes a TopN() call.
  // This first performs the TopN() to determine the top results and then
  // requeries to retrieve the full counts for each of the top results.