Skip to content

Commit

Permalink
Merge pull request #93 from burakcakirel/update-laravel-scout
Browse files Browse the repository at this point in the history
Update Laravel Scout and its dependencies
  • Loading branch information
matchish authored Mar 15, 2020
2 parents 31482f5 + 78e5e3c commit c00cd2b
Show file tree
Hide file tree
Showing 20 changed files with 69 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ filter:
build:
environment:
php:
version: '7.2'
version: '7.3'
variables:
ELASTICSEARCH_HOST: 'localhost:9200'
DB_HOST: '127.0.0.1'
Expand Down
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ env:
- ELASTICSEARCH_BUILD=7.1.1-amd64.deb ELASTICSEARCH_HOST=localhost:9200 DB_DATABASE=scout_database DB_USERNAME=travis DB_PASSWORD=""

php:
- 7.1
- 7.2
- 7.3
- nightly
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/)

## [Unreleased]

## [4.0.0] - 2020-03-12
### Added
- Scout 8 Support

## [3.0.3] - 2020-03-14
### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Don't forget to :star: the package if you like it. :pray:

## :warning: Requirements

- PHP version >= 7.1.3
- Laravel Framework version >= 5.6
- PHP version >= 7.2.0
- Laravel Framework version >= 6.0.0

| Elasticsearch version | ElasticsearchDSL version |
| --------------------- | --------------------------- |
Expand Down
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "matchish/laravel-scout-elasticsearch",
"description": "Search among multiple models with ElasticSearch and Laravel Scout",
"version": "3.0.3",
"version": "4.0.0",
"keywords": [
"laravel",
"scout",
Expand All @@ -17,19 +17,17 @@
}
],
"require": {
"php": "^7.1.3",
"php": "^7.2",
"elasticsearch/elasticsearch": ">=7.2",
"laravel/scout": "^6.1.1|^7.0",
"laravel/scout": "^8.0",
"ongr/elasticsearch-dsl": "^7.0"
},
"require-dev": {
"fzaninotto/faker": "^1.8",
"phpstan/phpstan": "0.11.6",
"orchestra/testbench": "3.8.5",
"phpunit/phpunit": "7.5.18",
"laravel/framework": "5.8.35",
"nunomaduro/larastan": "0.3.16",
"nette/bootstrap": "^2.4.6"
"orchestra/testbench": "^4.0|^5.0",
"phpunit/phpunit": "^8.0|^9.0",
"illuminate/support": "^6.0|^7.0",
"nunomaduro/larastan": "~0.5"
},
"autoload-dev": {
"psr-4": {
Expand Down
3 changes: 1 addition & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ parameters:
paths:
- src
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
ignoreErrors:
-
path: %currentWorkingDirectory%/src/Engines/ElasticSearchEngine.php
message: '#Call to an undefined method Illuminate\\Database\\Eloquent\\Model::searchableAs\(\)\.#'
-
path: %currentWorkingDirectory%/src/Engines/ElasticSearchEngine.php
message: '#message.*ServerErrorResponseException constructor expects string, string|false given.#'
message: '#message.*ServerErrorResponseException constructor expects string, string\|false given.#'
-
path: %currentWorkingDirectory%/src/Engines/ElasticSearchEngine.php
message: '#Parameter \#2 \$search of function array_key_exists expects array, array\|\(callable\) given\.#'
Expand Down
7 changes: 4 additions & 3 deletions src/Console/Commands/ImportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Matchish\ScoutElasticSearch\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Collection;
use Matchish\ScoutElasticSearch\Jobs\Import;
use Matchish\ScoutElasticSearch\Jobs\QueueableJob;
use Matchish\ScoutElasticSearch\Searchable\ImportSource;
Expand All @@ -27,13 +28,13 @@ final class ImportCommand extends Command
*/
public function handle(): void
{
$this->searchableList($this->argument('searchable'))
$this->searchableList((array) $this->argument('searchable'))
->each(function ($searchable) {
$this->import($searchable);
});
}

private function searchableList($argument)
private function searchableList(array $argument): Collection
{
return collect($argument)->whenEmpty(function () {
$factory = new SearchableListFactory(app()->getNamespace(), app()->path());
Expand All @@ -42,7 +43,7 @@ private function searchableList($argument)
});
}

private function import($searchable)
private function import(string $searchable): void
{
$sourceFactory = app(ImportSourceFactory::class);
$source = $sourceFactory::from($searchable);
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Commands/ProgressBarFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Matchish\ScoutElasticSearch\Console\Commands;

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Style\OutputStyle;

class ProgressBarFactory
Expand All @@ -19,7 +20,7 @@ public function __construct(OutputStyle $output)
$this->output = $output;
}

public function create(int $max = 0)
public function create(int $max = 0): ProgressBar
{
$bar = $this->output->createProgressBar($max);
$bar->setBarCharacter('<fg=green>⚬</>');
Expand Down
2 changes: 1 addition & 1 deletion src/Database/Scopes/ChunkScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function apply(Builder $builder, Model $model)
});
}

public function key()
public function key(): string
{
return static::class;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ElasticSearch/EloquentHitsIteratorAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@ public function getIterator()
})->filter()->all();
}

return new \ArrayIterator($hits);
return new \ArrayIterator((array) $hits);
}
}
2 changes: 1 addition & 1 deletion src/ElasticSearch/Params/Indices/Alias/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function toArray()
];
}

