Skip to content

Commit 1dc9984

Browse files
committed
V3 prep
1 parent 3687d0e commit 1dc9984

File tree

6 files changed

+168
-65
lines changed

6 files changed

+168
-65
lines changed

.github/CODEOWNERS

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Laravel Elasticsearch Package Code Ownership
2+
# Defines who must review changes to specific parts of the codebase.
3+
4+
# Package metadata and config
5+
/composer.json @pdphilip
6+
/LICENSE @pdphilip
7+
/.github/ @pdphilip
8+
/README.md @pdphilip
9+
10+
# Core source code
11+
/src/ @pdphilip

.github/workflows/run-tests.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222

2323
# Docs: https://docs.github.com/en/actions/using-containerized-services
2424
services:
25-
elasticsearch:
26-
image: elasticsearch:7.17.3
25+
opensearch:
26+
image: opensearch:latest
2727
env:
2828
discovery.type: single-node
2929
ES_JAVA_OPTS: '-Xms512m -Xmx512m'
@@ -41,9 +41,9 @@ jobs:
4141
- name: Checkout 🛎
4242
uses: actions/checkout@v4
4343

44-
- name: Verify Elasticsearch connection 🧩
44+
- name: Verify Opensearch connection
4545
run: |
46-
curl -X GET "localhost:${{ job.services.elasticsearch.ports['9200'] }}/_cluster/health?pretty=true"
46+
curl -X GET "localhost:${{ job.services.opensearch.ports['9200'] }}/_cluster/health?pretty=true"
4747
4848
- name: Setup PHP 🏗
4949
uses: shivammathur/setup-php@v2
@@ -57,13 +57,13 @@ jobs:
5757
run: |
5858
composer install --no-interaction --prefer-dist --optimize-autoloader
5959
60-
- name: List Installed Dependencies 📦
60+
- name: List Installed Dependencies
6161
run: composer show -D
6262

63-
- name: Run tests 🧪
63+
- name: Run tests
6464
run: |
6565
./vendor/bin/pest --version
6666
./vendor/bin/pest
6767
env:
6868
REDIS_PORT: ${{ job.services.redis.ports['6379'] }}
69-
ELASTICSEARCH_PORT: ${{ job.services.elasticsearch.ports['9200'] }}
69+
OPENSEARCH_PORT: ${{ job.services.opensearch.ports['9200'] }}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: "Update Changelog"
2+
3+
on:
4+
release:
5+
types: [released]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
update:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
ref: main
20+
21+
- name: Update Changelog
22+
uses: stefanzweifel/changelog-updater-action@v1
23+
with:
24+
latest-version: ${{ github.event.release.name }}
25+
release-notes: ${{ github.event.release.body }}
26+
27+
- name: Commit updated CHANGELOG
28+
uses: stefanzweifel/git-auto-commit-action@v5
29+
with:
30+
branch: main
31+
commit_message: Update CHANGELOG
32+
file_pattern: CHANGELOG.md

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
All notable changes to this `laravel-opensearch` package will be documented in this file.

README.md

+110-52
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,100 @@
22

33
# Laravel-OpenSearch
44

