Skip to content

Commit 1219fc1

Browse files
committed
docs update
1 parent aa54ae9 commit 1219fc1

File tree

1 file changed

+103
-57
lines changed

1 file changed

+103
-57
lines changed

README.md

Lines changed: 103 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ 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 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.
2323
>
2424
> #### Versioning Schema: {plugin_version}.{laravel_version}.{iteration}
2525
>
@@ -34,6 +34,10 @@ ____
3434
Installation
3535
===============
3636

37+
[Known] Elasticsearch compatible versions:
38+
- 7.16
39+
- 8.0
40+
3741
Install the package via Composer:
3842

3943
Laravel 9.x:
@@ -310,7 +314,10 @@ Elasticsearch [Matrix](https://www.elastic.co/guide/en/elasticsearch/reference/c
310314
$stats = Product::whereNotIn('color', ['red','green'])->matrix('price');
311315
$stats = Product::whereNotIn('color', ['red', 'green'])->matrix(['price', 'orders']);
312316
```
313-
Matrix results return as (example):
317+
318+
<details>
319+
<summary>Matrix results return as: (Click to expand)</summary>
320+
314321
```json
315322
{
316323
"matrix": {
@@ -351,9 +358,11 @@ Matrix results return as (example):
351358
]
352359
}
353360
}
354-
355361
```
356362

363+
</details>
364+
365+
357366
### Ordering
358367

359368
When searching text fields Elasticsearch uses an internal scoring to rank and sort by the most relevant results as a
@@ -725,7 +734,8 @@ Model Relationships are the lifeblood of any Laravel App, for that you can use t
725734

726735
Full Example:
727736

728-
Company:
737+
<details>
738+
<summary>Company: (Click to expand)</summary>
729739

730740
```php
731741
/**
@@ -737,6 +747,7 @@ Company:
737747
* @property integer $status
738748
* @property \Illuminate\Support\Carbon|null $created_at
739749
* @property \Illuminate\Support\Carbon|null $updated_at
750+
*
740751
******Relationships*******
741752
* @property-read CompanyLog $companyLogs
742753
* @property-read CompanyProfile $companyProfile
@@ -749,7 +760,7 @@ Company:
749760
class Company extends Model
750761
{
751762
protected $connection = 'elasticsearch';
752-
763+
753764
//Relationships =====================================
754765

755766
public function companyLogs()
@@ -774,8 +785,11 @@ class Company extends Model
774785
}
775786

776787
```
788+
</details>
777789

778-
CompanyLog:
790+
791+
<details>
792+
<summary>CompanyLog: (Click to expand)</summary>
779793

780794
```php
781795
/**
@@ -789,6 +803,7 @@ CompanyLog:
789803
* @property mixed $meta
790804
* @property Carbon|null $created_at
791805
* @property Carbon|null $updated_at
806+
*
792807
******Relationships*******
793808
* @property-read Company $company
794809
*
@@ -808,7 +823,10 @@ class CompanyLog extends Model
808823
}
809824
```
810825

811-
CompanyProfile:
826+
</details>
827+
828+
<details>
829+
<summary>CompanyProfile: (Click to expand)</summary>
812830

813831
```php
814832
/**
@@ -821,6 +839,7 @@ CompanyProfile:
821839
* @property string $website
822840
* @property \Illuminate\Support\Carbon|null $created_at
823841
* @property \Illuminate\Support\Carbon|null $updated_at
842+
*
824843
******Relationships*******
825844
* @property-read Company $company
826845
*
@@ -841,7 +860,10 @@ class CompanyProfile extends Model
841860
}
842861
```
843862

844-
Avatar:
863+
</details>
864+
865+
<details>
866+
<summary>Avatar: (Click to expand)</summary>
845867

846868
```php
847869
/**
@@ -854,6 +876,7 @@ Avatar:
854876
* @property string $imageable_type
855877
* @property \Illuminate\Support\Carbon|null $created_at
856878
* @property \Illuminate\Support\Carbon|null $updated_at
879+
*
857880
******Relationships*******
858881
* @property-read Company $company
859882
*
@@ -873,18 +896,24 @@ class Avatar extends Model
873896
}
874897
```
875898

876-
Photo:
899+
</details>
900+
901+
902+
<details>
903+
<summary>Photo: (Click to expand)</summary>
877904

878905
```php
879906
/**
880907
* App\Models\Photo
908+
*
881909
******Fields*******
882910
* @property string $_id
883911
* @property string $url
884912
* @property string $photoable_id
885913
* @property string $photoable_type
886914
* @property \Illuminate\Support\Carbon|null $created_at
887915
* @property \Illuminate\Support\Carbon|null $updated_at
916+
*
888917
******Relationships*******
889918
* @property-read Company $company
890919
*
@@ -904,6 +933,8 @@ class Photo extends Model
904933
}
905934
```
906935

936+
</details>
937+
907938
Example Usage:
908939

909940
```php
@@ -925,6 +956,9 @@ use**: `use PDPhilip\Elasticsearch\Eloquent\HybridRelations`
925956

926957
Example, mysql User model:
927958

959+
<details>
960+
<summary>MySQL => User: (Click to expand)</summary>
961+
928962
```php
929963
use Illuminate\Foundation\Auth\User as Authenticatable;
930964
use PDPhilip\Elasticsearch\Eloquent\HybridRelations;
@@ -933,49 +967,58 @@ use PDPhilip\Elasticsearch\Eloquent\HybridRelations;
933967
* App\Models\User
934968
*
935969
* *****Relationships*******
936-
* @property-read User $user
970+
* @property-read UserLog $userLogs
971+
* @property-read UserProfile $userProfile
972+
* @property-read Company $company
973+
* @property-read Avatar $avatar
974+
* @property-read Photo $photos
937975
*/
938976
class User extends Authenticatable
939977
{
940-
use HybridRelations;
941-
942-
protected $connection = 'mysql';
943-
944-
//Relationships =====================================
945-
// With Elasticsearch models
946-
947-
public function userLogs()
948-
{
949-
return $this->hasMany(UserLog::class);
950-
}
951-
952-
public function userProfile()
953-
{
954-
return $this->hasOne(UserProfile::class);
955-
}
956-
957-
public function company()
958-
{
959-
return $this->belongsTo(Company::class);
960-
}
961-
962-
public function avatar()
963-
{
964-
return $this->morphOne(Avatar::class, 'imageable');
965-
}
966-
967-
public function photos()
968-
{
969-
return $this->morphMany(Photo::class, 'photoable');
970-
}
978+
use HybridRelations;
979+
980+
protected $connection = 'mysql';
981+
982+
//Relationships =====================================
983+
// With Elasticsearch models
984+
985+
public function userLogs()
986+
{
987+
return $this->hasMany(UserLog::class);
988+
}
989+
990+
public function userProfile()
991+
{
992+
return $this->hasOne(UserProfile::class);
993+
}
994+
995+
public function company()
996+
{
997+
return $this->belongsTo(Company::class);
998+
}
999+
1000+
public function avatar()
1001+
{
1002+
return $this->morphOne(Avatar::class, 'imageable');
1003+
}
1004+
1005+
public function photos()
1006+
{
1007+
return $this->morphMany(Photo::class, 'photoable');
1008+
}
9711009
}
9721010
```
9731011

974-
UserLog
1012+
</details>
1013+
1014+
1015+
<details>
1016+
<summary>ES => UserLog: (Click to expand)</summary>
9751017

9761018
```php
9771019
/**
9781020
* App\Models\UserLog
1021+
*
9791022
******Fields*******
9801023
* @property string $_id
9811024
* @property string $company_id
@@ -984,6 +1027,7 @@ UserLog
9841027
* @property mixed $meta
9851028
* @property Carbon|null $created_at
9861029
* @property Carbon|null $updated_at
1030+
*
9871031
******Relationships*******
9881032
* @property-read User $user
9891033
*
@@ -993,7 +1037,7 @@ class UserLog extends Model
9931037
{
9941038

9951039
protected $connection = 'elasticsearch';
996-
1040+
9971041
public function user()
9981042
{
9991043
return $this->belongsTo(User::class);
@@ -1002,14 +1046,17 @@ class UserLog extends Model
10021046
}
10031047
```
10041048

1005-
UserProfile
1049+
</details>
1050+
1051+
1052+
<details>
1053+
<summary>ES => UserProfile: (Click to expand)</summary>
10061054

10071055
```php
10081056
/**
10091057
* App\Models\UserProfile
10101058
*
10111059
******Fields*******
1012-
*
10131060
* @property string $_id
10141061
* @property string $user_id
10151062
* @property string $twitter
@@ -1021,10 +1068,6 @@ UserProfile
10211068
******Relationships*******
10221069
* @property-read User $user
10231070
*
1024-
******Attributes*******
1025-
* @property-read mixed $status_name
1026-
* @property-read mixed $status_color
1027-
*
10281071
* @mixin \Eloquent
10291072
*
10301073
*/
@@ -1034,7 +1077,7 @@ class UserProfile extends Model
10341077
protected $connection = 'elasticsearch';
10351078

