Skip to content

Commit 48d9fbe

Browse files
committed
Merge branch '10.x'
# Conflicts: # CHANGELOG.md # src/EngineManager.php
2 parents cf93b3f + ee11fd3 commit 48d9fbe

17 files changed

+284
-48
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,24 @@ on:
1111

1212
jobs:
1313
tests:
14-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-22.04
1515

1616
strategy:
1717
fail-fast: true
1818
matrix:
19-
php: [7.3, 7.4, '8.0', 8.1, 8.2]
20-
laravel: [8, 9]
19+
php: ['8.0', 8.1, 8.2]
20+
laravel: [9, 10]
2121
exclude:
22-
- php: 7.3
22+
- php: '8.0'
2323
laravel: 9
24-
- php: 7.4
25-
laravel: 9
26-
- php: 8.2
27-
laravel: 8
24+
- php: '8.0'
25+
laravel: 10
2826

2927
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
3028

3129
steps:
3230
- name: Checkout code
33-
uses: actions/checkout@v2
31+
uses: actions/checkout@v3
3432

3533
- name: Setup PHP
3634
uses: shivammathur/setup-php@v2

CHANGELOG.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,52 @@
11
# Release Notes
22

3-
## [Unreleased](https://github.com/laravel/scout/compare/v9.5.1...master)
3+
## [Unreleased](https://github.com/laravel/scout/compare/v9.8.0...master)
4+
5+
## [v9.8.0](https://github.com/laravel/scout/compare/v9.7.2...v9.8.0) - 2023-01-17
6+
7+
### Added
8+
9+
- Laravel v10 Support by @driesvints in https://github.com/laravel/scout/pull/696
10+
- Enable order by for `collection` & `database` engines by @stein-j in https://github.com/laravel/scout/pull/695
11+
12+
## [v9.7.2](https://github.com/laravel/scout/compare/v9.7.1...v9.7.2) - 2023-01-09
13+
14+
### Fixed
15+
16+
- Handle non-consecutive key collection on MeiliSearch document deletion by @pyrou in https://github.com/laravel/scout/pull/688
17+
- Fix missing variable in closure by @driesvints in https://github.com/laravel/scout/pull/694
18+
19+
## [v9.7.1](https://github.com/laravel/scout/compare/v9.7.0...v9.7.1) - 2023-01-06
20+
21+
### Fixed
22+
23+
- Make scout compatible with new meilisearch casing by @mmachatschek in https://github.com/laravel/scout/pull/687
24+
25+
## [v9.7.0](https://github.com/laravel/scout/compare/v9.6.2...v9.7.0) - 2023-01-03
26+
27+
### Changed
28+
29+
- Add analytics for Meilisearch engine by @mmachatschek in https://github.com/laravel/scout/pull/681
30+
- Allow options for search requests by @driesvints in https://github.com/laravel/scout/pull/683
31+
32+
## [v9.6.2](https://github.com/laravel/scout/compare/v9.6.1...v9.6.2) - 2022-12-21
33+
34+
### Fixed
35+
36+
- Added a missing import by @driesvints in https://github.com/laravel/scout/commit/56adabcc1575a692824ffa8009719b20e7778f28
37+
38+
## [v9.6.1](https://github.com/laravel/scout/compare/v9.6.0...v9.6.1) - 2022-12-20
39+
40+
### Changed
41+
42+
- Allow FQCN to delete-index command by @kichetof in https://github.com/laravel/scout/pull/677
43+
44+
## [v9.6.0](https://github.com/laravel/scout/compare/v9.5.1...v9.6.0) - 2022-12-15
45+
46+
### Added
47+
48+
- Add command delete-all-indexes, update scout:index to allow FQCN and apply filterable on SoftDeletes by @kichetof in https://github.com/laravel/scout/pull/671
49+
- Added soft deleted to Meilisearch by @kichetof in https://github.com/laravel/scout/pull/672
450

551
## [v9.5.1](https://github.com/laravel/scout/compare/v9.5.0...v9.5.1) - 2022-12-08
652

RELEASE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Release Instructions
22

3-
1. Update the version in [`EngineManager.php`](./src/EngineManager.php) and commit it
3+
1. Update the version in [`Scout.php`](./src/Scout.php) and commit it
44
2. Create a new GitHub release for this version with the release notes

UPGRADE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,34 @@
11
# Upgrade Guide
22

