Skip to content

fix(core): rank Postgres prefix queries by the words typed; score titles - #2042

Merged
phernandez merged 1 commit into
mainfrom
fix/1981-1983-postgres-text-scores
Nov 4, 2026
Merged

phernandez merged 1 commit into
mainfrom
fix/1981-1983-postgres-text-scores

Conversation

@phernandez

Copy link
Copy Markdown
Member

Fixes #1981. Fixes #1983.

#1981: prefix queries collapse when a note has a longer matching word

  • A multi-word text query is a prefix AND query (project:* & status:*).
  • ts_rank keeps only the last lexeme a prefix operand matched. So a note that also contains project-tracker or project-status-monthly-report.md scored as if "project" appeared once, far from "status".
  • The reporter's repro is now a test. Before this change: B 0.751, M 0.185, N 0.185.
  • Every Postgres rank channel (document, row, chunk) now also ranks the exact form of the query (prefix markers removed) and keeps the better score.
  • Matching still uses the prefix query, so partial words like proj stat match and rank as before.
  • The relaxed retry rebinds the exact form along with the text.

#1983: title-only search reports 0.000

  • Title-only search now ranks the title tsvector against the title query.
  • The exact title still sorts first, through the existing leading_order_by.

Test plan

  • tests/repository/test_postgres_text_scores.py. All three were written first, and two failed with the reported numbers:
    • M and N score at least 0.8× B
    • proj stat still ranks
    • title hits score above 0, with the exact title first
  • Postgres, 4 workers: tests/repository, test_search_service, both search routers and test-int/mcp/test_search_integration.py. 1413 passed.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CMYVL4TcbWdXhdvAzxfqjo

#1981: a multi-word text query is a prefix AND query (project:* &
status:*). ts_rank keeps only the last lexeme a prefix operand matched,
so a note that also held a longer word starting with a query term
(project-tracker, project-status-monthly-report.md) scored as if the
term appeared once, far from the others: 0.185 against 0.751 for the
same text without that word. Every Postgres rank channel (document,
row, chunk) now also ranks the exact form of the query, with the prefix
markers removed, and keeps the better score. Matching still uses the
prefix query, so partial words like "proj stat" rank as before. Relaxed
retries rebind the exact form with the text.

#1983: a title-only search had no rank and reported 0.000 for every hit.
It now ranks the title tsvector against the title query; the exact title
still sorts first.

Fixes #1981. Fixes #1983.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CMYVL4TcbWdXhdvAzxfqjo
Signed-off-by: phernandez <paul@basicmachines.co>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 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-11-04T00:51:26.475262Z b209cda PR opened
ℹ️ 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 merged commit 3cc12fe into main Nov 4, 2026
50 checks passed
@phernandez
phernandez deleted the fix/1981-1983-postgres-text-scores branch November 4, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant