MCPcopy
hub / github.com/dgraph-io/dgraph / handleMatchFunction

Method handleMatchFunction

worker/task.go:1526–1621  ·  view source on GitHub ↗
(ctx context.Context, arg funcArgs)

Source from the content-addressed store, hash-verified

1524}
1525
1526func (qs *queryState) handleMatchFunction(ctx context.Context, arg funcArgs) error {
1527 span := trace.SpanFromContext(ctx)
1528 stop := x.SpanTimer(span, "handleMatchFunction")
1529 defer stop()
1530 span.AddEvent("Processing UIDs", trace.WithAttributes(
1531 attribute.Int64("uid_count", int64(arg.srcFn.n)),
1532 attribute.String("srcFn", x.SafeUTF8(fmt.Sprintf("%+v", arg.srcFn)))))
1533
1534 attr := arg.q.Attr
1535 typ := arg.srcFn.atype
1536
1537 span.AddEvent("Attribute information", trace.WithAttributes(
1538 attribute.String("attr", attr),
1539 attribute.String("type", typ.Name())))
1540 var uids *pb.List
1541 switch {
1542 case !typ.IsScalar():
1543 return errors.Errorf("Attribute not scalar: %s %v", attr, typ)
1544
1545 case typ != types.StringID:
1546 return errors.Errorf("Got non-string type. Fuzzy match is allowed only on string type.")
1547
1548 case arg.q.UidList != nil && len(arg.q.UidList.Uids) != 0:
1549 uids = arg.q.UidList
1550
1551 case schema.State().HasTokenizer(ctx, tok.IdentTrigram, attr):
1552 var err error
1553 uids, err = uidsForMatch(attr, arg)
1554 if err != nil {
1555 return err
1556 }
1557
1558 default:
1559 return errors.Errorf(
1560 "Attribute %v does not have trigram index for fuzzy matching. "+
1561 "Please add a trigram index or use has/uid function with match() as filter.",
1562 x.ParseAttr(attr))
1563 }
1564
1565 isList := schema.State().IsList(attr)
1566 lang := langForFunc(arg.q.Langs)
1567 span.AddEvent("Result UID information", trace.WithAttributes(
1568 attribute.Int("uid_count", len(uids.Uids)),
1569 attribute.Bool("is_list", isList),
1570 attribute.String("lang", lang)))
1571 arg.out.UidMatrix = append(arg.out.UidMatrix, uids)
1572
1573 matchQuery := strings.Join(arg.srcFn.tokens, "")
1574 filtered := &pb.List{}
1575 for _, uid := range uids.Uids {
1576 select {
1577 case <-ctx.Done():
1578 return ctx.Err()
1579 default:
1580 }
1581 pl, err := qs.cache.Get(x.DataKey(attr, uid))
1582 if err != nil {
1583 return err

Callers 1

helpProcessTaskMethod · 0.95

Calls 15

SpanTimerFunction · 0.92
SafeUTF8Function · 0.92
StateFunction · 0.92
ParseAttrFunction · 0.92
DataKeyFunction · 0.92
ConvertFunction · 0.92
IntersectWithFunction · 0.92
uidsForMatchFunction · 0.85
langForFuncFunction · 0.85
matchFuzzyFunction · 0.85
IsScalarMethod · 0.80
HasTokenizerMethod · 0.80

Tested by

no test coverage detected