public static function anyIndex($alias)
public static function anyIndex(string $alias): Get
{
return new static($alias, '*');
}
Expand Down
4 changes: 2 additions & 2 deletions src/ElasticSearch/Params/Indices/Alias/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function toArray(): array
];
}

public function add(string $index, string $alias)
public function add(string $index, string $alias): void
{
$this->actions[] = ['add' => [
'index' => $index,
'alias' => $alias,
]];
}

public function removeIndex($index)
public function removeIndex(string $index): void
{
$this->actions[] = ['remove_index' => ['index' => $index]];
}
Expand Down
14 changes: 8 additions & 6 deletions src/Engines/ElasticSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Illuminate\Database\Eloquent\Collection;
use Laravel\Scout\Builder as BaseBuilder;
use Laravel\Scout\Engines\Engine;
use Laravel\Scout\Searchable;
use Matchish\ScoutElasticSearch\ElasticSearch\HitsIteratorAggregate;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Bulk;
use Matchish\ScoutElasticSearch\ElasticSearch\Params\Indices\Refresh;
Expand Down Expand Up @@ -107,10 +106,13 @@ public function mapIds($results)
*/
public function map(BaseBuilder $builder, $results, $model)
{
$hits = app()->makeWith(HitsIteratorAggregate::class,
['results' => $results,
'callback' => $builder->queryCallback,
]);
$hits = app()->makeWith(
HitsIteratorAggregate::class,
[
'results' => $results,
'callback' => $builder->queryCallback,
]
);

return new Collection($hits);
}
Expand Down Expand Up @@ -141,7 +143,7 @@ private function performSearch(BaseBuilder $builder, $options = [])
$searchBody
);
}
/** @var Searchable $model */

$model = $builder->model;
$indexName = $builder->index ?: $model->searchableAs();
$params = new SearchParams($indexName, $searchBody->toArray());
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/ImportStages.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function fromSource(ImportSource $source)
{
$index = Index::fromSource($source);

return (new static([
return (new self([
new CleanUp($source),
new CreateWriteIndex($source, $index),
PullFromSource::chunked($source),
Expand Down
2 changes: 1 addition & 1 deletion src/Jobs/QueueableJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class QueueableJob implements ShouldQueue
use Queueable;
use ProgressReportable;

public function handle()
public function handle(): void
{
}
}
2 changes: 1 addition & 1 deletion src/Jobs/Stages/SwitchToNewAndRemoveOldIndex.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function handle(Client $elasticsearch): void
$params = new Update();
foreach ($response as $indexName => $alias) {
if ($indexName != $this->index->name()) {
$params->removeIndex($indexName);
$params->removeIndex((string) $indexName);
} else {
$params->add((string) $indexName, $source->searchableAs());
}
Expand Down
5 changes: 4 additions & 1 deletion src/ProgressReportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

trait ProgressReportable
{
/**
* @var ProgressBar|null
*/
private $progressBar;

public function withProgressReport(ProgressBar $progressBar)
public function withProgressReport(ProgressBar $progressBar): void
{
$this->progressBar = $progressBar;
}
Expand Down
24 changes: 18 additions & 6 deletions src/Searchable/DefaultImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@

namespace Matchish\ScoutElasticSearch\Searchable;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;
use Matchish\ScoutElasticSearch\Database\Scopes\PageScope;

final class DefaultImportSource implements ImportSource
{
const DEFAULT_CHUNK_SIZE = 500;

/**
* @var string
*/
private $className;
/**
* @var array
*/
private $scopes;

/**
Expand All @@ -22,12 +31,12 @@ public function __construct(string $className, array $scopes = [])
$this->scopes = $scopes;
}

public function syncWithSearchUsingQueue()
public function syncWithSearchUsingQueue(): ?string
{
return $this->model()->syncWithSearchUsingQueue();
}

public function syncWithSearchUsing()
public function syncWithSearchUsing(): ?string
{
return $this->model()->syncWithSearchUsing();
}
Expand All @@ -37,7 +46,7 @@ public function searchableAs(): string
return $this->model()->searchableAs();
}

public function chunked()
public function chunked(): Collection
{
$query = $this->newQuery();
$totalSearchables = $query->count();
Expand All @@ -63,7 +72,7 @@ private function model()
return new $this->className;
}

private function newQuery()
private function newQuery(): Builder
{
$query = $this->model()->newQuery();
$softDelete = $this->className::usesSoftDelete() && config('scout.soft_delete', false);
Expand All @@ -81,8 +90,11 @@ private function newQuery()
}, $query);
}

public function get()
public function get(): EloquentCollection
{
return $this->newQuery()->get();
/** @var EloquentCollection $models */
$models = $this->newQuery()->get();

return $models;
}
}
13 changes: 8 additions & 5 deletions src/Searchable/ImportSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

namespace Matchish\ScoutElasticSearch\Searchable;

use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Illuminate\Support\Collection;

interface ImportSource
{
public function syncWithSearchUsingQueue();
public function syncWithSearchUsingQueue(): ?string;

public function syncWithSearchUsing();
public function syncWithSearchUsing(): ?string;

public function searchableAs();
public function searchableAs(): string;

public function chunked();
public function chunked(): Collection;

public function get();
public function get(): EloquentCollection;
}
3 changes: 3 additions & 0 deletions src/Searchable/SearchableListFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

final class SearchableListFactory
{
/**
* @var array
*/
private static $declaredClasses;
/**
* @var string
Expand Down

0 comments on commit c00cd2b

Please sign in to comment.