3+
## Upgrading To 10.0 From 9.x
4+
5+
### Minimum Versions
6+
7+
The following dependency versions have been updated:
8+
9+
- The minimum PHP version is now v8.0
10+
- The minimum Laravel version is now v9.0
11+
12+
### The `getScoutKeyName` Method
13+
14+
PR: https://github.com/laravel/scout/pull/509
15+
16+
In Scout 10.x, the `getScoutKeyName` method will return the unqualified key name and no longer qualifies the key name with the table name. If you are overriding the `getScoutKeyName` method you will need to account for this change and make sure you return an unqualified key name.
17+
18+
```diff
19+
public function getScoutKeyName()
20+
{
21+
- return 'posts.id';
22+
+ return 'id';
23+
}
24+
```
25+
26+
### Removal Of `getUnqualifiedScoutKeyName`
27+
28+
PR: https://github.com/laravel/scout/pull/657
29+
30+
Due to the `getScoutKeyName` change discussed above, the `getUnqualifiedScoutKeyName` method was removed as it is no longer necessary.
31+
332
## Upgrading To 9.0 From 8.x
433

534
### Minimum Laravel Version

composer.json

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,20 @@
1414
}
1515
],
1616
"require": {
17-
"php": "^7.3|^8.0",
18-
"illuminate/bus": "^8.0|^9.0",
19-
"illuminate/contracts": "^8.0|^9.0",
20-
"illuminate/database": "^8.0|^9.0",
21-
"illuminate/http": "^8.0|^9.0",
22-
"illuminate/pagination": "^8.0|^9.0",
23-
"illuminate/queue": "^8.0|^9.0",
24-
"illuminate/support": "^8.0|^9.0"
17+
"php": "^8.0",
18+
"illuminate/bus": "^9.0|^10.0",
19+
"illuminate/contracts": "^9.0|^10.0",
20+
"illuminate/database": "^9.0|^10.0",
21+
"illuminate/http": "^9.0|^10.0",
22+
"illuminate/pagination": "^9.0|^10.0",
23+
"illuminate/queue": "^9.0|^10.0",
24+
"illuminate/support": "^9.0|^10.0"
2525
},
2626
"require-dev": {
27-
"meilisearch/meilisearch-php": "^0.19",
27+
"meilisearch/meilisearch-php": "^0.23",
2828
"mockery/mockery": "^1.0",
29-
"orchestra/testbench": "^6.17|^7.0",
29+
"php-http/guzzle7-adapter": "^1.0",
30+
"orchestra/testbench": "^7.0|^8.0",
3031
"phpunit/phpunit": "^9.3"
3132
},
3233
"autoload": {
@@ -54,7 +55,10 @@
5455
"meilisearch/meilisearch-php": "Required to use the MeiliSearch engine (^0.23)."
5556
},
5657
"config": {
57-
"sort-packages": true
58+
"sort-packages": true,
59+
"allow-plugins": {
60+
"php-http/discovery": true
61+
}
5862
},
5963
"minimum-stability": "dev",
6064
"prefer-stable": true

src/Builder.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ class Builder
7575
*/
7676
public $orders = [];
7777

78+
/**
79+
* Extra options that should be applied to the search.
80+
*
81+
* @var int
82+
*/
83+
public $options = [];
84+
7885
/**
7986
* Create a new search builder instance.
8087
*
@@ -190,6 +197,19 @@ public function orderBy($column, $direction = 'asc')
190197
return $this;
191198
}
192199

200+
/**
201+
* Set extra options for the search query.
202+
*
203+
* @param array $options
204+
* @return $this
205+
*/
206+
public function options(array $options)
207+
{
208+
$this->options = $options;
209+
210+
return $this;
211+
}
212+
193213
/**
194214
* Apply the callback's query changes if the given "value" is true.
195215
*

src/Console/DeleteIndexCommand.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Console\Command;
7+
use Illuminate\Support\Str;
78
use Laravel\Scout\EngineManager;
89

910
class DeleteIndexCommand extends Command
@@ -31,11 +32,28 @@ class DeleteIndexCommand extends Command
3132
public function handle(EngineManager $manager)
3233
{
3334
try {
34-
$manager->engine()->deleteIndex($this->argument('name'));
35+
$manager->engine()->deleteIndex($name = $this->indexName($this->argument('name')));
3536

36-
$this->info('Index "'.$this->argument('name').'" deleted.');
37+
$this->info('Index "'.$name.'" deleted.');
3738
} catch (Exception $exception) {
3839
$this->error($exception->getMessage());
3940
}
4041
}
42+
43+
/**
44+
* Get the fully-qualified index name for the given index.
45+
*
46+
* @param string $name
47+
* @return string
48+
*/
49+
protected function indexName($name)
50+
{
51+
if (class_exists($name)) {
52+
return (new $name)->searchableAs();
53+
}
54+
55+
$prefix = config('scout.prefix');
56+
57+
return ! Str::startsWith($name, $prefix) ? $prefix.$name : $name;
58+
}
4159
}

