(ctx context.Context, arg funcArgs)
| 1524 | } |
| 1525 | |
| 1526 | func (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 |
no test coverage detected