You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ Hey! We've built a Docker-based deployment tool to launch apps and sites fully c
23
23
* Search through one or more [Eloquent models](https://laravel.com/docs/master/eloquent).
24
24
* Support for cross-model [pagination](https://laravel.com/docs/master/pagination#introduction).
25
25
* Search through single or multiple columns.
26
+
* Order by (cross-model) columns or by relevance.
26
27
* Use [constraints](https://laravel.com/docs/master/eloquent#retrieving-models) and [scoped queries](https://laravel.com/docs/master/eloquent#query-scopes).
27
28
*[Eager load relationships](https://laravel.com/docs/master/eloquent-relationships#eager-loading) for each model.
28
29
* In-database [sorting](https://laravel.com/docs/master/queries#ordering-grouping-limit-and-offset) of the combined result.
If you want to sort the results by another column, you can pass that column to the `add` method as a third parameter. Call the `orderByDesc` method to sort the results in descending order.
142
143
143
144
```php
144
-
Search::add(Post::class, 'title', 'publihed_at')
145
+
Search::add(Post::class, 'title', 'published_at')
145
146
->add(Video::class, 'title', 'released_at')
146
147
->orderByDesc()
147
148
->get('learn');
148
149
```
149
150
151
+
You can call the `orderByRelevance` method to sort the results by the number of occurrences of the search terms. Imagine these two sentences:
152
+
153
+
* Apple introduces iPhone 13 and iPhone 13 mini
154
+
* Apple unveils new iPad mini with breakthrough performance in stunning new design
155
+
156
+
If you search for *Apple iPad*, the second sentence will come up first, as there are more matches of the search terms.
157
+
158
+
```php
159
+
Search::add(Post::class, 'title')
160
+
->beginWithWildcard()
161
+
->orderByRelevance()
162
+
->get('Apple iPad');
163
+
```
164
+
150
165
### Pagination
151
166
152
167
We highly recommend paginating your results. Call the `paginate` method before the `get` method, and you'll get an instance of `\Illuminate\Contracts\Pagination\LengthAwarePaginator` as a result. The `paginate` method takes three (optional) parameters to customize the paginator. These arguments are [the same](https://laravel.com/docs/master/pagination#introduction) as Laravel's database paginator.
0 commit comments