Skip to content

feat(mail): type: and reach: fields in mail search - #3372

Merged
leemour merged 2 commits into
mainfrom
feat/search-mail-type
Nov 25, 2026
Merged

leemour merged 2 commits into
mainfrom
feat/search-mail-type

Conversation

@leemour

@leemour leemour commented Nov 25, 2026

Copy link
Copy Markdown
Member

Task

Let memo filter mail by type and reach. memo searches mail only through cli-core's search (memo search mail), and a filter after the search would return short pages, so the filter has to run inside the query's SQL. Follows #3358 (store version 76: mailType, reach, typeSignal per email) and #3366 (sorting rules).

Why

The query language had no type or reach field. memo also had to copy SENDER_BOT_PREFIX and MAIL_TYPES, because cli-core 1.1.0 does not export them.

What

Query fields (src/search/lucene/registry.ts). Both are enum fields that take terms only and work in mail only. tg and max refuse them as mail fields (MAIL_FIELDS).

  • type: takes one of the 16 mail types: type:order OR type:bill, invoice -type:promotion.
  • reach: takes direct, group or broadcast: reach:direct.
  • A wrong value is refused and the error lists the values. Values are case-insensitive.

Untyped mail. Types are kept lazily, so a search can meet emails that have no stored type yet.

  • Fill before the search. mailIndexed in src/store/queries.ts runs storeMailTypes next to drainEmailIndex, but only when the query names type: or reach:. This is feat(mail): each email gets its own type and reach (store version 76) #3358's fill, 5,000 emails per write. It runs outside the search's read and outside its 2 s time limit. A search without these fields types nothing.
  • The compiler never writes. The compiler (src/store/sqlite/lucene-fields.ts) only reads, through the new typeCondition (src/store/sqlite/email-types.ts). typeWhere is now that function plus the fill.
    • When types are current, the filter uses the stored columns (emails_by_mail_type).
    • When they are not (a read-only open, or rankings and statistics, which skip the fill), the untyped emails are worked out in memory and only the ones that pass are kept. The time limit is checked between batches.
    • Whether types are current is asked once per query.

Output.

  • Email hits have MailFields.mailType and MailFields.reach.
  • In --json they appear as email.mail_type and email.reach, the snake_case output keys. They also appear on mail's text hit line.
  • A hit's page that is not typed yet is typed in memory in one batch (withTypes in emailHitsByPk).
  • The JSON schema keeps both as text: picklists push ENTITIES past what tsc will write into a declaration (TS7056).

Exports.

  • SENDER_BOT_PREFIX from @wirecat/cli-core/store.
  • MAIL_TYPES, MailType, REACHES and Reach from @wirecat/cli-core/store/areas (experimental).

Docs. The search reference (generated table, mail paragraph, local-only list), mail's help, and the glossary rows for mail type and reach.

Line limit. emails.ts group 1033 to 1038, for the batched hit typing.

No schema change.

Testing

  • New test in src/services/mail-search.test.ts:

    • a plain search types nothing;
    • a read-only open finds type:order OR type:BILL with no stored type and keeps none;
    • a writable search types all mail;
    • checks reach:group, negation with a word, a word with a type, hits carrying mailType/reach, wrong values, and tg refusing type:.
  • Local checks, one or two workers:

    • src/mail and src/services: 187 files, 2,389 tests.
    • src/store, src/cli/messenger and command lint: 370 files, 3,382 tests.
    • src/search, src/entities, the mail-types and version-76 tests: 19 files, 1,159 tests.
    • pnpm typecheck, biome on the changed files, pnpm docs:check, cli-dev api-report --check.
  • Timings on 100,000 synthetic emails, one run at load average 22–28:

    Search Time
    read-only, untyped store, type:order 1.83 s
    read-only, untyped store, hello reach:direct 1.49 s
    first type:order on a writable open (types all 100,000) 18.4 s
    warm type:order 33 ms
    warm type:order OR type:bill 35 ms
    warm reach:broadcast 72 ms
    warm hello type:personal 105 ms
    warm order -type:promotion 65 ms
    warm hello, no type field (baseline) 40 ms

    The page and script are in cli-testing, performance/mail/types. The read-only first search is close to the 2 s limit, and on a larger untyped store it may stop with "out of time". One search on a writable open fixes it for good.

🤖 Generated with Claude Code

leemour and others added 2 commits November 26, 2026 00:14
memo searches mail only through cli-core's search, and a filter after the
search returns short pages, so the type and reach filters run inside the
query's SQL.

- type: takes one of the 16 mail types, reach: direct, group or broadcast
  (enum fields, terms only, mail only; tg and max refuse them).
- A search that names either field first types the mail the store has not
  typed yet (storeMailTypes, 5,000 per write), outside the search's read and
  its 2 s time limit. The compiler itself never writes: when types are not
  current (a read-only open, or rankings and statistics that skip the fill)
  it works the untyped mail out in memory, checking the time limit between
  batches. A search without these fields types nothing.
- Email hits carry mailType and reach (mail_type and reach in --json, and on
  the text line); untyped hits get theirs worked out in memory for the page.
- SENDER_BOT_PREFIX is exported from ./store, MAIL_TYPES, MailType, REACHES
  and Reach from ./store/areas.
- The emails.ts line limit goes 1033 -> 1038 for the batched hit typing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@leemour
leemour merged commit 8118e5b into main Nov 25, 2026
41 checks passed
@leemour
leemour deleted the feat/search-mail-type branch November 25, 2026 23:22
leemour added a commit to WireCatLabs/cli-testing that referenced this pull request Nov 25, 2026
…415)

Adds a "Search by type and reach" section and `search.mjs` to
`performance/mail/types`, for
[cli-core#3372](WireCatLabs/cli-core#3372). It
times 100,000 synthetic emails, one run at a load average of 22–28:

- **First search on a writable open:** 18.4 s. This search types every
email first.
- **First search on a read-only open:** 1.5–1.8 s, close to the 2 s
search limit. Nothing is kept.
- **Warm searches:** 33–105 ms, against 40 ms for a plain word.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant