-
-
Notifications
You must be signed in to change notification settings - Fork 56
feat: add support for websearch_to_tsquery
#437
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
812cf40 to
b8a8436
Compare
WalkthroughAdds a new Doctrine DQL variadic function WebsearchToTsquery mapping to PostgreSQL WEBSEARCH_TO_TSQUERY, plus unit and integration tests validating SQL/DQL generation, argument bounds (1–2), and error behavior for invalid regconfig. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Developer
participant DQL as Doctrine DQL Parser
participant Fn as WebsearchToTsquery
participant DB as PostgreSQL
Developer->>DQL: SELECT WEBSEARCH_TO_TSQUERY('english', e.text1)
DQL->>Fn: construct function node with args
Note right of Fn #DDEEFE: validate argument count (1–2)\nmap node types to SQL
Fn-->>DQL: websearch_to_tsquery('english', c0_.text1)
DQL->>DB: execute SQL
alt valid regconfig
DB-->>DQL: return TSQuery string
else invalid regconfig
DB-->>DQL: DriverException (missing text search config)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
✨ 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/Issue comments)Type Other keywords and placeholders
Status, 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: 0
🧹 Nitpick comments (3)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (3)
21-26: Test name nit: clarify intentConsider a more descriptive name for discoverability.
- public function totsquery(): void + public function websearch_to_tsquery_produces_expected_tsquery(): void
28-35: Loosen error-message assertion for portabilityPG error wording/quotes can vary slightly across versions/locales. Make the regex case-insensitive and less brittle.
- $this->expectExceptionMessageMatches('/text search configuration "invalid_regconfig" does not exist/'); + $this->expectExceptionMessageMatches('/text search configuration .*invalid_regconfig.* does not exist/i');
20-26: Optional: add a 1-arg integration caseCovers default-config path end-to-end.
@@ #[Test] - public function totsquery(): void + public function websearch_to_tsquery_with_explicit_config(): void { @@ } + #[Test] + public function websearch_to_tsquery_with_default_config(): void + { + $dql = "SELECT websearch_to_tsquery('\"sad cat\" or \"fat rat\"') as result FROM Fixtures\\MartinGeorgiev\\Doctrine\\Entity\\ContainsTexts t WHERE t.id = 1"; + $result = $this->executeDqlQuery($dql); + $this->assertSame("'sad' <-> 'cat' | 'fat' <-> 'rat'", $result[0]['result']); + }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.php(1 hunks)tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php(1 hunks)tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php(1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#357
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpMatchTest.php:28-62
Timestamp: 2025-04-22T00:03:37.733Z
Learning: This project focuses on providing Doctrine ORM interfaces to PostgreSQL functions. Tests should validate correct DQL-to-SQL translation rather than PostgreSQL functionality itself. Test cases should focus on parameter passing and SQL generation, not on testing specific PostgreSQL regex pattern behaviors.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#352
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpInstrTest.php:1-67
Timestamp: 2025-04-20T11:24:18.300Z
Learning: This PostgreSQL-for-Doctrine project is a translation layer only, focusing on correctly converting Doctrine DQL to PostgreSQL SQL syntax. It ensures arguments are passed in the expected format but does not test or handle PostgreSQL's actual function behavior or data handling. Test cases should focus on DQL-to-SQL translation and argument validation, not on PostgreSQL-specific behaviors.
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#0
File: :0-0
Timestamp: 2025-08-24T16:52:32.488Z
Learning: All new features in this repository must include proper test coverage before approval - this ltree implementation demonstrates exemplary test coverage with comprehensive unit tests, integration tests, data providers for edge cases, and validation of all relationships and error conditions.
📚 Learning: 2025-04-22T00:03:37.733Z
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#357
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RegexpMatchTest.php:28-62
Timestamp: 2025-04-22T00:03:37.733Z
Learning: This project focuses on providing Doctrine ORM interfaces to PostgreSQL functions. Tests should validate correct DQL-to-SQL translation rather than PostgreSQL functionality itself. Test cases should focus on parameter passing and SQL generation, not on testing specific PostgreSQL regex pattern behaviors.
Applied to files:
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.phptests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.phptests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php
📚 Learning: 2025-03-29T03:31:17.114Z
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase, and therefore don't need an explicit import.
Applied to files:
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.phptests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.phptests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php
📚 Learning: 2025-05-23T11:11:57.951Z
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#383
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/RadiansTest.php:1-9
Timestamp: 2025-05-23T11:11:57.951Z
Learning: Tests in the `Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), rather than PHPUnit's TestCase directly, and therefore don't need an explicit import.
Applied to files:
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.phptests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.phptests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php
📚 Learning: 2025-03-29T03:31:17.114Z
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#318
File: tests/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/XmlAggTest.php:1-9
Timestamp: 2025-03-29T03:31:17.114Z
Learning: Tests in the `Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions` namespace extend a custom `TestCase` class from the same namespace (`Tests\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\TestCase`), not PHPUnit's TestCase, and therefore don't need an explicit import statement.
Applied to files:
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.phptests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.phptests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php
📚 Learning: 2025-09-01T18:48:28.508Z
Learnt from: martin-georgiev
PR: martin-georgiev/postgresql-for-doctrine#434
File: tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/PostGIS/ST_CrossesTest.php:12-31
Timestamp: 2025-09-01T18:48:28.508Z
Learning: When analyzing unit test files in this codebase, always verify the actual file structure and existing patterns before suggesting changes. The ContainsGeometries fixture exists at ./fixtures/MartinGeorgiev/Doctrine/Entity/ContainsGeometries.php and the PostGIS unit tests use the namespace Tests\Unit\MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\PostGIS consistently.
Applied to files:
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.phptests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php
🧬 Code graph analysis (3)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.php (1)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (1)
BaseVariadicFunction(20-143)
tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (4)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.php (1)
WebsearchToTsquery(15-36)tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (3)
Test(45-52)WebsearchToTsqueryTest(13-53)getStringFunctions(20-25)tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TextTestCase.php (1)
TextTestCase(9-48)tests/Integration/MartinGeorgiev/TestCase.php (1)
executeDqlQuery(271-285)
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (5)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunction.php (1)
BaseVariadicFunction(20-143)src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/Exception/InvalidArgumentForVariadicFunctionException.php (1)
InvalidArgumentForVariadicFunctionException(7-56)src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.php (1)
WebsearchToTsquery(15-36)tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/BaseVariadicFunctionTestCase.php (1)
BaseVariadicFunctionTestCase(17-106)tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/TestCase.php (1)
assertSqlFromDql(109-113)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (17)
- GitHub Check: PHP 8.3 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
- GitHub Check: PHP 8.2 + Doctrine ORM latest + Doctrine Lexer latest
- GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer 3.0
- GitHub Check: PHP 8.2 + Doctrine ORM 2.18 + Doctrine Lexer latest
- GitHub Check: PHP 8.1 + Doctrine ORM 2.14 + Doctrine Lexer latest
- GitHub Check: PHP 8.2 + Doctrine ORM 2.14 + Doctrine Lexer 2.1
- GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer latest
- GitHub Check: PHP 8.1 + Doctrine ORM 3.0 + Doctrine Lexer 3.0
- GitHub Check: PHP 8.1 + Doctrine ORM 2.18 + Doctrine Lexer 2.1
- GitHub Check: sloth
- GitHub Check: PostgreSQL 17 + PostGIS 3.4 + PHP 8.4
- GitHub Check: PostgreSQL 16 + PostGIS 3.5 + PHP 8.4
- GitHub Check: PostgreSQL 17 + PostGIS 3.5 + PHP 8.3
- GitHub Check: PostgreSQL 16 + PostGIS 3.5 + PHP 8.3
- GitHub Check: PostgreSQL 16 + PostGIS 3.4 + PHP 8.3
- GitHub Check: PostgreSQL 16 + PostGIS 3.5 + PHP 8.1
- GitHub Check: wait-for-tests-worflows-before-upload
🔇 Additional comments (10)
src/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsquery.php (4)
17-20: Node mapping looks correct for 1–2 string argsUsing a simple pattern allows both 1-arg (default config) and 2-arg (explicit regconfig) calls.
22-35: Function name and arity align with PostgreSQLName matches SQL function and min/max argument counts are correct.
7-14: Verify the @SInCE version tagConfirm the next library version before merging to avoid drift.
If needed, update inline:
- * @since 3.5 + * @since 3.x
17-35: No issues found in BaseVariadicFunction naming
The variable$isNodeMappingASimplePatternis consistently defined and used (lines 72 and 91), so there’s no typo to correct.tests/Integration/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (1)
13-18: Registration is correctLowercase DQL function name mapped to the class is consistent with the query usage below.
tests/Unit/MartinGeorgiev/Doctrine/ORM/Query/AST/Functions/WebsearchToTsqueryTest.php (5)
15-18: Fixture creation LGTMCorrectly instantiates with DQL name used in this test suite.
20-25: Function map LGTMUppercase alias mapping matches DQL in this file; case-insensitivity is exercised across unit/integration suites.
27-34: SQL expectations are preciseCovers default, expression, and explicit-config cases.
36-43: DQL generation coverage is sufficientMirrors SQL cases; good parity.
45-52: Too-many-args path tested correctlyException expectation with parser-driven getSQL() is the established pattern here.
b8a8436 to
2ea89bd
Compare
websearch_to_tsquery
|
Thanks @janklan - CI seems to be slightly off though. |
2ea89bd to
ee50f22
Compare
Sorry, it should be all good now. |
websearch_to_tsqueryis an alternative toto_tsquery, taking a more user-friendly input. I find it pretty useful, and I believe it would benefit users of this bundle.Summary by CodeRabbit
New Features
Tests