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

Fix relevance sort #2773

Merged
merged 6 commits into from
Apr 12, 2021
Merged

Fix relevance sort #2773

merged 6 commits into from
Apr 12, 2021

Conversation

askvortsov1
Copy link
Sponsor Member

Fixes #2772

Changes proposed in this pull request:

  • Adds a field to QueryCriteria that determines whether the sort provided is the controller's default sort
  • Set this field to true iff sort not in query params. Default it to false
  • Override $sort if a new default sort has been set on search state, and the param is true.
  • Add tests!

Confirmed

  • Frontend changes: tested on a local Flarum installation.
  • Backend changes: tests are green (run composer test).

src/Api/Controller/AbstractSerializeController.php Outdated Show resolved Hide resolved
src/Api/Controller/ListPostsController.php Outdated Show resolved Hide resolved
@@ -85,12 +85,13 @@ protected function data(ServerRequestInterface $request, Document $document)

$filters = $this->extractFilter($request);
$sort = $this->extractSort($request);
$sortIsDefault = $this->sortIsDefault($request);
Copy link
Member

Choose a reason for hiding this comment

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

can we rename sortIsDefault to isDefaultSorting or maybe isSortingByDefault.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Mixed feelings about this one. Any use of sorting describes whether or not any sort is being applied. But this variable should describe whether the sort currently being used (whatever that is, could be no sort at all) is the controller's default sort.

Alternatively, we could use userRequestedSort or userSpecifiedSort and invert everything, but that sounds very verbose.

Copy link
Member

Choose a reason for hiding this comment

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

True, we only want to know if we're falling back to the default sort.

Though I was more looking for just a isSomething naming, since that's the usual convention for boolean variables/methods where possible. But isDefaultSort might be weird.

Let's keep it as is then!

@askvortsov1 askvortsov1 requested a review from SychO9 April 11, 2021 17:31
@askvortsov1 askvortsov1 merged commit b6f0b01 into master Apr 12, 2021
@askvortsov1 askvortsov1 deleted the as/fix-relevance-sort branch April 12, 2021 02:21
askvortsov1 added a commit to flarum/sticky that referenced this pull request Apr 12, 2021
This was introduced in flarum/framework#2773, and allows us to more cleanly determine whether the sort requested is the default one, while taking extension modifications into account.
askvortsov1 added a commit to flarum/sticky that referenced this pull request Mar 11, 2022
This was introduced in flarum/framework#2773, and allows us to more cleanly determine whether the sort requested is the default one, while taking extension modifications into account.
askvortsov1 added a commit to flarum/sticky that referenced this pull request May 10, 2022
This was introduced in flarum/framework#2773, and allows us to more cleanly determine whether the sort requested is the default one, while taking extension modifications into account.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discussion relevance ordering is broken
3 participants