10361079
//Relationships =====================================
1037-
1080+
10381081
public function user()
10391082
{
10401083
return $this->belongsTo(User::class);
@@ -1043,7 +1086,10 @@ class UserProfile extends Model
10431086
}
10441087
```
10451088

1046-
- Company (as example before) where user has the filed `company_id` as $company->_id
1089+
</details>
1090+
1091+
1092+
- Company (as example before) where user has the field `company_id` as $company->_id
10471093
- Avatar: (as before) having `imageable_id` as $user->id and `imageable_type` as 'App\Models\User'
10481094
- Photo: (as before) having `photoable_id` as $user->id and `photoable_type` as 'App\Models\User'
10491095

@@ -1239,14 +1285,14 @@ return Product::rawSearch($bodyParams); //Will search within the products index
12391285
Elasticsearchisms
12401286
=================
12411287

1242-
#### Error: all shards failed
1288+
#### [A] Error: all shards failed
12431289

12441290
This error usually points to an index mapping issue, ex:
12451291

12461292
- Trying to order on a TEXT field
12471293
- Trying a get filter on a field that is not explicitly set as one
12481294

1249-
#### Elasticsearch's default search limit is to return 10 collections
1295+
#### [B] Elasticsearch's default search limit is to return 10 collections
12501296

12511297
This plugin sets the default limit to 1000, however you can set your own with `MAX_SIZE`:
12521298

@@ -1265,7 +1311,7 @@ class Product extends Model
12651311

12661312
**Remember, you can use chunking if you need to cycle through all the records**
12671313

1268-
#### Empty Text Fields
1314+
#### [C] Empty Text Fields
12691315

12701316
By default, empty text fields are not searchable as they are not indexed. If you need to be able to search for empty
12711317
values you have two options:
@@ -1274,11 +1320,11 @@ values you have two options:
12741320
2. Create an index where the field is set to have a null value see [Schema](#Schema/index)
12751321
where `$index->keyword('favorite_color')->nullValue('NA'); `
12761322

1277-
#### Ordering by Text field
1323+
#### [D] Ordering by Text field
12781324

12791325
Elasticsearch can not order by text fields due to how the values are indexed and tokenized. If you do not define a
12801326
string value upfront in your [Schema](#Schema/index) then Elasticsearch will default to saving the field as a `text`
1281-
field. If you try to sort by that field the database engine will fail. Options:
1327+
field. If you try to sort by that field the database engine will fail with the error: [all shards failed](#a-error-all-shards-failed). Options:
12821328

12831329
1. If you do not need to search the text within the field and ordering is important, then use a `keyword` field type: To
12841330
do so define your index upfront in the [Schema](#Schema/index) and set `$index->keyword('email')`
@@ -1295,7 +1341,7 @@ field. If you try to sort by that field the database engine will fail. Options:
12951341
able to order by this field you would have to use `orderBy('description.keyword')` to tell elasticsearch which type
12961342
to use.
12971343

1298-
#### Saving and refresh
1344+
#### [E] Saving and refresh
12991345

13001346
Refresh requests are synchronous and do not return a response until the refresh operation completes.
13011347

0 commit comments

Comments
 (0)