Skip to content

Commit 8d7c37f

Browse files
committed
Several upgrades and bug fixes
1 parent 8d4ad74 commit 8d7c37f

File tree

15 files changed

+798
-668
lines changed

15 files changed

+798
-668
lines changed

README.md

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ Elasticsearch in laravel as if it were native to Laravel, meaning:
1919
- [Eloquent style searching](#elasticsearching)
2020

2121
> # Alpha release notice
22-
> This package is being released prematurely to an interested community of testers. It is not ready for production just yet only due to a lack of testing mileage. Once deemed stable, the plugin will move to V1. Elasticsearch is a deep topic on its own and there are many native features that have not yet been included. I built this because I needed it but this plugin is for everyone; submit issues (there's no way I could have found all the edge cases on my own) and feel free to submit pull requests.
22+
> This package is being released prematurely to an interested community of testers. It is not ready for production just
23+
> yet only due to a lack of testing mileage. Once deemed stable, the plugin will move to V1. Elasticsearch is a deep topic
24+
> on its own and there are many native features that have not yet been included. I built this because I needed it but this
25+
> plugin is for everyone; submit issues (there's no way I could have found all the edge cases on my own) and feel free to
26+
> submit pull requests.
2327
>
2428
> #### Versioning Schema: {plugin_version}.{laravel_version}.{iteration}
2529
>
@@ -306,7 +310,9 @@ Elasticsearch [Matrix](https://www.elastic.co/guide/en/elasticsearch/reference/c
306310
$stats = Product::whereNotIn('color', ['red','green'])->matrix('price');
307311
$stats = Product::whereNotIn('color', ['red', 'green'])->matrix(['price', 'orders']);
308312
```
313+
309314
Matrix results return as (example):
315+
310316
```json
311317
{
312318
"matrix": {
@@ -388,8 +394,6 @@ Pagination links (Blade)
388394
{{ $products->appends(request()->query())->links() }}
389395
```
390396

391-
392-
393397
Elasticsearch specific queries
394398
-----------------------------
395399

@@ -411,22 +415,22 @@ UserLog::where('status',7)->filterGeoBox('agent.geo',[-10,10],[10,-10])->get();
411415
Filters results that fall within a radius distance from a `point[lat,lon]`
412416

413417
- **Method**: `filterGeoPoint($field,$distance,$point)`
414-
- `$distance` is a string value of distance and distance-unit, see [https://www.elastic.co/guide/en/elasticsearch/reference/current/api-conventions.html#distance-units](distance units)
418+
- `$distance` is a string value of distance and distance-unit,
419+
see [https://www.elastic.co/guide/en/elasticsearch/reference/current/api-conventions.html#distance-units](distance units)
415420

416421
```php
417422
UserLog::where('status',7)->filterGeoPoint('agent.geo','20km',[0,0])->get();
418423
```
419424

420-
**Note:** the field **must be of type geo otherwise your [shards will fail](#error-all-shards-failed) **, make sure to set the geo field in your [migration](#migrations), ex:
425+
**Note:** the field **must be of type geo otherwise your [shards will fail](#error-all-shards-failed) **, make sure to
426+
set the geo field in your [migration](#migrations), ex:
421427

422428
```php
423429
Schema::create('user_logs',function (IndexBlueprint $index){
424430
$index->geo('agent.geo');
425431
});
426432
```
427433

428-
429-
430434
#### Regex (in where)
431435

432436
[Syntax](https://www.elastic.co/guide/en/elasticsearch/reference/current/regexp-syntax.html)
@@ -436,8 +440,6 @@ Product::whereRegex('color','bl(ue)?(ack)?')->get(); //Returns blue or black
436440
Product::whereRegex('color','bl...*')->get(); //Returns blue or black or blond or blush etc..
437441
```
438442

439-
440-
441443
Saving Models
442444
-------------
443445

@@ -577,15 +579,15 @@ $product->forceDelete();
577579

578580
```
579581

580-
581-
582582
Elasticsearching
583583
===============
584584

585585
The Search Query
586586
----------------
587587

588-
The search query is different from the `where()->get()` methods as search is performed over all (or selected) fields in the index. Building a search query is easy and intuitive to seasoned Eloquenters with a slight twist; simply static call off your model with `term()`, chain your ORM clauses, then end your chain with `search()` to perform your search, ie:
588+
The search query is different from the `where()->get()` methods as search is performed over all (or selected) fields in
589+
the index. Building a search query is easy and intuitive to seasoned Eloquenters with a slight twist; simply static call
590+
off your model with `term()`, chain your ORM clauses, then end your chain with `search()` to perform your search, ie:
589591

590592
```php
591593
MyModel::term('XYZ')->.........->search()
@@ -595,8 +597,9 @@ MyModel::term('XYZ')->.........->search()
595597

596598
**1.1 Simple example**
597599

598-
- To search across all the fields in the **books** index for '**eric**' (case-insensitive if the default analyser is set),
599-
- Results ordered by most relevant first (score in desc order)
600+
- To search across all the fields in the **books** index for '**eric**' (case-insensitive if the default analyser is
601+
set),
602+
- Results ordered by most relevant first (score in desc order)
600603

601604
```php
602605
Book::term('Eric')->search();
@@ -605,7 +608,8 @@ Book::term('Eric')->search();
605608
**1.2 Multiple terms**
606609

607610
- To search across all the fields in the **books** index for: **eric OR (lean AND startup)**
608-
- ***Note**: You can't start a search query chain with and/or and you can't have subsequent chained terms without and/or - **ordering matters***
611+
- ***Note**: You can't start a search query chain with and/or and you can't have subsequent chained terms without
612+
and/or - **ordering matters***
609613

610614
```php
611615
Book::term('Eric')->orTerm('Lean')->andTerm('Startup')->search();
@@ -636,7 +640,7 @@ Book::term('Eric')->fields(['title','author','description'])->search();
636640
- **title** is boosted by a factor of 3, search hits here will be the most relevant
637641
- **author** is boosted by a factor of 2, search hits here will be the second most relevant
638642
- **description** has no boost, search hits here will be the least relevant
639-
- *The results, as per the default, are ordered by most relevant first (score in desc order)*
643+
- *The results, as per the default, are ordered by most relevant first (score in desc order)*
640644

641645
```php
642646
Book::term('Eric')->field('title',3)->field('author',2)->field('description')->search();
@@ -646,9 +650,9 @@ Book::term('Eric')->field('title',3)->field('author',2)->field('description')->s
646650

647651
- Controls how many 'should' clauses the query should match
648652
- Caveats:
649-
- Fields must be specified in your query
650-
- You can have no standard clauses in your query (ex `where()`)
651-
- Won't work on SoftDelete enabled models
653+
- Fields must be specified in your query
654+
- You can have no standard clauses in your query (ex `where()`)
655+
- Won't work on SoftDelete enabled models
652656
- https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html
653657

654658
- Match at least 2 of the 3 terms:
@@ -660,28 +664,27 @@ Book::term('Eric')->orTerm('Lean')->orTerm('Startup')->field('title')->field('au
660664
**1.7 Min Score**
661665

662666
- Sets a min_score filter for the search
663-
- (Optional, float) Minimum 'relevance score' for matching documents. Documents with a lower 'score' are not included in the search results.
667+
- (Optional, float) Minimum 'relevance score' for matching documents. Documents with a lower 'score' are not included in
668+
the search results.
664669

665670
```php
666671
Book::term('Eric')->field('title',3)->field('author',2)->field('description')->minScore(2.1)->search();
667672
```
668673

669-
**1.8 Blend Search with [most] standard eloquent queries**
674+
**1.8 Blend Search with [most] standard eloquent queries**
670675

671676
- Search for 'david' where field `is_active` is `true`:
672677

673678
```php
674679
Book::term('David')->field('title',3)->field('author',2)->field('description')->minScore(2.1)->where('is_active',true)->search();
675680
```
676681

677-
678-
679682
### 2. FuzzyTerm:
680683

681-
- Same usage as `term()` `andTerm()` `orTerm()` but as
682-
- `fuzzyTerm()`
683-
- `orFuzzyTerm()`
684-
- `andFuzzyTerm()`
684+
- Same usage as `term()` `andTerm()` `orTerm()` but as
685+
- `fuzzyTerm()`
686+
- `orFuzzyTerm()`
687+
- `andFuzzyTerm()`
685688

686689
```php
687690
Book::fuzzyTerm('quikc')->orFuzzyTerm('brwn')->andFuzzyTerm('foks')->search();
@@ -691,17 +694,15 @@ Book::fuzzyTerm('quikc')->orFuzzyTerm('brwn')->andFuzzyTerm('foks')->search();
691694

692695
https://www.elastic.co/guide/en/elasticsearch/reference/current/regexp-syntax.html
693696

694-
- Same usage as `term()` `andTerm()` `orTerm()` but as
695-
- `regEx()`
696-
- `orRegEx()`
697-
- `andRegEx()`
697+
- Same usage as `term()` `andTerm()` `orTerm()` but as
698+
- `regEx()`
699+
- `orRegEx()`
700+
- `andRegEx()`
698701

699702
```php
700703
Book::regEx('joh?n(ath[oa]n)')->andRegEx('doey*')->search();
701704
```
702705

703-
704-
705706
Mutators & Casting
706707
-------------
707708

@@ -1215,7 +1216,8 @@ _[Coming]_
12151216

12161217
Dynamic Indies
12171218
========
1218-
In some cases you will need to split a model into different indices. There are limits to this to keep within reasonable Laravel ORM bounds, but if you keep the index prefix consistent then the plugin can manage the rest.
1219+
In some cases you will need to split a model into different indices. There are limits to this to keep within reasonable
1220+
Laravel ORM bounds, but if you keep the index prefix consistent then the plugin can manage the rest.
12191221

12201222
For example, let's imagine we're tracking page hits, the `PageHit.php` model could be
12211223

@@ -1240,9 +1242,10 @@ If you set a dynamic index you can read/search across all the indices that match
12401242
$pageHits = PageHit::where('page_id',1)->get();
12411243
```
12421244

1243-
You will need to set the record's actual index when creating a new record, with `setIndex('value')`
1245+
You will need to set the record's actual index when creating a new record, with `setIndex('value')`
12441246

12451247
Create example:
1248+
12461249
```php
12471250
$pageHit = new PageHit
12481251
$pageHit->page_id = 4;
@@ -1253,11 +1256,11 @@ $pageHit->save();
12531256
```
12541257

12551258
Each eloquent model will have the current record's index embedded into it, to retrieve it simply call `getRecordIndex()`
1259+
12561260
```php
12571261
$pageHit->getRecordIndex(); //returns page_hits_2021-01-01
12581262
```
12591263

1260-
12611264
```
12621265
12631266
RAW DSL

composer.json

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
{
2-
"name": "pdphilip/elasticsearch",
3-
"description": "An Elasticsearch implementation of Laravel's Eloquent ORM",
4-
"keywords": [
5-
"laravel",
6-
"eloquent",
7-
"elasticsearch",
8-
"elastic",
9-
"database",
10-
"model"
11-
],
12-
"homepage": "https://github.com/pdphilip/laravel-elasticsearch",
13-
"authors": [
14-
{
15-
"name": "David Philip",
16-
"email": "[email protected]",
17-
"homepage": "https://github.com/pdphilip"
18-
}
19-
],
20-
"license": "MIT",
21-
"require": {
22-
"illuminate/support": "^8.0",
23-
"illuminate/container": "^8.0",
24-
"illuminate/database": "^8.0",
25-
"illuminate/events": "^8.0",
26-
"elasticsearch/elasticsearch": "8.7"
27-
},
28-
"require-dev": {
29-
},
30-
"autoload": {
31-
"psr-4": {
32-
"PDPhilip\\Elasticsearch\\": "src/"
33-
}
34-
},
35-
"extra": {
36-
"laravel": {
37-
"providers": [
38-
"PDPhilip\\Elasticsearch\\ElasticServiceProvider"
39-
]
40-
}
2+
"name": "pdphilip/elasticsearch",
3+
"description": "An Elasticsearch implementation of Laravel's Eloquent ORM",
4+
"keywords": [
5+
"laravel",
6+
"eloquent",
7+
"elasticsearch",
8+
"elastic",
9+
"database",
10+
"model"
11+
],
12+
"homepage": "https://github.com/pdphilip/laravel-elasticsearch",
13+
"authors": [
14+
{
15+
"name": "David Philip",
16+
"email": "[email protected]",
17+
"homepage": "https://github.com/pdphilip"
4118
}
19+
],
20+
"license": "MIT",
21+
"require": {
22+
"illuminate/support": "^8.0",
23+
"illuminate/container": "^8.0",
24+
"illuminate/database": "^8.0",
25+
"illuminate/events": "^8.0",
26+
"elasticsearch/elasticsearch": "8.10"
27+
},
28+
"require-dev": {
29+
},
30+
"autoload": {
31+
"psr-4": {
32+
"PDPhilip\\Elasticsearch\\": "src/"
33+
}
34+
},
35+
"extra": {
36+
"laravel": {
37+
"providers": [
38+
"PDPhilip\\Elasticsearch\\ElasticServiceProvider"
39+
]
40+
}
41+
}
4242
}

0 commit comments

Comments
 (0)