Skip to content

feat(query): execute Boolean FTS predicates (#2006) - #2012

Merged
Sinity merged 1 commit into
masterfrom
feature/feat/query-boolean-fts-2006
Jun 17, 2026
Merged

Sinity merged 1 commit into
masterfrom
feature/feat/query-boolean-fts-2006

Conversation

@Sinity

@Sinity Sinity commented Jun 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds executable lexical predicates to the #2006 Boolean DSL. ~term and ~"quoted phrase" now parse into a typed QueryTextPredicate and lower into a correlated FTS5 filter against messages_fts joined through blocks.

Problem

After #2011, the DSL could execute session fields, structural exists(...), and action seq(...), but lexical text inside Boolean predicates was still not representable. That meant users could not write queries such as sessions where origin:chatgpt-export AND ~"timeout failure" without dropping back to the older flat ranked FTS path.

Solution

Introduced QueryTextPredicate, extended the Lark Boolean grammar with ~text / ~"phrase", and wired the archive Boolean lowerer to messages_fts MATCH ?. Because messages_fts is contentless and its unindexed columns read back as NULL, the lowerer joins blocks by rowid for session correlation, matching the existing search path's storage reality. This PR gives Boolean FTS filter semantics; the existing flat query-term path remains the ranked lexical search path.

Verification

  • nix develop --command devtools test tests/unit/cli/test_query_expression.py -> 190 passed in 24.52s
  • nix develop --command devtools verify --quick -> exit_code: 0
  • pre-push devtools verify --quick on pushed branch -> exit_code: 0

Ref #2006

@coderabbitai

coderabbitai Bot commented Jun 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 35 minutes and 49 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2e8ee3db-1fa6-4aee-bf87-e7c8eaeed97a

📥 Commits

Reviewing files that changed from the base of the PR and between def884e and 2455dab.

📒 Files selected for processing (4)
  • polylogue/archive/query/expression.py
  • polylogue/archive/query/predicate.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • tests/unit/cli/test_query_expression.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/feat/query-boolean-fts-2006

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Sinity

Sinity commented Jun 17, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@Sinity
Sinity force-pushed the feature/feat/query-boolean-fts-2006 branch from 0206a10 to 2455dab Compare June 17, 2026 02:06
@Sinity
Sinity merged commit a30dc78 into master Jun 17, 2026
13 checks passed
@Sinity
Sinity deleted the feature/feat/query-boolean-fts-2006 branch June 17, 2026 02:08

@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: 0206a108c9

ℹ️ 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".

return _field_token_to_predicate(_QUERY_TRANSFORMER.field_clause(token))

def fts_quoted_leaf(self, token: Token) -> QueryPredicate:
return QueryTextPredicate(text=_decode_escaped_string(Token("ESCAPED_STRING", str(token)[1:])))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve phrase semantics for quoted FTS predicates

For ~"timeout failure", this decodes the token to timeout failure and drops any marker that it was quoted. _fts_predicate_clause later passes that through normalize_fts5_query, which leaves timeout failure unquoted; in FTS5 that matches rows containing both terms anywhere, so a session with timeout ... failure satisfies a query documented as a quoted phrase. Preserve the quoted form or a quoted flag through QueryTextPredicate so MATCH receives an exact phrase query.

Useful? React with 👍 / 👎.

Comment on lines +4497 to +4501
FROM messages_fts
JOIN blocks filter_fts_blocks
ON filter_fts_blocks.rowid = messages_fts.rowid
WHERE filter_fts_blocks.session_id = {table_alias}.session_id
AND messages_fts MATCH ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Guard Boolean FTS filters with index readiness checks

This new subquery is reached from list_summaries and count_sessions via _session_filter_clause, but those paths do not call _ensure_messages_fts_ready before referencing messages_fts (unlike search_summaries, which does). On archives where the FTS table is missing or incomplete, sessions where ~timeout can surface a raw SQLite error or produce incorrect false negatives instead of the established sanitized “Search index” degradation with a repair hint.

Useful? React with 👍 / 👎.

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