singularity

用户问题

go is logging this line fmt.Printf(“🚩 %v”, filters) as [sign share] are those two values in filters which is supposed to be a []string

ChatGPT

Yes — if you’re seeing output like:

🚩 [sign share]

then filters is a []string{"sign", "share"}.

Explanation:

When you do:

fmt.Printf("🚩 %v", filters)

and filters is a []string, Go will print it in the default format:

[elem1 elem2 ...]

If you want to double-check the type or print with quotes (to catch whitespace or weirdness), you could do:

fmt.Printf("🚩 %#v\n", filters) // prints: []string{"sign", "share"}

If this isn’t what you expected filters to contain, the issue lies in how it’s being populated. Want to trace that next?

用户问题

func matchesAnyFilter(text string, filters []string) bool { text = strings.ToLower(text) for _, f := range filters { if strings.Contains(text, strings.ToLower(f)) { return true } } return false }

for _, record := range records {
	actionText := record.Action
	if source := record.Source; source != "" && source != "direct" {
		actionText = fmt.Sprintf("%s via %s", record.Action, source)
	}

	elapsed := now.Sub(record.CreatedAt)
	when := humanizeTimeAgo(elapsed)

	if len(filters) > 0 && !matchesAnyFilter(actionText, filters) {
		continue
	}

	result := map[string]any{
		"action":    actionText,
		"Location":  nil, // TODO: add location
		"when":      when,
		"user_name": record.MemberName,
	}

	results = append(results, result)
}

i only want to append to results if the actionText has a match in the filters when the filters but its not working

ChatGPT

Your code logic is mostly correct, but there’s a likely subtle issue in how actionText and the filters are structured or formatted. Let’s isolate what could be going wrong.

Possibilities:

  1. Filters like [“sign”, “share”] don’t match actionText = “Signed document via email” because matchesAnyFilter does a case-insensitive Contains, but doesn’t trim whitespace or normalize.
  2. Trailing or leading spaces in filters (e.g., " share" vs "share").
  3. Unicode weirdness, though unlikely if it’s plain ASCII.

Suggestions:

🔍 1. Print Debug with #v

Update your debug print to catch subtle issues:

fmt.Printf("🚩 filters: %#v, actionText: %q\n", filters, actionText)

✅ 2. Normalize and Trim Filters

Improve matchesAnyFilter defensively:

func matchesAnyFilter(text string, filters []string) bool {
	text = strings.ToLower(strings.TrimSpace(text))
	for _, f := range filters {
		f = strings.ToLower(strings.TrimSpace(f))
		if strings.Contains(text, f) {
			return true
		}
	}
	return false
}

✅ 3. Confirm actionText is what you think

Log inside the loop:

fmt.Printf("🧪 checking: %q against filters: %#v\n", actionText, filters)

If nothing gets appended, likely no match is happening — try a simple dummy filter like ["via"] and confirm it appends.

Want to test this exact path together with a mock record to confirm the behavior?

用户问题

actionText can be “signed” or “Shared via twitter” or “view” “viewed” etc

ChatGPT

Got it — sounds like the filter matching logic is too naive. Here’s the mismatch:

🔍 Problem:

You’re expecting filters like [“sign”, “share”] to match actions like:

But strings.Contains("signed", "sign") works, while strings.Contains("shared", "share") does too — but only if cases and spaces line up. More problematic:

✅ Fix Plan:

  1. Lowercase & trim both actionText and filters ✅
  2. Match using prefix/stem, not just contains

✂️ Better Matching (startsWith or root match):

If your filters are verbs, consider prefix matching instead of contains:

func matchesAnyFilter(text string, filters []string) bool {
	text = strings.ToLower(strings.TrimSpace(text))
	for _, f := range filters {
		f = strings.ToLower(strings.TrimSpace(f))
		if strings.HasPrefix(text, f) || strings.Contains(text, " "+f) {
			return true
		}
	}
	return false
}

Or use a simple stemming heuristic:

func matchesAnyFilter(text string, filters []string) bool {
	text = strings.ToLower(text)
	for _, f := range filters {
		f = strings.ToLower(f)
		if strings.Contains(text, f) {
			return true
		}
		// crude stem-based match
		if strings.HasSuffix(f, "e") && strings.Contains(text, f+"d") {
			return true // e.g., "share" matches "shared"
		}
		if strings.Contains(text, f+"ed") {
			return true // e.g., "view" matches "viewed"
		}
	}
	return false
}

Would you prefer to use proper stemming (e.g. porterstemmer) or keep it heuristic?

用户问题

text = strings.ToLower(strings.TrimSpace(text)) text will contain things like “viewed via xyx” “shared via zzz” etc, just match with the first word instead of the whole string as it will guaranteed contain the verb, the rest of the string is overmatching with strings we dont need

ChatGPT

Perfect — the cleanest fix is to just match filters against the first word of actionText.

🔧 Updated Matcher:

func matchesAnyFilter(text string, filters []string) bool {
	words := strings.Fields(strings.ToLower(strings.TrimSpace(text)))
	if len(words) == 0 {
		return false
	}
	first := words[0]
	for _, f := range filters {
		if first == strings.ToLower(strings.TrimSpace(f)) {
			return true
		}
	}
	return false
}

✅ Behavior:

This avoids false positives from the "via xyz" part and keeps intent tight.

Want to add plural/ed-form tolerance (e.g., “share” matching “shared”) too, or keep strict?