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

Sorting feature is missing in MeiliSearch Engine #572

Closed
bedus-creation opened this issue Jan 13, 2022 · 6 comments · Fixed by #587
Closed

Sorting feature is missing in MeiliSearch Engine #572

bedus-creation opened this issue Jan 13, 2022 · 6 comments · Fixed by #587

Comments

@bedus-creation
Copy link

  • Scout Version: 9.3.4
  • Scout Driver: MeiliSearch
  • Laravel Version: 8.61
  • PHP Version: 8.0.14
  • Database Driver & Version: Mysql 8

Description:

MeiliSearch supports sorting feature out of the box after defining sortable parameters while indexing. The given orderBy method is supposed to work for sorting. Consider the following code.

return User::search('Admin')
        ->orderBy("id", "desc")
        ->get();

The above code should generate a query like in https://github.com/laravel/scout/blob/9.x/src/Engines/MeiliSearchEngine.php#L114

public function paginate(Builder $builder, $perPage, $page) 
 { 
     return $this->performSearch($builder, array_filter([ 
         'filters' => $this->filters($builder), 
         'limit' => (int) $perPage, 
         'sort'=> ['id:desc'],
         'offset' => ($page - 1) * $perPage, 
     ])); 
 } 

But the sort options is missing while performing the search.

public function paginate(Builder $builder, $perPage, $page)
{
return $this->performSearch($builder, array_filter([
'filters' => $this->filters($builder),
'limit' => (int) $perPage,
'offset' => ($page - 1) * $perPage,
]));
}

public function search(Builder $builder)
{
return $this->performSearch($builder, array_filter([
'filters' => $this->filters($builder),
'limit' => $builder->limit,
]));
}

@driesvints driesvints changed the title Sorting feature is missing in MeiliSearch Engine. Sorting feature is missing in MeiliSearch Engine Jan 13, 2022
@driesvints
Copy link
Member

This sounds like a feature request. We'd be happy to receive PR's.

/cc @mmachatschek

@mmachatschek
Copy link
Contributor

mmachatschek commented Jan 14, 2022

Hi @bedus-creation,

this feature is plausable but was already tried to be implemented here #537 (See discussion)

Maybe this is useful to the DatabaseEngine too and all engines could benefit from a generic solution. @driesvints

@driesvints
Copy link
Member

@taylorotwell can we maybe revisit the PR from above that @mmachatschek linked to?

@driesvints
Copy link
Member

The related pr was merged

@bedus-creation
Copy link
Author

I think sort option is still missing in paginate function #537

@driesvints
Copy link
Member

@bedus-creation please send in a PR

mrABR pushed a commit to mrABR/scout that referenced this issue Feb 15, 2022
mrABR added a commit to mrABR/scout that referenced this issue Feb 15, 2022
taylorotwell pushed a commit that referenced this issue Feb 15, 2022
* Implements Meilisearch sort on paginate

Fixes #572

* Fix test style ci

* Fix formatting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants