Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: zingimmick/laravel-scout-opensearch
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.x
Choose a base ref
...
head repository: vormkracht10/laravel-scout-opensearch
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.x
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 5 commits
  • 14 files changed
  • 2 contributors

Commits on Aug 13, 2024

  1. Add option to match for strings

    Casmo committed Aug 13, 2024
    Copy the full SHA
    6031a5f View commit details
  2. Update to standalone package

    Casmo committed Aug 13, 2024
    Copy the full SHA
    8dfaf43 View commit details
  3. Rename to standard package

    Casmo committed Aug 13, 2024
    Copy the full SHA
    124ee33 View commit details

Commits on Aug 19, 2024

  1. Copy the full SHA
    64b2d3c View commit details

Commits on Sep 4, 2024

  1. Copy the full SHA
    0d37741 View commit details
22 changes: 13 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
{
"name": "zing/laravel-scout-opensearch",
"name": "vormkracht10/laravel-scout-opensearch",
"description": "Laravel Scout custom engine for OpenSearch",
"keywords": ["opensearch", "laravel", "scout", "search"],
"license": "MIT",
"homepage": "https://github.com/zingimmick/laravel-scout-opensearch",
"homepage": "https://github.com/vormkracht10/laravel-scout-opensearch",
"support": {
"issues": "https://github.com/zingimmick/laravel-scout-opensearch/issues",
"source": "https://github.com/zingimmick/laravel-scout-opensearch"
"issues": "https://github.com/vormkracht10/laravel-scout-opensearch/issues",
"source": "https://github.com/vormkracht10/laravel-scout-opensearch"
},
"authors": [
{
"name": "Mathieu de Ruiter",
"email": "mathieu@vormkracht10.nl",
"homepage": "https://github.com/casmo"
},
{
"name": "zingimmick",
"email": "zingimmick@outlook.com",
@@ -34,17 +39,16 @@
"nunomaduro/larastan": "^1.0 || ^2.0",
"orchestra/testbench": "^4.5 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpstan/phpstan-mockery": "^1.0",
"phpunit/phpunit": "^9.3.3 || ^10.0 || ^11.0",
"zing/coding-standard": "^6.4 || ^7.0"
"phpunit/phpunit": "^9.3.3 || ^10.0 || ^11.0"
},
"autoload": {
"psr-4": {
"Zing\\LaravelScout\\OpenSearch\\": "src"
"Vormkracht10\\LaravelScout\\OpenSearch\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Zing\\LaravelScout\\OpenSearch\\Tests\\": "tests"
"Vormkracht10\\LaravelScout\\OpenSearch\\Tests\\": "tests"
}
},
"scripts": {
@@ -70,7 +74,7 @@
"extra": {
"laravel": {
"providers": [
"Zing\\LaravelScout\\OpenSearch\\OpenSearchServiceProvider"
"Vormkracht10\\LaravelScout\\OpenSearch\\OpenSearchServiceProvider"
]
}
},
108 changes: 77 additions & 31 deletions src/Engines/OpenSearchEngine.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Engines;
namespace Vormkracht10\LaravelScout\OpenSearch\Engines;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -148,50 +148,96 @@ protected function performSearch(Builder $builder, array $options = []): mixed
return \call_user_func($builder->callback, $this->client, $builder->query, $options);
}

$query = $builder->query;
$must = collect([
[
'query_string' => [
'query' => $query,
$options['query'] = [
'bool' => [
'must' => [
[
'query_string' => [
'query' => $builder->query
]
]
],
],
]);
$must = $must->merge(collect($builder->wheres)
->map(static fn ($value, $key): array => [
'term' => [
$key => $value,
'should' => [

],
])->values())->values();
'must_not' => [

if (property_exists($builder, 'whereIns')) {
$must = $must->merge(collect($builder->whereIns)->map(static fn ($values, $key): array => [
'terms' => [
$key => $values,
],
])->values())->values();
'filter' => [
]
]
];

collect($builder->wheres)
->each(function ($value, $key) use (&$options) {
if (is_string($value)) {
$options['query']['bool']['must'][] = [
'match' => [
$key => $value
]
];
}
else {
$options['query']['bool']['must'][] = [
'term' => [
$key => $value
]
];
}
});

if (property_exists($builder, 'whereIns')) {
collect($builder->whereIns)
->each(function ($values, $key) use (&$options) {
if (is_string($values[0])) {
$options['query']['bool']['must'][] = [
'match' => [
$key => [
'query' => implode(' ', $values),
'operator' => 'or',
'minimum_should_match' => 1
]
]
];
}
else {
$options['query']['bool']['must'][] = [
'terms' => [
$key => $values
]
];
}
});
}

$mustNot = collect();
if (property_exists($builder, 'whereNotIns')) {
$mustNot = $mustNot->merge(collect($builder->whereNotIns)->map(static fn ($values, $key): array => [
'terms' => [
$key => $values,
],
])->values())->values();
collect($builder->whereNotIns)
->each(function ($values, $key) use (&$options) {
if (is_string($values[0])) {
foreach ($values as $value) {
$options['query']['bool']['must_not'][] = [
'match' => [
$key => $value
]
];
}
}
else {
$options['query']['bool']['must_not'][] = [
'terms' => [
$key => $values
]
];
}
});
}

$options['query'] = [
'bool' => [
'must' => $must->all(),
'must_not' => $mustNot->all(),
],
];

$options['sort'] = collect($builder->orders)->map(static fn ($order): array => [
$order['column'] => [
'order' => $order['direction'],
],
])->all();

$result = $this->client->search([
'index' => $index,
'body' => $options,
4 changes: 2 additions & 2 deletions src/OpenSearchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch;
namespace Vormkracht10\LaravelScout\OpenSearch;

use Illuminate\Support\ServiceProvider;
use Laravel\Scout\EngineManager;
use OpenSearch\Client;
use OpenSearch\ClientBuilder;
use Zing\LaravelScout\OpenSearch\Engines\OpenSearchEngine;
use Vormkracht10\LaravelScout\OpenSearch\Engines\OpenSearchEngine;

class OpenSearchServiceProvider extends ServiceProvider
{
2 changes: 1 addition & 1 deletion tests/Fixtures/CustomKeySearchableModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

class CustomKeySearchableModel extends SearchableModel
{
2 changes: 1 addition & 1 deletion tests/Fixtures/EmptySearchableModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

class EmptySearchableModel extends SearchableModel
{
2 changes: 1 addition & 1 deletion tests/Fixtures/SearchableAndSoftDeletesModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
2 changes: 1 addition & 1 deletion tests/Fixtures/SearchableModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

use Illuminate\Database\Eloquent\Model;
use Laravel\Scout\Searchable;
2 changes: 1 addition & 1 deletion tests/Fixtures/SearchableModelHasUuids.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Database\Eloquent\Model;
2 changes: 1 addition & 1 deletion tests/Fixtures/SoftDeletedEmptySearchableModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests\Fixtures;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures;

class SoftDeletedEmptySearchableModel extends SearchableModel
{
14 changes: 7 additions & 7 deletions tests/OpenSearchEngineTest.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests;

use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Collection;
@@ -14,12 +14,12 @@
use Laravel\Scout\Jobs\RemoveFromSearch;
use Mockery as m;
use OpenSearch\Client;
use Zing\LaravelScout\OpenSearch\Engines\OpenSearchEngine;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\CustomKeySearchableModel;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\EmptySearchableModel;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\SearchableAndSoftDeletesModel;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\SearchableModel;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\SoftDeletedEmptySearchableModel;
use Vormkracht10\LaravelScout\OpenSearch\Engines\OpenSearchEngine;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\CustomKeySearchableModel;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\EmptySearchableModel;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\SearchableAndSoftDeletesModel;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\SearchableModel;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\SoftDeletedEmptySearchableModel;

/**
* @internal
4 changes: 2 additions & 2 deletions tests/ScoutHasUuidsTest.php
Original file line number Diff line number Diff line change
@@ -2,13 +2,13 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests;

use Illuminate\Database\Eloquent\Concerns\HasUuids;
use Illuminate\Foundation\Testing\WithFaker;
use Laravel\Scout\Builder;
use OpenSearch\Client;
use Zing\LaravelScout\OpenSearch\Tests\Fixtures\SearchableModelHasUuids;
use Vormkracht10\LaravelScout\OpenSearch\Tests\Fixtures\SearchableModelHasUuids;

/**
* @internal
2 changes: 1 addition & 1 deletion tests/ScoutTest.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests;

use Illuminate\Foundation\Testing\WithFaker;
use Laravel\Scout\Builder;
2 changes: 1 addition & 1 deletion tests/SearchableModel.php
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
4 changes: 2 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@

declare(strict_types=1);

namespace Zing\LaravelScout\OpenSearch\Tests;
namespace Vormkracht10\LaravelScout\OpenSearch\Tests;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
use Laravel\Scout\ScoutServiceProvider;
use OpenSearch\ClientBuilder;
use Orchestra\Testbench\TestCase as BaseTestCase;
use Zing\LaravelScout\OpenSearch\OpenSearchServiceProvider;
use Vormkracht10\LaravelScout\OpenSearch\OpenSearchServiceProvider;

abstract class TestCase extends BaseTestCase
{