Skip to content

fix(core): quote punctuated words one by one in SQLite full-text queries - #1695

Merged
phernandez merged 4 commits into
mainfrom
fix/1657-quote-punctuated-words
Oct 9, 2026
Merged

phernandez merged 4 commits into
mainfrom
fix/1657-quote-punctuated-words

Conversation

@phernandez

Copy link
Copy Markdown
Member

Fixes #1657. Ported from @dougvann's fix (d498fed on his fork). His commit had no DCO sign-off and targets the pre-refactor module, so I ported it onto sqlite_search_query.py and credited him with Co-authored-by.

Why

In a multi-word query, one word with FTS5-significant punctuation (IT-644, #344, --diff, config.json) made prepare_single_term quote the whole query as one exact phrase. A phrase only matches adjacent words in order, so IT-644 cacheability returned nothing although both words are in the note.

The title of #1657 points at the content_stems cap, but that isn't what hid the matches. On SQLite, queries also match content_snippet, which holds the full body (since 5e4b119). On Postgres, the full body is indexed in chunks since #1373. I confirmed live that a token 57 KB into a note is found.

Change

  • Each punctuated word is quoted as its own phrase, and every word is AND-joined: "IT-644"* AND cacheability*.
  • A caller-quoted phrase stays one unit, and a single caller-quoted term isn't quoted again.
  • A file path keeps its exact match, with no prefix wildcard.
  • A word with no letters or digits (&) is dropped. It has no tokens in the index, and as an empty phrase it would make the AND match nothing. test_search_special_characters_in_title caught this with Note & Symbols!.

Tests

  • Four whole-phrase assertions are updated to the per-word form.
  • @dougvann's identifier cases are added (IT-644, #344 #336, --diff, queue:run, caller-quoted phrases), plus the file-path and & cases.
  • New end-to-end repository test: a note with "IT-644" and "cacheability" in different sentences is found by IT-644 cacheability.
  • just fast-check is clean. just fast-test on every test module that touches term preparation, the search service, the search tool, and the search integration tests: 265 passed, 31 skipped (Postgres-only).
  • Live MCP probe on this branch: IT-644 cacheability now hits. Before, it missed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01APFUk2bjEwMptMQqpRhjea

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T03:24:35.263153Z f2a5718 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@phernandez phernandez added this to the v0.24.0 milestone Oct 9, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0c7a306a28

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@phernandez
phernandez force-pushed the fix/1657-quote-punctuated-words branch from 0edc2f8 to e375b28 Compare October 9, 2026 02:24

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e375b283ca

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

phernandez and others added 3 commits October 8, 2026 21:37
A multi-word query where any word carried FTS5-significant punctuation
(IT-644, #344, --diff, config.json) was quoted whole, as one exact
phrase. A phrase needs its words adjacent and in order, so
"IT-644 cacheability" returned nothing although both words are in the
note (#1657).

Each punctuated word is now quoted as its own phrase and every word is
AND-joined, so order and distance do not matter. A phrase the caller
quoted stays one unit, a single caller-quoted term is not quoted twice,
a file path keeps its exact match, and a word with no letters or digits
("&") is dropped: it has no tokens in the index, and as an empty phrase
it would make the AND match nothing.

Ported from @dougvann's fix (d498fed on his fork) onto the current
query module, with his test cases.

Co-authored-by: doug vann <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01APFUk2bjEwMptMQqpRhjea
Signed-off-by: phernandez <[email protected]>
…uery

`IT-644 cache*` became `"IT-644"* AND cache**`, which FTS5 rejects with a
syntax error. A word's own trailing `*` is now stripped before quoting
and added back once, so `cache*` stays `cache*` and `IT-6*` becomes
`"IT-6"*`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01APFUk2bjEwMptMQqpRhjea
Signed-off-by: phernandez <[email protected]>
`IT-644 *cache` became `"IT-644"* AND *cache*`, and FTS5 rejects the
bare leading `*`, so the search returned nothing. A `*` left anywhere
but the end of a word now makes the word a quoted phrase, which the
tokenizer reads as `cache`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01APFUk2bjEwMptMQqpRhjea
Signed-off-by: phernandez <[email protected]>
@phernandez
phernandez force-pushed the fix/1657-quote-punctuated-words branch from 037fc17 to 6cea5d8 Compare October 9, 2026 02:47
Postgres turned every `*` in a term into `:*` before splitting words, so
`foo cache*` became `foo cache:*`: two operands with no `&`, which
to_tsquery rejects, and the search returned nothing. Only a single token
is converted whole now; in a multi-word query each word handles its own
wildcard (a trailing `*` makes it a prefix term, any other `*` is
dropped) and the words join with `&`. CI caught this through the new
end-to-end `IT-644 cache*` check, which runs on both backends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01APFUk2bjEwMptMQqpRhjea
Signed-off-by: phernandez <[email protected]>
@phernandez
phernandez merged commit 523ee41 into main Oct 9, 2026
32 checks passed
@phernandez
phernandez deleted the fix/1657-quote-punctuated-words branch October 9, 2026 03:45
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.

MAX_CONTENT_STEMS_SIZE truncates FTS on SQLite; make backend-conditional or configurable

1 participant