5-
[![Latest Stable Version](http://img.shields.io/github/release/pdphilip/laravel-opensearch.svg)](https://packagist.org/packages/pdphilip/laravel-opensearch)
5+
[![Latest Stable Version](http://img.shields.io/github/release/pdphilip/laravel-opensearch.svg)](https://packagist.org/packages/pdphilip/opensearch)
6+
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/pdphilip/laravel-opensearch/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/pdphilip/laravel-opensearch/actions/workflows/run-tests.yml?query=branch%3Amain)
7+
[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/pdphilip/laravel-opensearch/phpstan.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/pdphilip/laravel-opensearch/actions/workflows/phpstan.yml?query=branch%3Amain++)
68
[![Total Downloads](http://img.shields.io/packagist/dm/pdphilip/opensearch.svg)](https://packagist.org/packages/pdphilip/opensearch)
79

8-
9-
> **This package has been built off the back of the original [Elasticsearch version](https://github.com/pdphilip/laravel-elasticsearch) of this package**
10-
>
11-
> **The starting point of this package was forked from `v4.0.1` with over 2 years of development**
12-
1310
[OpenSearch](https://opensearch.net/) is a distributed, community-driven, Apache 2.0-licensed, 100% open-source search and analytics suite used for a broad set of use cases like real-time application monitoring, log analytics, and website
1411
search.
1512

1613
### An OpenSearch implementation of Laravel's Eloquent ORM
1714

15+
### The Power of OpenSearch with Laravel's Eloquent
16+
1817
This package extends Laravel's Eloquent model and query builder with seamless integration of OpenSearch functionalities. Designed to feel native to Laravel, this package enables you to work with Eloquent models while leveraging the
1918
powerful search and analytics capabilities of OpenSearch.
2019

21-
Examples:
20+
The Eloquent you already know:
2221

2322
```php
24-
$logs = UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
23+
UserLog::where('created_at','>=',Carbon::now()->subDays(30))->get();
2524
```
2625

2726
```php
28-
$updates = UserLog::where('status', 1)->update(['status' => 4]);
27+
UserLog::create([
28+
'user_id' => '2936adb0-b10d-11ed-8e03-0b234bda3e12',
29+
'ip' => '62.182.98.146',
30+
'location' => [40.7185,-74.0025],
31+
'country_code' => 'US',
32+
'status' => 1,
33+
]);
2934
```
3035

3136
```php
32-
$updates = UserLog::where('status', 1)->paginate(50);
37+
UserLog::where('status', 1)->update(['status' => 4]);
3338
```
3439

3540
```php
36-
$profiles = UserProfile::whereIn('country_code',['US','CA'])->orderByDesc('last_login')->take(10)->get();
41+
UserLog::where('status', 4)->orderByDesc('created_at')->paginate(50);
3742
```
3843

3944
```php
40-
$deleted = UserProfile::where('state','unsubscribed')->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
45+
UserProfile::whereIn('country_code',['US','CA'])
46+
->orderByDesc('last_login')->take(10)->get();
4147
```
4248

4349
```php
44-
$search = UserProfile::phrase('loves espressos')->highlight()->search();
50+
UserProfile::where('state','unsubscribed')
51+
->where('updated_at','<=',Carbon::now()->subDays(90))->delete();
52+
```
53+
54+
opensearch with Eloquent:
55+
56+
```php
57+
UserProfile::searchTerm('Laravel')->orSearchTerm('opensearch')->get();
58+
```
59+
60+
```php
61+
UserProfile::searchPhrasePrefix('loves espressos and t')->highlight()->get();
62+
```
63+
64+
```php
65+
UserProfile::whereMatch('bio', 'PHP')->get();
66+
```
67+
68+
```php
69+
UserLog::whereGeoDistance('location', '10km', [40.7185,-74.0025])->get();
70+
```
71+
72+
```php
73+
UserProfile::whereFuzzy('description', 'qick brwn fx')->get();
74+
```
75+
76+
Built in Relationships (even to SQL models):
77+
78+
```php
79+
UserLog::where('status', 1)->orderByDesc('created_at')->with('user')->get();
4580
```
4681

47-
---
48-
> ### Read the [Documentation](https://opensearch.pdphilip.com/)
4982
---
5083

84+
# Read the [Documentation](https://opensearch.pdphilip.com/)
85+
5186
## Installation
5287

53-
**Laravel 10 & 11 (main):**
88+
**Laravel 10.x, 11.x & 12.x (main):**
5489

5590
```bash
5691
composer require pdphilip/opensearch
5792
```
5893

59-
| Laravel Version | Command | Maintained |
60-
|-----------------|--------------------------------------------|------------|
61-
| Laravel 10 & 11 | `composer require pdphilip/opensearch:~2 ` ||
62-
| Laravel 8 & 9 | `composer require pdphilip/opensearch:~1` ||
94+
| Laravel Version | Command | Maintained |
95+
|--------------------|--------------------------------------------|------------|
96+
| Laravel 10/11/12 | `composer require pdphilip/opensearch:~3 ` ||
97+
| Laravel 10/11 (v2) | `composer require pdphilip/opensearch:~2 ` | ❌ EOL |
98+
| Laravel 8 & 9 | `composer require pdphilip/opensearch:~1` | ❌ EOL |
6399

64100
## Configuration
65101

@@ -69,22 +105,30 @@ composer require pdphilip/opensearch
69105
OS_HOSTS="http://opensearch:9200"
70106
OS_USERNAME=
71107
OS_PASSWORD=
72-
OS_INDEX_PREFIX=my_app
73-
108+
OS_INDEX_PREFIX=my_app_
109+
# prefix will be added to all indexes created by the package with an underscore
110+
# ex: my_app_user_logs for UserLog.php model
111+
112+
# AWS SigV4 Config:
74113
OS_SIG_V4_PROVIDER=
75114
OS_SIG_V4_REGION=
76115
OS_SIG_V4_SERVICE=
77116

117+
# Cert Config:
78118
OS_SSL_CERT=
79119
OS_SSL_CERT_PASSWORD=
80120
OS_SSL_KEY=
81121
OS_SSL_KEY_PASSWORD=
82122

123+
# Optional Settings:
83124
OS_OPT_VERIFY_SSL=true
84125
OS_OPT_RETRIES=
85126
OS_OPT_SNIFF_ON_START=
86127
OS_OPT_PORT_HOST_HEADERS=
87-
OS_ERROR_INDEX=
128+
OS_OPT_ID_SORTABLE=false
129+
OS_OPT_META_HEADERS=true
130+
OS_OPT_BYPASS_MAP_VALIDATION=false
131+
OS_OPT_DEFAULT_LIMIT=1000
88132
```
89133

90134
For multiple nodes, pass in as comma-separated:
@@ -93,7 +137,7 @@ For multiple nodes, pass in as comma-separated:
93137
OS_HOSTS="http://opensearch-node1:9200,http://opensearch-node2:9200,http://opensearch-node3:9200"
94138
```
95139

96-
2. In `config/database.php`, add the opensearch connection:
140+
2. In `config/database.php`, add the OpensSearch connection:
97141

98142
```php
99143
'opensearch' => [
@@ -116,12 +160,15 @@ OS_HOSTS="http://opensearch-node1:9200,http://opensearch-node2:9200,http://opens
116160
],
117161
'index_prefix' => env('OS_INDEX_PREFIX', false),
118162
'options' => [
119-
'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
120-
'retires' => env('OS_OPT_RETRIES'),
121-
'sniff_on_start' => env('OS_OPT_SNIFF_ON_START'),
122-
'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS'),
163+
'bypass_map_validation' => env('OS_OPT_BYPASS_MAP_VALIDATION', false),
164+
'ssl_verification' => env('OS_OPT_VERIFY_SSL', true),
165+
'retires' => env('OS_OPT_RETRIES',null),
166+
'sniff_on_start' => env('OS_OPT_SNIFF_ON_START',false),
167+
'logging' => env('OS_OPT_LOGGING', false),
168+
'port_in_host_header' => env('OS_OPT_PORT_HOST_HEADERS',false),
169+
'default_limit' => env('OS_OPT_DEFAULT_LIMIT', 1000),
170+
'allow_id_sort' => env('OS_OPT_ID_SORTABLE', false),
123171
],
124-
'error_log_index' => env('OS_ERROR_INDEX', false),
125172
],
126173
```
127174

@@ -156,34 +203,45 @@ Now, you're all set to use OpenSearch with Laravel as if it were native to the f
156203

157204
# Documentation Links
158205

159-
## Getting Started
206+
### Getting Started
160207

161-
- [Installation](https://opensearch.pdphilip.com/#installation)
162-
- [Configuration](https://opensearch.pdphilip.com/#configuration)
208+
- [Installation](https://opensearch.pdphilip.com/getting-started)
209+
- [Configuration](https://opensearch.pdphilip.com/getting-started#configuration-guide)
163210

164-
## Eloquent
211+
### Eloquent
165212

166-
- [The Base Model](https://opensearch.pdphilip.com/the-base-model)
167-
- [Querying Models](https://opensearch.pdphilip.com/querying-models)
168-
- [Saving Models](https://opensearch.pdphilip.com/saving-models)
169-
- [Deleting Models](https://opensearch.pdphilip.com/deleting-models)
170-
- [Ordering and Pagination](https://opensearch.pdphilip.com/ordering-and-pagination)
171-
- [Distinct and GroupBy](https://opensearch.pdphilip.com/distinct)
172-
- [Aggregations](https://opensearch.pdphilip.com/aggregation)
173-
- [Chunking](https://opensearch.pdphilip.com/chunking)
174-
- [Nested Queries](https://opensearch.pdphilip.com/nested-queries)
175-
- [OpenSearch Specific Queries](https://opensearch.pdphilip.com/os-specific)
176-
- [Full-Text Search](https://opensearch.pdphilip.com/full-text-search)
177-
- [Dynamic Indices](https://opensearch.pdphilip.com/dynamic-indices)
213+
- [The Base Model](https://opensearch.pdphilip.com/eloquent/the-base-model)
214+
- [Saving Models](https://opensearch.pdphilip.com/eloquent/saving-models)
215+
- [Deleting Models](https://opensearch.pdphilip.com/eloquent/deleting-models)
216+
- [Querying Models](https://opensearch.pdphilip.com/eloquent/querying-models)
217+
- [Eloquent Queries](https://opensearch.pdphilip.com/eloquent/eloquent-queries)
218+
- [OS Eloquent Queries](https://opensearch.pdphilip.com/eloquent/os-queries)
219+
- [Cross Fields Search Queries](https://opensearch.pdphilip.com/eloquent/search-queries)
220+
- [Aggregation Queries](https://opensearch.pdphilip.com/eloquent/aggregation)
221+
- [Distinct and GroupBy Queries](https://opensearch.pdphilip.com/eloquent/distinct)
222+
- [Nested Queries](https://opensearch.pdphilip.com/eloquent/nested-queries)
223+
- [Ordering and Pagination](https://opensearch.pdphilip.com/eloquent/ordering-and-pagination)
224+
- [Chunking](https://opensearch.pdphilip.com/eloquent/chunking)
225+
- [Dynamic Indices](https://opensearch.pdphilip.com/eloquent/dynamic-indices)
178226

179-
## Relationships
227+
### Relationships
180228

181-
- [OpenSearch to OpenSearch](https://opensearch.pdphilip.com/os-os)
182-
- [OpenSearch to MySQL](https://opensearch.pdphilip.com/os-mysql)
229+
- [OpenSearch to OpenSearch](https://opensearch.pdphilip.com/relationships/os-os)
230+
- [OpenSearch to SQL](https://opensearch.pdphilip.com/relationships/os-sql)
183231

184-
## Schema/Index
232+
### Migrations: Schema/Index
185233

186-
- [Migrations](https://opensearch.pdphilip.com/migrations)
187-
- [Re-indexing Process](https://opensearch.pdphilip.com/re-indexing)
234+
- [Migrations](https://opensearch.pdphilip.com/schema/migrations)
235+
- [Index Blueprint](https://opensearch.pdphilip.com/schema/index-blueprint)
188236

189-
---
237+
### Misc
238+
239+
- [Mapping OS to Eloquent](https://opensearch.pdphilip.com/notes/opensearch-to-eloquent-map)
240+
241+
## Credits
242+
243+
- [David Philip](https://github.com/pdphilip)
244+
245+
## License
246+
247+
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

src/Eloquent/Docs/ModelDocs.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Illuminate\Pagination\Cursor;
99
use PDPhilip\OpenSearch\Eloquent\Builder;
1010
use PDPhilip\OpenSearch\Eloquent\Model;
11+
use PDPhilip\OpenSearch\Eloquent\OpenCollection;
1112
use PDPhilip\OpenSearch\Pagination\SearchAfterPaginator;
1213

1314
/**
@@ -178,14 +179,14 @@
178179
* @method static Model firstOrCreate($attributes, $values = [])
179180
*-----------------------------------
180181
* @method static array getModels($columns = ['*'])
181-
* @method static ElasticCollection get($columns = ['*'])
182-
* @method static ElasticCollection insert($values, $returnData = null)
182+
* @method static OpenCollection get($columns = ['*'])
183+
* @method static OpenCollection insert($values, $returnData = null)
183184
*-----------------------------------
184185
* @method static array toDsl($columns = ['*'])
185186
* @method static array toSql($columns = ['*'])
186187
*-----------------------------------
187188
* @method static mixed rawDsl($bodyParams)
188-
* @method static ElasticCollection rawSearch($bodyParams)
189+
* @method static OpenCollection rawSearch($bodyParams)
189190
* @method static array rawAggregation($bodyParams)
190191
*-----------------------------------
191192
* @method static LengthAwarePaginator paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $page = null, $total = null)
@@ -194,7 +195,7 @@
194195
* @method static bool chunk($count, $callback)
195196
* @method static bool chunkById($count, $callback, $column = '_id', $alias = null)
196197
* -----------------------------------
197-
* @method static ElasticCollection distinct($columns = [], $includeCount = false)
198+
* @method static OpenCollection distinct($columns = [], $includeCount = false)
198199
*===========================================
199200
* Aggregators Methods
200201
*===========================================
@@ -204,14 +205,12 @@
204205
* @method static int|array avg($columns)
205206
* @method static mixed agg(array $functions, $column)
206207
*-----------------------------------
207-
* @method static mixed boxplot($columns, $options = [])
208208
* @method static mixed cardinality($columns, $options = [])
209209
* @method static mixed extendedStats($columns, $options = [])
210210
* @method static mixed matrix($columns, $options = [])
211211
* @method static mixed medianAbsoluteDeviation($columns, $options = [])
212212
* @method static mixed percentiles($columns, $options = [])
213213
* @method static mixed stats($columns, $options = [])
214-
* @method static mixed stringStats( $columns, $options = [])
215214
*-----------------------------------
216215
* @method static array getAggregationResults()
217216
* @method static array getRawAggregationResults()

0 commit comments

Comments
 (0)