MCPcopy Index your code
hub / github.com/dgraph-io/dgraph / handleHasWithOrderFunction

Method handleHasWithOrderFunction

worker/task.go:2597–2677  ·  view source on GitHub ↗
(ctx context.Context, q *pb.Query, out *pb.Result,
	rev bool, offset, first int, srcFn *functionContext)

Source from the content-addressed store, hash-verified

2595}
2596
2597func (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

Callers 1

handleHasFunctionMethod · 0.95

Calls 9

IndexPrefixMethod · 0.95
getValsForUIDMethod · 0.95
IndexKeyFunction · 0.92
IndexKeyAfterAllTermsFunction · 0.92
langForFuncFunction · 0.85
needsStringFilteringFunction · 0.85
IterateDiskMethod · 0.80
SliceMethod · 0.80
UidsMethod · 0.45

Tested by

no test coverage detected