Skip to content

Conversation

@abnegate
Copy link
Member

@abnegate abnegate commented Aug 11, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Full-text filter validation now also applies to negated search filters, ensuring a matching full-text index is required. This prevents unindexed queries from bypassing validation and aligns behavior with standard search filters. Users may encounter clearer validation errors when using negated full-text filters without an appropriate index, prompting index creation for consistent performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Walkthrough

The validation logic in IndexedQueries.php now checks for fulltext index requirements when filters are of type TYPE_SEARCH or TYPE_NOT_SEARCH. Previously, only TYPE_SEARCH triggered this validation. No public API signatures were changed.

Changes

Cohort / File(s) Summary
Validator logic update
src/Database/Validator/IndexedQueries.php
Expanded condition to validate fulltext index for both TYPE_SEARCH and TYPE_NOT_SEARCH filters; unchanged overall validation flow and no public signature changes.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Validator
  participant IndexCatalog as FulltextIndexCatalog

  Client->>Validator: validate(filter)
  alt filter.type in {TYPE_SEARCH, TYPE_NOT_SEARCH}
    Validator->>IndexCatalog: hasFulltextIndex(filter.attribute)
    alt index exists
      Validator-->>Client: ok
    else
      Validator-->>Client: error (missing fulltext index)
    end
  else
    Validator-->>Client: ok (no fulltext check)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

I twitch my ears at queries’ tread,
Now search and not-search both are fed—
With indexed crumbs to swiftly find,
No missing maps to lag behind.
A hop, a skip, a speedier trail,
Fulltext ready, we won’t fail! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-catch-not-search

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/Database/Validator/IndexedQueries.php (1)

94-97: Simplify condition with in_array for readability

Minor cleanup to avoid repeating getMethod():

-            if (
-                $filter->getMethod() === Query::TYPE_SEARCH ||
-                $filter->getMethod() === Query::TYPE_NOT_SEARCH
-            ) {
+            if (\in_array($filter->getMethod(), [Query::TYPE_SEARCH, Query::TYPE_NOT_SEARCH], true)) {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61dd323 and d9bf1e0.

📒 Files selected for processing (1)
  • src/Database/Validator/IndexedQueries.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/Database/Validator/IndexedQueries.php (1)
src/Database/Query.php (2)
  • getMethod (122-125)
  • Query (8-836)
🔇 Additional comments (1)
src/Database/Validator/IndexedQueries.php (1)

94-97: Correctly enforce FTS for NOT_SEARCH as well

Requiring a fulltext index for both search and notSearch is logically correct and prevents unindexed scans.

Comment on lines +94 to +97
if (
$filter->getMethod() === Query::TYPE_SEARCH ||
$filter->getMethod() === Query::TYPE_NOT_SEARCH
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Add/verify tests for NOT_SEARCH requiring FTS

Please ensure we have coverage that fails validation when using notSearch without a fulltext index and passes when the index exists.

Run this to check for existing tests; I can help add them if missing:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Look for notSearch usage in tests and any assertion on the FTS requirement
rg -n -S "TYPE_NOT_SEARCH|notSearch"
rg -n -S "requires a fulltext index"

Length of output: 4482


Add tests for notSearch requiring fulltext index
We need to cover the new Query::TYPE_NOT_SEARCH path in the fulltext‐index validator to ensure it fails when no FTS index exists and passes when one does.

Please add test cases in:

  • tests/unit/Validator/IndexedQueriesTest.php
    • A test that $validator->isValid(Query::notSearch('name', 'foo')) returns false and $validator->getDescription() equals
      "Searching by attribute \"name\" requires a fulltext index." when no fulltext index is defined.
    • A test that the same query returns true when the mock index list includes a fulltext index on “name.”

(Optional) Extend your end-to-end suite as well:

  • tests/e2e/Adapter/Scopes/GeneralTests.php – cover notSearch against a table without and with an FTS index.

Sample snippet for IndexedQueriesTest.php:

public function testNotSearchRequiresFulltextIndex(): void
{
    $validator = new IndexedQueries(['description'], []); // no fulltext index on 'name'
    $filter    = Query::notSearch('name', 'foo');

    $this->assertFalse($validator->isValid($filter));
    $this->assertEquals(
        'Searching by attribute "name" requires a fulltext index.',
        $validator->getDescription()
    );

    // Now allow fulltext on 'name'
    $validatorWithFTS = new IndexedQueries(['description'], ['name']);
    $this->assertTrue($validatorWithFTS->isValid($filter));
}
🤖 Prompt for AI Agents
In src/Database/Validator/IndexedQueries.php around lines 94-97 the branch
handling Query::TYPE_NOT_SEARCH was added but lacks unit coverage; add tests in
tests/unit/Validator/IndexedQueriesTest.php that create an IndexedQueries
instance without a fulltext index for 'name', assert
$validator->isValid(Query::notSearch('name','foo')) returns false and
$validator->getDescription() equals "Searching by attribute \"name\" requires a
fulltext index.", then create a second IndexedQueries instance that includes
'name' in the FTS list and assert isValid returns true; optionally add
corresponding e2e cases in tests/e2e/Adapter/Scopes/GeneralTests.php to exercise
notSearch against a table without and with an FTS index.

@abnegate abnegate merged commit eaa4e27 into main Aug 11, 2025
15 checks passed
@abnegate abnegate deleted the fix-catch-not-search branch August 11, 2025 13:56
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.

2 participants