Skip to content

[Autocomplete] implement max_results option #478

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

Merged
merged 1 commit into from
Sep 27, 2022

Conversation

DarrHeLL
Copy link
Contributor

@DarrHeLL DarrHeLL commented Sep 23, 2022

Q A
Bug fix? no
New feature? yes
Tickets N/A
License MIT

Added max_results option in formType options to control the results number returned by a query on automatic endpoint.

@DarrHeLL DarrHeLL changed the title Autocomplete maxresult feat(Autocomplete): implement max_results option Sep 23, 2022
@DarrHeLL DarrHeLL changed the title feat(Autocomplete): implement max_results option [Autocomplete] implement max_results option Sep 23, 2022
@DarrHeLL DarrHeLL marked this pull request as ready for review September 23, 2022 10:41
Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

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

Thanks for this! We could use a test - I'm thinking that FieldAutocompleterTest would be a good spot. We could add a new test method that creates, for example, 10 categories. Then in CategoryAutocompleteType we can pass max_results => 5. Then in the test, we do some search and assert that we only see 5 results, not the full 10.

// if no max is set, set one
if (!$queryBuilder->getMaxResults()) {
$queryBuilder->setMaxResults(10);
}
Copy link
Member

Choose a reason for hiding this comment

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

This should probably stay - for the (edge) case when someone is using this class but have their own custom EntityAutocompleterInterface implementation (one whose createFilteredQueryBuilder may not have the max results set).

This will make it so that setting to null does NOT avoid limiting results. But, I think that's ok - I'm not sure you should ever return ALL results - that's a recipe for hydrating too many entities.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in f46e34d


``max_results`` (default: 10)
Allow you to control the reults number returned by a query on automatic endpoint.
Set it to ``null`` if you don't want to limit results.
Copy link
Member

Choose a reason for hiding this comment

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

blank line after this line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 40c7632

@@ -258,7 +258,9 @@ to the options above, you can also pass:
$qb->andWhere('entity.name LIKE :filter OR entity.description LIKE :filter')
->setParameter('filter', '%'.$query.'%');
}

``max_results`` (default: 10)
Allow you to control the reults number returned by a query on automatic endpoint.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Allow you to control the reults number returned by a query on automatic endpoint.
Allow you to control the max number of results returned by the automatic autocomplete endpoint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 40c7632

@weaverryan weaverryan added Status: Needs Work Additional work is needed Feature New Feature labels Sep 23, 2022
@DarrHeLL
Copy link
Contributor Author

OK I will correct your suggestions and I tel you when it's done

@DarrHeLL
Copy link
Contributor Author

Unit test added in commit f34e8b0

@DarrHeLL
Copy link
Contributor Author

Outch don't know why CS is crying

@weaverryan weaverryan force-pushed the autocomplete_maxresult branch from 40c7632 to 289463d Compare September 27, 2022 13:36
@weaverryan
Copy link
Member

This is fantastic work! Thank you @DarrHeLL! I'll check out the CI - it's just a code styling issue, and it doesn't look like the CI outputs in a very helpful way.

@weaverryan weaverryan merged commit b2e03eb into symfony:2.x Sep 27, 2022
weaverryan added a commit that referenced this pull request Nov 9, 2022
…tity (daFish)

This PR was merged into the 2.x branch.

Discussion
----------

[Autocomplete] max_results option is not passed to parent entity

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Tickets       | none <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

There seems to be an oversight from #478 when it comes to passing the option from types that use `#[AsEntityAutocompleteField]`.

This fix removes the unsetting of `$options['max_results']` from the `AutocompleteEntityTypeSubscriber` to allow passing the information. I also extended the tests to cover this case.

Commits
-------

43e74fe fix(autocomplete): max_results option is not passed to parent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Work Additional work is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants