Returns true if string A contains string B as a substring.
| Field | Type | Description |
|---|---|---|
A | *string | String to search in |
B | *string | Substring to search for |
| Field | Type | Description |
|---|---|---|
Match | bool | True when A contains B |
Checks whether a customer support message contains the word "cancel" for churn routing.
package main
import (
"context"
"encoding/json"
"log"
"os"
"time"
"github.com/akennis/sparsi-go/library"
_ "github.com/akennis/dagor/operator/builtin"
"github.com/panjf2000/ants/v2"
"github.com/akennis/dagor"
"github.com/akennis/dagor/graph"
)
func main() {
text, keyword := "Please cancel my subscription immediately.", "cancel"
library.RegisterConst("msg_text", text)
library.RegisterConst("keyword", keyword)
g, err := graph.NewBuilder("strcontains_demo").
Vertex("src_a").Op("msg_text").Output("Result", "wire_a").
Vertex("src_b").Op("keyword").Output("Result", "wire_b").
Vertex("check").Op("IfStringContainsOp").
Input("A", "wire_a").Input("B", "wire_b").
Output("Match", "found").
Build()
if err != nil {
log.Fatalf("build: %v", err)
}
pool, err := ants.NewPool(4)
if err != nil {
log.Fatalf("pool: %v", err)
}
defer pool.Release()
eng, err := dagor.NewEngine(g, pool)
if err != nil {
log.Fatalf("engine: %v", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := eng.Run(ctx); err != nil {
log.Fatalf("run: %v", err)
}
out := map[string]any{"text": text, "keyword": keyword}
if raw, ok := eng.GetOutput("found"); ok {
out["keyword_found"] = *raw.(*bool)
}
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
enc.Encode(out)
}