Skip to content

Sorting feature is missing in MeiliSearch Engine #572

Closed
@bedus-creation

Description

@bedus-creation
  • 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,
]));
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions