(ctx context.Context, q *pb.Query, out *pb.Result, rev bool, offset, first int, srcFn *functionContext)
| 2595 | } |
| 2596 | |
| 2597 | func (qs *queryState) handleHasWithOrderFunction(ctx context.Context, q *pb.Query, out *pb.Result, |
| 2598 | rev bool, offset, first int, srcFn *functionContext) error { |
| 2599 | if first == 0 { |
| 2600 | first = math.MaxInt |
| 2601 | } |
| 2602 | |
| 2603 | initKey := x.ParsedKey{ |
| 2604 | Attr: q.Attr, |
| 2605 | } |
| 2606 | |
| 2607 | startKey := x.IndexKey(q.Attr, "") |
| 2608 | if rev { |
| 2609 | startKey = x.IndexKeyAfterAllTerms(q.Attr) |
| 2610 | } |
| 2611 | |
| 2612 | prefix := initKey.IndexPrefix() |
| 2613 | |
| 2614 | result := &pb.List{} |
| 2615 | |
| 2616 | lang := langForFunc(q.Langs) |
| 2617 | needFiltering := needsStringFiltering(srcFn, q.Langs, q.Attr) |
| 2618 | |
| 2619 | // This function checks if we should include uid in result or not when has is queried with |
| 2620 | // @lang(eg: has(name@en)). We need to do this inside this function to return correct result |
| 2621 | // for first. |
| 2622 | checkInclusion := func(uid uint64) error { |
| 2623 | if !needFiltering { |
| 2624 | return nil |
| 2625 | } |
| 2626 | |
| 2627 | _, err := qs.getValsForUID(q.Attr, lang, uid, q.ReadTs) |
| 2628 | return err |
| 2629 | } |
| 2630 | |
| 2631 | cnt := int32(0) |
| 2632 | |
| 2633 | iteratorFunc := &posting.IterateDiskArgs{ |
| 2634 | Prefix: prefix, |
| 2635 | ReadTs: q.ReadTs, |
| 2636 | AllVersions: false, |
| 2637 | Reverse: rev, |
| 2638 | CheckInclusion: func(uid uint64) error { |
| 2639 | return nil |
| 2640 | }, |
| 2641 | Function: func(l *posting.List, pk x.ParsedKey) error { |
| 2642 | pl, err := l.Uids(posting.ListOptions{ReadTs: q.ReadTs}) |
| 2643 | if err != nil { |
| 2644 | return err |
| 2645 | } |
| 2646 | |
| 2647 | if cnt < q.Offset { |
| 2648 | cnt++ |
| 2649 | return nil |
| 2650 | } |
| 2651 | |
| 2652 | for _, uid := range pl.Uids { |
| 2653 | if err := checkInclusion(uid); err != nil { |
| 2654 | continue |
no test coverage detected