-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Fixed broken search in PostgreSQL #6262
Conversation
No need to lynch yourself :) Do you think this is a real fix, though? If I understand things correctly, the initial problem was an incorrect query with an empty WHERE statement, because there are no any $queryTermConditions. Adding a bogus condition just to make the |
That would be counter-intuitive. Imagine: you type text into the search box and see ALL entries as if they all contained that text (in fact none of them). You could add an infeasible condition, like WHERE 1 = 2 😄 But that wouldn't be any better: some developer would go crazy once he uses the profiler and sees the queries. |
Right, so the problem you have is when someone searches for a string in a controller that only deals with numbers. Then the array of conditions is empty, and the result is intended to be always empty as well as there can't be any matches. Wouldn't in this case make sense to just return an empty iterator instead of running a SQL query that we know will yield no results? Looking at the code, it's probably not as easy to do that. With that in mind, I think this would be a viable solution developers would not freak about. Right under the massive if/else statement:
At least you can easily find the source of the query by searching for "look-for-this-string-in-the-source-code-for-more-info" in the code :D |
In general, you're right. But I'm pretty sure it's impossible without extensive refactoring, which will be backwards-incompatible. This QueryBuilder already exists in the user-space, and all we can/should do is refine its conditions. Just saw the second part of your comment. I hope you're not serious :D |
The aesthetics of this |
I was dead serious. Another thought: |
I would suggest similar solution as suggested by @janklan but without imbricated conditions: $queryTermConditions = new Orx();
foreach ($searchablePropertiesConfig as $propertyConfig) {
// All conditions...
}
/** Add this */
// No searchable property => return empty result
if ($queryTermConditions->count() === 0) {
$queryTermConditions->add('1 = 2');
}
/** End add this */
if (SearchMode::ALL_TERMS === $searchDto->getSearchMode()) {
$queryBuilder->andWhere($queryTermConditions);
} else {
$queryBuilder->orWhere($queryTermConditions);
} |
So be it. Please review :) |
Oh, no... I think someone already fixed this, but no one saw his PR I should close this. |
Right, but you code still need to be reverted |
See #6242
A recent change (which I shamefully commited) broke search for the PostgreSQL platform. This PR should fix the issue.