You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 11, 2018. It is now read-only.
Copy file name to clipboardExpand all lines: README.md
+60-27Lines changed: 60 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,7 +67,7 @@ use Illuminate\Database\Eloquent\Model;
67
67
class Contact extends Model
68
68
{
69
69
use AlgoliaEloquentTrait;
70
-
70
+
71
71
public function getAlgoliaRecord()
72
72
{
73
73
return array_merge($this->toArray(), [
@@ -87,20 +87,47 @@ use Illuminate\Database\Eloquent\Model;
87
87
class Contact extends Model
88
88
{
89
89
use AlgoliaEloquentTrait;
90
-
90
+
91
91
public $algoliaSettings = [
92
92
'attributesToIndex' => [
93
-
'id',
93
+
'id',
94
94
'name',
95
95
],
96
96
'customRanking' => [
97
-
'desc(popularity)',
97
+
'desc(popularity)',
98
98
'asc(name)',
99
99
],
100
100
];
101
101
}
102
102
```
103
103
104
+
#### Synonyms
105
+
106
+
Synonyms are used to tell the engine about words or expressions that should be considered equal in regard to the textual relevance.
107
+
108
+
Our [synonyms API](https://www.algolia.com/doc/relevance/synonyms) has been designed to manage as easily as possible a large set of synonyms for an index and its slaves.
109
+
110
+
You can use the synonyms API by adding a `synonyms` in `$algoliaSettings` class property like this:
111
+
112
+
```php
113
+
use Illuminate\Database\Eloquent\Model;
114
+
115
+
class Contact extends Model
116
+
{
117
+
use AlgoliaEloquentTrait;
118
+
119
+
public $algoliaSettings = [
120
+
'synonyms' => [
121
+
[
122
+
'objectID' => 'red-color',
123
+
'type' => 'synonym',
124
+
'synonyms' => ['red', 'another red', 'yet another red']
125
+
]
126
+
]
127
+
];
128
+
}
129
+
```
130
+
104
131
You can propagate (save) the settings to algolia using the `setSetting` method:
105
132
106
133
```php
@@ -131,26 +158,32 @@ You could also use the `search` method but it's not recommended to implement ins
131
158
Contact::search('jon doe');
132
159
```
133
160
161
+
You can also pass additional parameters to the search function:
Each time a record is saved; it will be - asynchronously - indexed. On the other hand, each time a record is destroyed, it will be - asynchronously - removed from the index.
139
172
140
173
You can disable the auto-indexing and auto-removing setting the following options:
141
-
174
+
142
175
```php
143
176
use Illuminate\Database\Eloquent\Model;
144
177
145
178
class Contact extends Model
146
179
{
147
180
use AlgoliaEloquentTrait;
148
-
181
+
149
182
public static $autoIndex = false;
150
183
public static $autoDelete = false;
151
184
}
152
185
```
153
-
186
+
154
187
You can temporary disable auto-indexing. This is often used for performance reason.
155
188
156
189
```php
@@ -174,7 +207,7 @@ use Illuminate\Database\Eloquent\Model;
174
207
class Contact extends Model
175
208
{
176
209
use AlgoliaEloquentTrait;
177
-
210
+
178
211
public $indices = ['contact_all'];
179
212
}
180
213
```
@@ -189,7 +222,7 @@ use Illuminate\Database\Eloquent\Model;
189
222
class Contact extends Model
190
223
{
191
224
use AlgoliaEloquentTrait;
192
-
225
+
193
226
public static $perEnvironment = true; // Index name will be 'Contacts_{\App::environnement()}';
194
227
}
195
228
```
@@ -204,7 +237,7 @@ use Illuminate\Database\Eloquent\Model;
204
237
class Contact extends Model
205
238
{
206
239
use AlgoliaEloquentTrait;
207
-
240
+
208
241
public static $objectIdKey = 'new_key';
209
242
}
210
243
```
@@ -219,7 +252,7 @@ use Illuminate\Database\Eloquent\Model;
219
252
class Contact extends Model
220
253
{
221
254
use AlgoliaEloquentTrait;
222
-
255
+
223
256
public function indexOnly($index_name)
224
257
{
225
258
return (bool) $condition;
@@ -235,22 +268,22 @@ If you want to index records that didn't yet load any relations you can do it by
235
268
236
269
It will look like:
237
270
238
-
```
271
+
```php
239
272
public function getAlgoliaRecord()
240
273
{
241
274
/**
242
275
* Load the categories relation so that it's available
243
276
* in the laravel toArray method
244
277
*/
245
-
$this->categories;
246
-
278
+
$this->categories;
279
+
247
280
return $this->toArray();
248
281
}
249
282
```
250
283
251
-
In the resulted object you will have categories converted to array by Laravel. If you want a custom relation structure you will instead do something like:
284
+
In the resulted object you will have categories converted to array by Laravel. If you want a custom relation structure you will instead do something like:
252
285
253
-
```
286
+
```php
254
287
public function getAlgoliaRecord()
255
288
{
256
289
/**
@@ -261,7 +294,7 @@ public function getAlgoliaRecord()
To *safely* reindex all your records (index to a temporary index + move the temporary index to the current one atomically), use the `reindex` class method:
@@ -305,7 +339,7 @@ Contact::reindex(false);
305
339
306
340
To clear an index, use the `clearIndices` class method:
307
341
308
-
```ruby
342
+
```php
309
343
Contact::clearIndices();
310
344
```
311
345
@@ -319,14 +353,14 @@ use Illuminate\Database\Eloquent\Model;
319
353
class Contact extends Model
320
354
{
321
355
use AlgoliaEloquentTrait;
322
-
356
+
323
357
public $algoliaSettings = [
324
358
'attributesToIndex' => [
325
-
'id',
359
+
'id',
326
360
'name',
327
361
],
328
362
'customRanking' => [
329
-
'desc(popularity)',
363
+
'desc(popularity)',
330
364
'asc(name)',
331
365
],
332
366
'slaves' => [
@@ -367,12 +401,12 @@ use Illuminate\Database\Eloquent\Model;
0 commit comments