src/EngineManager.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function createAlgoliaDriver()
3636
{
3737
$this->ensureAlgoliaClientIsInstalled();
3838

39-
UserAgent::addCustomUserAgent('Laravel Scout', '11.0.0-dev');
39+
UserAgent::addCustomUserAgent('Laravel Scout', Scout::VERSION);
4040

4141
$config = SearchConfig::create(
4242
config('scout.algolia.id'),
@@ -116,7 +116,11 @@ public function createMeilisearchDriver()
116116
$this->ensureMeiliSearchClientIsInstalled();
117117

118118
return new MeiliSearchEngine(
119-
$this->container->make(MeiliSearch::class),
119+
$this->container->make(
120+
class_exists(MeiliSearch::class)
121+
? MeiliSearch::class
122+
: \Meilisearch\Client::class
123+
),
120124
config('scout.soft_delete', false)
121125
);
122126
}
@@ -130,7 +134,7 @@ public function createMeilisearchDriver()
130134
*/
131135
protected function ensureMeiliSearchClientIsInstalled()
132136
{
133-
if (class_exists(MeiliSearch::class)) {
137+
if (class_exists(MeiliSearch::class) || class_exists(\Meilisearch\Client::class)) {
134138
return;
135139
}
136140

src/Engines/AlgoliaEngine.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ protected function performSearch(Builder $builder, array $options = [])
140140
$builder->index ?: $builder->model->searchableAs()
141141
);
142142

143+
$options = array_merge($builder->options, $options);
144+
143145
if ($builder->callback) {
144146
return call_user_func(
145147
$builder->callback,

src/Engines/CollectionEngine.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,13 @@ protected function searchModels(Builder $builder)
100100
$query->whereIn($key, $values);
101101
}
102102
})
103-
->orderBy(
104-
$builder->model->qualifyColumn($builder->model->getScoutKeyName()), 'desc'
105-
);
103+
->when($builder->orders, function ($query) use ($builder) {
104+
foreach ($builder->orders as $order) {
105+
$query->orderBy($order['column'], $order['direction']);
106+
}
107+
}, function ($query) use ($builder) {
108+
$query->orderBy($builder->model->qualifyColumn($builder->model->getScoutKeyName()), 'desc');
109+
});
106110

107111
$models = $this->ensureSoftDeletesAreHandled($builder, $query)
108112
->get()

src/Engines/DatabaseEngine.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public function search(Builder $builder)
7272
public function paginate(Builder $builder, $perPage, $page)
7373
{
7474
return $this->buildSearchQuery($builder)
75+
->when($builder->orders, function ($query) use ($builder) {
76+
foreach ($builder->orders as $order) {
77+
$query->orderBy($order['column'], $order['direction']);
78+
}
79+
})
7580
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
7681
$query->orderBy($builder->model->getKeyName(), 'desc');
7782
})
@@ -89,6 +94,11 @@ public function paginate(Builder $builder, $perPage, $page)
8994
public function simplePaginate(Builder $builder, $perPage, $page)
9095
{
9196
return $this->buildSearchQuery($builder)
97+
->when($builder->orders, function ($query) use ($builder) {
98+
foreach ($builder->orders as $order) {
99+
$query->orderBy($order['column'], $order['direction']);
100+
}
101+
})
92102
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
93103
$query->orderBy($builder->model->getKeyName(), 'desc');
94104
})
@@ -109,6 +119,11 @@ protected function searchModels(Builder $builder, $page = null, $perPage = null)
109119
->when(! is_null($page) && ! is_null($perPage), function ($query) use ($page, $perPage) {
110120
$query->forPage($page, $perPage);
111121
})
122+
->when($builder->orders, function ($query) use ($builder) {
123+
foreach ($builder->orders as $order) {
124+
$query->orderBy($order['column'], $order['direction']);
125+
}
126+
})
112127
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
113128
$query->orderBy($builder->model->getKeyName(), 'desc');
114129
})
@@ -125,7 +140,7 @@ protected function buildSearchQuery(Builder $builder)
125140
{
126141
$query = $this->initializeSearchQuery(
127142
$builder,
128-
$columns = array_keys($builder->model->toSearchableArray()),
143+
array_keys($builder->model->toSearchableArray()),
129144
$this->getPrefixColumns($builder),
130145
$this->getFullTextColumns($builder)
131146
);
@@ -216,8 +231,8 @@ protected function addAdditionalConstraints(Builder $builder, $query)
216231
* Ensure that soft delete constraints are properly applied to the query.
217232
*
218233
* @param \Laravel\Scout\Builder $builder
219-
* @param \Illuminate\Database\Query\Builder $query
220-
* @return \Illuminate\Database\Query\Builder
234+
* @param \Illuminate\Database\Eloquent\Builder $query
235+
* @return \Illuminate\Database\Eloquent\Builder
221236
*/
222237
protected function constrainForSoftDeletes($builder, $query)
223238
{

0 commit comments

Comments
 (0)