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 Jul 31, 2018. It is now read-only.
Laravel Algolia requires a connection configuration. To get started, you'll need to publish all vendor assets:
45
45
@@ -51,7 +51,7 @@ You can add the ```--provider="Vinkla\Algolia\AlgoliaServiceProvider"``` option
51
51
52
52
This will create a `config/algolia.php` file in your app that you can modify to set your configuration. Also, make sure you check for changes compared to the original config file after an upgrade.
53
53
54
-
# Quick Start
54
+
##Quick Start
55
55
56
56
The following code adds search capabilities to your `Contact` model creating a `Contact` index:
57
57
@@ -73,7 +73,7 @@ use Illuminate\Database\Eloquent\Model;
73
73
class Contact extends Model
74
74
{
75
75
use AlgoliaEloquentTrait;
76
-
76
+
77
77
public function getAlgoliaRecord()
78
78
{
79
79
return array_merge($this->toArray(), [
@@ -83,7 +83,7 @@ class Contact extends Model
83
83
}
84
84
```
85
85
86
-
## Ranking & Relevance
86
+
###Ranking & Relevance
87
87
88
88
We provide many ways to configure your index settings to tune the overall relevancy but the most important ones are the **searchable attributes** and the attributes reflecting the **record popularity**. You can configure them with the following code:
89
89
@@ -93,14 +93,14 @@ use Illuminate\Database\Eloquent\Model;
93
93
class Contact extends Model
94
94
{
95
95
use AlgoliaEloquentTrait;
96
-
96
+
97
97
public $algoliaSettings = [
98
98
'attributesToIndex' => [
99
-
'id',
99
+
'id',
100
100
'name',
101
101
],
102
102
'customRanking' => [
103
-
'desc(popularity)',
103
+
'desc(popularity)',
104
104
'asc(name)',
105
105
],
106
106
];
@@ -113,7 +113,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
113
113
Contact::setSettings();
114
114
```
115
115
116
-
#### Synonyms
116
+
#####Synonyms
117
117
118
118
Synonyms are used to tell the engine about words or expressions that should be considered equal in regard to the textual relevance.
119
119
@@ -146,7 +146,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
146
146
Contact::setSettings();
147
147
```
148
148
149
-
## Frontend Search (realtime experience)
149
+
###Frontend Search (realtime experience)
150
150
151
151
Traditional search implementations tend to have search logic and functionality on the backend. This made sense when the search experience consisted of a user entering a search query, executing that search, and then being redirected to a search result page.
You could also use the `search` method but it's not recommended to implement instant/realtime search experience:
168
168
169
169
```php
170
170
Contact::search('jon doe');
171
171
```
172
172
173
-
# Options
173
+
##Options
174
174
175
-
## Auto-indexing & Asynchronism
175
+
###Auto-indexing & Asynchronism
176
176
177
177
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.
178
178
179
179
You can disable the auto-indexing and auto-removing setting the following options:
180
-
180
+
181
181
```php
182
182
use Illuminate\Database\Eloquent\Model;
183
183
184
184
class Contact extends Model
185
185
{
186
186
use AlgoliaEloquentTrait;
187
-
187
+
188
188
public static $autoIndex = false;
189
189
public static $autoDelete = false;
190
190
}
191
191
```
192
-
192
+
193
193
You can temporary disable auto-indexing. This is often used for performance reason.
194
194
195
195
```php
@@ -237,7 +237,7 @@ Be careful those two methods are defined in AlgoliaEloquentTrait.
237
237
When putting those methods in a parent class they will be "erased" by AlgoliaEloquentTrait if used in a child class
238
238
(because of php inheritance)
239
239
240
-
## Custom Index Name
240
+
###Custom Index Name
241
241
242
242
By default, the index name will be the pluralized class name, e.g. "Contacts". You can customize the index name by using the `$indices` option:
243
243
@@ -247,12 +247,12 @@ use Illuminate\Database\Eloquent\Model;
247
247
class Contact extends Model
248
248
{
249
249
use AlgoliaEloquentTrait;
250
-
250
+
251
251
public $indices = ['contact_all'];
252
252
}
253
253
```
254
254
255
-
## Per-environment Indexes
255
+
###Per-environment Indexes
256
256
257
257
You can suffix the index name with the current App environment using the following option:
258
258
@@ -262,12 +262,12 @@ use Illuminate\Database\Eloquent\Model;
262
262
class Contact extends Model
263
263
{
264
264
use AlgoliaEloquentTrait;
265
-
265
+
266
266
public static $perEnvironment = true; // Index name will be 'Contacts_{\App::environnement()}';
267
267
}
268
268
```
269
269
270
-
## Custom `objectID`
270
+
###Custom `objectID`
271
271
272
272
By default, the `objectID` is based on your record's `keyName` (`id` by default). You can change this behavior specifying the `objectIdKey` option (be sure to use a uniq field).
273
273
@@ -277,12 +277,12 @@ use Illuminate\Database\Eloquent\Model;
277
277
class Contact extends Model
278
278
{
279
279
use AlgoliaEloquentTrait;
280
-
280
+
281
281
public static $objectIdKey = 'new_key';
282
282
}
283
283
```
284
284
285
-
## Restrict Indexing to a Subset of Your Data
285
+
###Restrict Indexing to a Subset of Your Data
286
286
287
287
You can add constraints controlling if a record must be indexed by defining the `indexOnly()` method.
288
288
@@ -292,15 +292,15 @@ use Illuminate\Database\Eloquent\Model;
292
292
class Contact extends Model
293
293
{
294
294
use AlgoliaEloquentTrait;
295
-
295
+
296
296
public function indexOnly($index_name)
297
297
{
298
298
return (bool) $condition;
299
299
}
300
300
}
301
301
```
302
302
303
-
# Relationships
303
+
##Relationships
304
304
305
305
By default the Algolia package will fetch the **loaded** relationships.
306
306
@@ -315,8 +315,8 @@ public function getAlgoliaRecord()
315
315
* Load the categories relation so that it's available
316
316
* in the laravel toArray method
317
317
*/
318
-
$this->categories;
319
-
318
+
$this->categories;
319
+
320
320
return $this->toArray();
321
321
}
322
322
```
@@ -334,16 +334,16 @@ 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:
367
367
@@ -375,15 +375,15 @@ To reindex all your records (in place, without deleting out-dated records):
375
375
Contact::reindex(false);
376
376
```
377
377
378
-
## Clearing an Index
378
+
###Clearing an Index
379
379
380
380
To clear an index, use the `clearIndices` class method:
381
381
382
382
```ruby
383
383
Contact::clearIndices();
384
384
```
385
385
386
-
# Master/Slave
386
+
##Master/Slave
387
387
388
388
You can define slave indexes using the `$algolia_settings` variable:
389
389
@@ -393,14 +393,14 @@ use Illuminate\Database\Eloquent\Model;
393
393
class Contact extends Model
394
394
{
395
395
use AlgoliaEloquentTrait;
396
-
396
+
397
397
public $algoliaSettings = [
398
398
'attributesToIndex' => [
399
-
'id',
399
+
'id',
400
400
'name',
401
401
],
402
402
'customRanking' => [
403
-
'desc(popularity)',
403
+
'desc(popularity)',
404
404
'asc(name)',
405
405
],
406
406
'slaves' => [
@@ -431,7 +431,7 @@ To search using a slave use the following code:
0 commit comments