Skip to content

Commit 93b18c1

Browse files
committed
Initial OpenSearch Scout driver
0 parents  commit 93b18c1

25 files changed

Lines changed: 1252 additions & 0 deletions

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[Makefile]
2+
indent_style = tab

.github/workflows/fix-style.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
on:
2+
push:
3+
paths:
4+
- '**.php'
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
php-code-styling:
11+
runs-on: ubuntu-latest
12+
timeout-minutes: 5
13+
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
ref: ${{ github.head_ref }}
19+
20+
- name: Fix PHP code style issues
21+
uses: aglipanci/laravel-pint-action@2.5
22+
23+
- name: Commit changes
24+
uses: stefanzweifel/git-auto-commit-action@v5
25+
with:
26+
commit_message: Fix styling

.github/workflows/run-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: run-tests
2+
3+
on:
4+
push:
5+
6+
jobs:
7+
test:
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: true
11+
matrix:
12+
os: [ubuntu-latest]
13+
php: [8.4, 8.3, 8.2]
14+
include:
15+
- php: 8.4
16+
laravel: 13.*
17+
testbench: 11.*
18+
19+
- php: 8.3
20+
laravel: 12.*
21+
testbench: 10.*
22+
23+
- php: 8.2
24+
laravel: 11.*
25+
testbench: 9.*
26+
27+
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.os }}
28+
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
38+
coverage: none
39+
40+
- name: Install dependencies
41+
run: |
42+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
43+
composer update --prefer-dist --no-interaction
44+
45+
- name: Execute tests
46+
run: vendor/bin/pest --ci

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/.idea
2+
/bin
3+
/vendor
4+
/composer.lock
5+
/phpunit.xml
6+
/.phpunit.result.cache
7+
/.php_cs
8+
/.php_cs.cache
9+
/.php-cs-fixer.cache
10+
/phpstan.neon

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Ivan Babenko
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# OpenSearch Scout Driver
2+
3+
OpenSearch driver for Laravel Scout.
4+
5+
## Installation
6+
7+
Install the package with Composer:
8+
9+
```bash
10+
composer require directorytree/opensearch-scout-driver
11+
```
12+
13+
Publish the Scout configuration file if your application has not already done so:
14+
15+
```bash
16+
php artisan vendor:publish --provider="Laravel\Scout\ScoutServiceProvider"
17+
```
18+
19+
Set Scout to use OpenSearch:
20+
21+
```php
22+
'driver' => env('SCOUT_DRIVER', 'opensearch'),
23+
```
24+
25+
Publish the OpenSearch client configuration:
26+
27+
```bash
28+
php artisan vendor:publish --provider="DirectoryTree\OpenSearchClient\OpenSearchClientServiceProvider"
29+
```
30+
31+
Publish the OpenSearch Scout configuration:
32+
33+
```bash
34+
php artisan vendor:publish --provider="DirectoryTree\OpenSearchScoutDriver\OpenSearchScoutServiceProvider"
35+
```
36+
37+
## Configuration
38+
39+
Configure the OpenSearch client connection in `config/opensearch.client.php`:
40+
41+
```php
42+
'default' => env('OPENSEARCH_CONNECTION', 'default'),
43+
44+
'connections' => [
45+
'default' => [
46+
'hosts' => [
47+
env('OPENSEARCH_HOST', 'localhost:9200'),
48+
],
49+
],
50+
],
51+
```
52+
53+
The Scout driver configuration is published to `config/opensearch.scout.php`:
54+
55+
```php
56+
'refresh_documents' => env('OPENSEARCH_SCOUT_REFRESH_DOCUMENTS', false),
57+
```
58+
59+
## Usage
60+
61+
Use Scout as usual:
62+
63+
```php
64+
use App\Models\Post;
65+
66+
$posts = Post::search('laravel')->get();
67+
```
68+
69+
The driver converts Scout builders into OpenSearch search requests and uses the configured OpenSearch client connection to index, delete, flush, and search models.

composer.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "directorytree/opensearch-scout-driver",
3+
"description": "OpenSearch driver for Laravel Scout",
4+
"keywords": [
5+
"opensearch",
6+
"scout",
7+
"laravel",
8+
"driver",
9+
"php"
10+
],
11+
"type": "library",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "DirectoryTree",
16+
"email": "support@directorytree.com"
17+
}
18+
],
19+
"autoload": {
20+
"psr-4": {
21+
"DirectoryTree\\OpenSearchScoutDriver\\": "src"
22+
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"DirectoryTree\\OpenSearchScoutDriver\\Tests\\": "tests"
27+
}
28+
},
29+
"require": {
30+
"php": "^8.2",
31+
"directorytree/opensearch-adapter": "dev-master",
32+
"directorytree/opensearch-client": "dev-master",
33+
"laravel/scout": "^10.0|^11.0|^12.0|^13.0"
34+
},
35+
"require-dev": {
36+
"laravel/framework": "^11.0|^12.0|^13.0",
37+
"laravel/pint": "^1.0",
38+
"mockery/mockery": "^1.0",
39+
"orchestra/testbench": "^9.0|^10.0|^11.0",
40+
"pestphp/pest": "^3.0"
41+
},
42+
"repositories": [
43+
{
44+
"type": "path",
45+
"url": "../OpenSearchAdapter"
46+
},
47+
{
48+
"type": "path",
49+
"url": "../OpenSearchClient"
50+
}
51+
],
52+
"config": {
53+
"allow-plugins": {
54+
"php-http/discovery": true,
55+
"pestphp/pest-plugin": true
56+
}
57+
},
58+
"extra": {
59+
"laravel": {
60+
"providers": [
61+
"DirectoryTree\\OpenSearchScoutDriver\\OpenSearchScoutServiceProvider"
62+
]
63+
}
64+
}
65+
}

config/opensearch.scout.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
return [
4+
/*
5+
|--------------------------------------------------------------------------
6+
| Refresh Documents
7+
|--------------------------------------------------------------------------
8+
|
9+
| This option determines whether indexed and deleted documents should be
10+
| made immediately available to search requests. This is useful while
11+
| testing, but production applications usually leave it disabled.
12+
|
13+
*/
14+
15+
'refresh_documents' => env('OPENSEARCH_SCOUT_REFRESH_DOCUMENTS', false),
16+
];

0 commit comments

Comments
 (0)