-
Notifications
You must be signed in to change notification settings - Fork 55
Fix missing throw on no FTS on not search #660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe 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
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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 readabilityMinor 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
📒 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 wellRequiring a fulltext index for both search and notSearch is logically correct and prevents unindexed scans.
| if ( | ||
| $filter->getMethod() === Query::TYPE_SEARCH || | ||
| $filter->getMethod() === Query::TYPE_NOT_SEARCH | ||
| ) { |
There was a problem hiding this comment.
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.”
- A test that
(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.
Summary by CodeRabbit