Skip to content
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

[Autocomplete] Fix Incompatibility filter_query and max_results (doc) #2440

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Autocomplete/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ to the options above, you can also pass:

``filter_query`` (default: ``null``)
If you want to completely control the query made for the "search results",
use this option. This is incompatible with ``searchable_fields``::
use this option. This is incompatible with ``searchable_fields`` and ``max_results``::
Copy link
Member

Choose a reason for hiding this comment

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

Nice catch here!

Would you also update the BaseAutocompleteType code to make the same check than filter/searcheable_fields ?

$resolver->setAllowedTypes('filter_query', ['callable', 'null']);
$resolver->setNormalizer('searchable_fields', function (Options $options, ?array $searchableFields) {
if (null !== $searchableFields && null !== $options['filter_query']) {
throw new RuntimeException('Both the searchable_fields and filter_query options cannot be set.');
}
return $searchableFields;
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be a problem because max_results has default to 10.

Copy link
Member

Choose a reason for hiding this comment

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

Well let's forget then :) Thanks for the fix!


[
'filter_query' => function(QueryBuilder $qb, string $query, EntityRepository $repository) {
Expand Down
Loading