Skip to content

Commit fa7b782

Browse files
committed
Merge branch '10.x' into 11.x
# Conflicts: # CHANGELOG.md # src/Scout.php
2 parents e1d4d69 + 2d3131a commit fa7b782

File tree

13 files changed

+120
-25
lines changed

13 files changed

+120
-25
lines changed

.github/ISSUE_TEMPLATE/2_Feature_request.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
blank_issues_enabled: false
22
contact_links:
3+
- name: Feature request
4+
url: https://github.com/laravel/scout/pulls
5+
about: 'For ideas or feature requests, send in a pull request'
36
- name: Support Questions & Other
47
url: https://laravel.com/docs/contributions#support-questions
58
about: 'This repository is only for reporting bugs. If you have a question or need help using the library, click:'

.github/SECURITY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ If you discover a security vulnerability within Laravel, please send an email to
1515
```
1616
-----BEGIN PGP PUBLIC KEY BLOCK-----
1717
Version: OpenPGP v2.0.8
18-
Comment: https://sela.io/pgp/
18+
Comment: Report Security Vulnerabilities to taylor@laravel.com
1919
2020
xsFNBFugFSQBEACxEKhIY9IoJzcouVTIYKJfWFGvwFgbRjQWBiH3QdHId5vCrbWo
2121
s2l+4Rv03gMG+yHLJ3rWElnNdRaNdQv59+lShrZF7Bvu7Zvc0mMNmFOM/mQ/K2Lt

.github/workflows/static-analysis.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,34 @@ on:
77
- '*.x'
88
pull_request:
99

10-
permissions:
11-
contents: read
12-
1310
jobs:
14-
tests:
15-
uses: laravel/.github/.github/workflows/static-analysis.yml@main
11+
types:
12+
runs-on: ubuntu-24.04
13+
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
directory: [src, types]
18+
19+
name: ${{ matrix.directory == 'src' && 'Source Code' || 'Types' }}
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Setup PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: 8.2
29+
tools: composer:v2
30+
coverage: none
31+
32+
- name: Install dependencies
33+
uses: nick-fields/retry@v3
34+
with:
35+
timeout_minutes: 5
36+
max_attempts: 5
37+
command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress
38+
39+
- name: Execute type checking
40+
run: vendor/bin/phpstan --configuration="phpstan.${{ matrix.directory }}.neon.dist"

CHANGELOG.md

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

3-
## [Unreleased](https://github.com/laravel/scout/compare/v10.9.0...11.x)
3+
## [Unreleased](https://github.com/laravel/scout/compare/v10.11.2...11.x)
4+
5+
## [v10.11.2](https://github.com/laravel/scout/compare/v10.11.1...v10.11.2) - 2024-09-03
6+
7+
* [10.x] Add Generic Docblocks To Builder by [@Magnesium38](https://github.com/Magnesium38) in https://github.com/laravel/scout/pull/857
8+
9+
## [v10.11.1](https://github.com/laravel/scout/compare/v10.11.0...v10.11.1) - 2024-08-06
10+
11+
* refactor(typesense): remove unused exists checks by [@saibotk](https://github.com/saibotk) in https://github.com/laravel/scout/pull/847
12+
13+
## [v10.11.0](https://github.com/laravel/scout/compare/v10.10.2...v10.11.0) - 2024-07-30
14+
15+
* [10.x] Allow setting custom scout builder class by [@gdebrauwer](https://github.com/gdebrauwer) in https://github.com/laravel/scout/pull/852
16+
17+
## [v10.10.2](https://github.com/laravel/scout/compare/v10.10.1...v10.10.2) - 2024-07-23
18+
19+
* [Typesense] Sync server state in getOrCreateCollectionFromModel #845 by [@tharropoulos](https://github.com/tharropoulos) in https://github.com/laravel/scout/pull/846
20+
21+
## [v10.10.1](https://github.com/laravel/scout/compare/v10.10.0...v10.10.1) - 2024-07-02
22+
23+
* [10.x] Get the key name through getScoutKeyName() on the Database engine by [@antonioribeiro](https://github.com/antonioribeiro) in https://github.com/laravel/scout/pull/843
24+
25+
## [v10.10.0](https://github.com/laravel/scout/compare/v10.9.0...v10.10.0) - 2024-06-18
26+
27+
* Added possibility to version indexes. by [@Boorinio](https://github.com/Boorinio) in https://github.com/laravel/scout/pull/836
428

529
## [v10.9.0](https://github.com/laravel/scout/compare/v10.8.6...v10.9.0) - 2024-05-07
630

File renamed without changes.

phpstan.types.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
level: max
3+
paths:
4+
- types

src/Builder.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
use Laravel\Scout\Contracts\PaginatesEloquentModels;
1212
use Laravel\Scout\Contracts\PaginatesEloquentModelsUsingDatabase;
1313

14+
/**
15+
* @template TModel of \Illuminate\Database\Eloquent\Model
16+
*/
1417
class Builder
1518
{
1619
use Conditionable, Macroable, Tappable;
1720

1821
/**
1922
* The model instance.
2023
*
21-
* @var \Illuminate\Database\Eloquent\Model
24+
* @var TModel
2225
*/
2326
public $model;
2427

@@ -95,7 +98,7 @@ class Builder
9598
/**
9699
* Create a new search builder instance.
97100
*
98-
* @param \Illuminate\Database\Eloquent\Model $model
101+
* @param TModel $model
99102
* @param string $query
100103
* @param \Closure|null $callback
101104
* @param bool $softDelete
@@ -300,7 +303,7 @@ public function keys()
300303
/**
301304
* Get the first result from the search.
302305
*
303-
* @return \Illuminate\Database\Eloquent\Model
306+
* @return TModel
304307
*/
305308
public function first()
306309
{
@@ -310,7 +313,7 @@ public function first()
310313
/**
311314
* Get the results of the search.
312315
*
313-
* @return \Illuminate\Database\Eloquent\Collection
316+
* @return \Illuminate\Database\Eloquent\Collection<int, TModel>
314317
*/
315318
public function get()
316319
{
@@ -320,7 +323,7 @@ public function get()
320323
/**
321324
* Get the results of the search as a "lazy collection" instance.
322325
*
323-
* @return \Illuminate\Support\LazyCollection
326+
* @return \Illuminate\Support\LazyCollection<int, TModel>
324327
*/
325328
public function cursor()
326329
{

src/Engines/DatabaseEngine.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function paginateUsingDatabase(Builder $builder, $perPage, $pageName, $pa
9292
}
9393
})
9494
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
95-
$query->orderBy($builder->model->getKeyName(), 'desc');
95+
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
9696
})
9797
->paginate($perPage, ['*'], $pageName, $page);
9898
}
@@ -127,7 +127,7 @@ public function simplePaginateUsingDatabase(Builder $builder, $perPage, $pageNam
127127
}
128128
})
129129
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
130-
$query->orderBy($builder->model->getKeyName(), 'desc');
130+
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
131131
})
132132
->simplePaginate($perPage, ['*'], $pageName, $page);
133133
}
@@ -152,7 +152,7 @@ protected function searchModels(Builder $builder, $page = null, $perPage = null)
152152
}
153153
})
154154
->when(! $this->getFullTextColumns($builder), function ($query) use ($builder) {
155-
$query->orderBy($builder->model->getKeyName(), 'desc');
155+
$query->orderBy($builder->model->getScoutKeyName(), 'desc');
156156
})
157157
->get();
158158
}
@@ -198,7 +198,7 @@ protected function initializeSearchQuery(Builder $builder, array $columns, array
198198
$canSearchPrimaryKey = ctype_digit($builder->query) &&
199199
in_array($builder->model->getKeyType(), ['int', 'integer']) &&
200200
($connectionType != 'pgsql' || $builder->query <= PHP_INT_MAX) &&
201-
in_array($builder->model->getKeyName(), $columns);
201+
in_array($builder->model->getScoutKeyName(), $columns);
202202

203203
if ($canSearchPrimaryKey) {
204204
$query->orWhere($builder->model->getQualifiedKeyName(), $builder->query);
@@ -214,7 +214,7 @@ protected function initializeSearchQuery(Builder $builder, array $columns, array
214214
$this->getFullTextOptions($builder)
215215
);
216216
} else {
217-
if ($canSearchPrimaryKey && $column === $builder->model->getKeyName()) {
217+
if ($canSearchPrimaryKey && $column === $builder->model->getScoutKeyName()) {
218218
continue;
219219
}
220220

src/Engines/TypesenseEngine.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,19 @@ protected function getOrCreateCollectionFromModel($model, bool $indexOperation =
498498
{
499499
$method = $indexOperation ? 'indexableAs' : 'searchableAs';
500500

501-
$collection = $this->typesense->getCollections()->{$model->{$method}()};
501+
$collectionName = $model->{$method}();
502+
$collection = $this->typesense->getCollections()->{$collectionName};
503+
504+
// Determine if the collection exists in Typesense...
505+
try {
506+
$collection->retrieve();
507+
508+
// No error means this collection exists on the server...
509+
$collection->setExists(true);
502510

503-
if ($collection->exists() === true) {
504511
return $collection;
512+
} catch (TypesenseClientError $e) {
513+
//
505514
}
506515

507516
$schema = config('scout.typesense.model-settings.'.get_class($model).'.collection-schema') ?? [];

src/Searchable.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ public function searchIndexShouldBeUpdated()
114114
*
115115
* @param string $query
116116
* @param \Closure $callback
117-
* @return \Laravel\Scout\Builder
117+
* @return \Laravel\Scout\Builder<static>
118118
*/
119119
public static function search($query = '', $callback = null)
120120
{
121-
return app(Builder::class, [
121+
return app(static::$scoutBuilder ?? Builder::class, [
122122
'model' => new static,
123123
'query' => $query,
124124
'callback' => $callback,

types/Builder.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Laravel\Scout\Builder;
5+
6+
use function PHPStan\Testing\assertType;
7+
8+
/** @param \Laravel\Scout\Builder<User> $builder */
9+
function test(
10+
Builder $builder,
11+
): void {
12+
assertType('Illuminate\Database\Eloquent\Collection<int, User>', $builder->get());
13+
assertType('User', $builder->first());
14+
}
15+
16+
class User extends Model
17+
{
18+
}

types/Searchable.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Laravel\Scout\Searchable;
5+
6+
use function PHPStan\Testing\assertType;
7+
8+
assertType('Laravel\Scout\Builder<Post>', Post::search());
9+
10+
class Post extends Model
11+
{
12+
use Searchable;
13+
}

0 commit comments

Comments
 (0)