Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to add Routing meta-field to be able to use join datatype #91

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ build:
coverage:
file: 'coverage.clover'
format: 'clover'
dependencies:
override:
- composer update --no-interaction --no-suggest --prefer-source
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<img alt="Import progress report" src="https://raw.githubusercontent.com/matchish/laravel-scout-elasticsearch/master/docs/demo.gif" >

<p align="center">
<a href="https://scrutinizer-ci.com/g/matchish/laravel-scout-elasticsearch/"><img src="https://img.shields.io/scrutinizer/build/g/matchish/laravel-scout-elasticsearch.svg" alt="Build Status"></img></a>
<a href="https://travis-ci.com/matchish/laravel-scout-elasticsearch"><img src="https://img.shields.io/travis/com/matchish/laravel-scout-elasticsearch/master.svg" alt="Build Status"></img></a>
<a href="https://scrutinizer-ci.com/g/matchish/laravel-scout-elasticsearch"><img alt="Code quality" src="https://img.shields.io/scrutinizer/g/matchish/laravel-scout-elasticsearch.svg?label=quality"></img></a>
<a href="https://scrutinizer-ci.com/g/matchish/laravel-scout-elasticsearch"><img src="https://img.shields.io/scrutinizer/coverage/g/matchish/laravel-scout-elasticsearch.svg" alt="Coverage"></img></a>
<a href="https://packagist.org/packages/matchish/laravel-scout-elasticsearch"><img src="https://poser.pugx.org/matchish/laravel-scout-elasticsearch/d/total.svg" alt="Total Downloads"></a>
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
},
"require-dev": {
"fzaninotto/faker": "^1.8",
"phpstan/phpstan": "^0.11",
"orchestra/testbench": "^3.0",
"phpunit/phpunit": "^7.4",
"illuminate/support": "5.6.*|5.7.*|5.8.*",
"nunomaduro/larastan": "~0.3",
"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"
},
"autoload-dev": {
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ parameters:
paths:
- src
reportUnmatchedIgnoredErrors: false
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
ignoreErrors:
-
path: %currentWorkingDirectory%/src/Engines/ElasticSearchEngine.php
Expand Down
4 changes: 4 additions & 0 deletions src/ElasticSearch/Params/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function delete($docs): void
}

/**
* TODO: Add ability to extend payload without modifying the class.
*
* @return array
*/
public function toArray(): array
Expand All @@ -47,6 +49,7 @@ function ($payload, $model) {
'_index' => $model->searchableAs(),
'_id' => $model->getScoutKey(),
'_type' => '_doc',
'routing' => false === empty($model->routing) ? $model->routing : $model->getScoutKey(),
],
];

Expand All @@ -67,6 +70,7 @@ function ($payload, $model) {
'_index' => $model->searchableAs(),
'_id' => $model->getScoutKey(),
'_type' => '_doc',
'routing' => false === empty($model->routing) ? $model->routing : $model->getScoutKey(),
],
];

Expand Down
2 changes: 1 addition & 1 deletion src/Engines/ElasticSearchEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function map(BaseBuilder $builder, $results, $model)
{
$hits = app()->makeWith(HitsIteratorAggregate::class,
['results' => $results,
'callback' => $builder->queryCallback,
'callback' => $builder->queryCallback,
]);

return new Collection($hits);
Expand Down
12 changes: 6 additions & 6 deletions tests/Integration/Elasticsearch/HitsIteratorAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class HitsIteratorAggregateTest extends TestCase
public function test_hits_iterator_aggregate_binds_to_eloquent_implementation()
{
$iteratorAggregate = $this->app->makeWith(HitsIteratorAggregate::class, [
'results' => [],
'callback' => null,
]);
'results' => [],
'callback' => null,
]);

$this->assertEquals(EloquentHitsIteratorAggregate::class, get_class($iteratorAggregate));
}
Expand All @@ -24,9 +24,9 @@ public function test_override_bind_for_custom_iterator_aggregate_implementation(
$this->app->bind(HitsIteratorAggregate::class, CustomHitsIteratorAggregate::class);

$iteratorAggregate = $this->app->makeWith(HitsIteratorAggregate::class, [
'results' => [],
'callback' => null,
]);
'results' => [],
'callback' => null,
]);

$this->assertEquals(CustomHitsIteratorAggregate::class, get_class($iteratorAggregate));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ElasticSearch/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function test_creation_from_searchable()

namespace Matchish\ScoutElasticSearch\ElasticSearch;

function time():int
function time(): int
{
return 1525376494;
}
10 changes: 5 additions & 5 deletions tests/Unit/ElasticSearch/Params/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function test_delete()
$params = $bulk->toArray();

$this->assertEquals([
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]]],
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]]],
], $params);
}

Expand All @@ -31,7 +31,7 @@ public function test_delete_with_custom_key_name()
$params = $bulk->toArray();

$this->assertEquals([
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout']]],
'body' => [['delete' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout', 'routing' => 'Scout']]],
], $params);
}

Expand All @@ -45,7 +45,7 @@ public function test_index()

$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]],
['title' => 'Scout', 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand All @@ -62,7 +62,7 @@ public function test_index_with_custom_key_name()

$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout']],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 'Scout', 'routing' => 'Scout']],
['title' => 'Scout', 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand All @@ -78,7 +78,7 @@ public function test_push_soft_delete_meta_data()
$params = $bulk->toArray();
$this->assertEquals([
'body' => [
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2]],
['index' => ['_index' => 'products', '_type' => '_doc', '_id' => 2, 'routing' => 2]],
['title' => 'Scout', '__soft_deleted' => 0, 'id' => 2, '__class_name' => 'App\Product'],
],
], $params);
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Engines/ElasticSearchEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function test_pass_query_to_callback_before_executing()
'hits' => [
[
'_id' => 1, '_source' => [
'__class_name' => Product::class,
], ],
'__class_name' => Product::class,
], ],
[
'_id' => 2, '_source' => [
'__class_name' => Product::class,
], ],
'__class_name' => Product::class,
], ],
],
'total' => 2,
], ], new Product());
Expand Down