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.
You could also use `search` but it's not recommended. This method will search on Algolia
126
+
You could also use `search` but it's not recommended. This method will search on Algolia.
123
127
124
128
```php
125
-
Contact::search("jon doe");
129
+
Contact::search('jon doe');
126
130
```
127
131
128
132
## Options
@@ -134,7 +138,9 @@ Each time a record is saved; it will be - asynchronously - indexed. On the other
134
138
You can disable auto-indexing and auto-removing setting the following options:
135
139
136
140
```php
137
-
class Contact extends \Illuminate\Database\Eloquent\Model
141
+
use Illuminate\Database\Eloquent\Model;
142
+
143
+
class Contact extends Model
138
144
{
139
145
use AlgoliaEloquentTrait;
140
146
@@ -158,10 +164,12 @@ Contact::reindex(); // Will use batch operations.
158
164
159
165
#### Custom Index Name
160
166
161
-
By default, the index name will be the class name pluriazed, e.g. "Contacts". You can customize the index name by using the `indices` option:
167
+
By default, the index name will be the class name pluriazed, e.g. "Contacts". You can customize the index name by using the `$indices` option:
162
168
163
169
```php
164
-
class Contact extends \Illuminate\Database\Eloquent\Model
170
+
use Illuminate\Database\Eloquent\Model;
171
+
172
+
class Contact extends Model
165
173
{
166
174
use AlgoliaEloquentTrait;
167
175
@@ -174,20 +182,24 @@ class Contact extends \Illuminate\Database\Eloquent\Model
174
182
You can suffix the index name with the current Rails environment using the following option:
175
183
176
184
```php
177
-
class Contact extends \Illuminate\Database\Eloquent\Model
185
+
use Illuminate\Database\Eloquent\Model;
186
+
187
+
class Contact extends Model
178
188
{
179
189
use AlgoliaEloquentTrait;
180
190
181
-
public $perEnvironment = true; # index name will be "Contacts_{\App::environnement()}"
191
+
public $perEnvironment = true; // Index name will be 'Contacts_{\App::environnement()}';
182
192
}
183
193
```
184
194
185
-
#### Custom ```objectID```
195
+
#### Custom `objectID`
186
196
187
197
By default, the `objectID` is based on your record's keyName (`id` by default). You can change this behavior specifying the `object_id_key` option (be sure to use a uniq field).
188
198
189
199
```php
190
-
class Contact extends \Illuminate\Database\Eloquent\Model
200
+
use Illuminate\Database\Eloquent\Model;
201
+
202
+
class Contact extends Model
191
203
{
192
204
use AlgoliaEloquentTrait;
193
205
@@ -197,20 +209,18 @@ class Contact extends \Illuminate\Database\Eloquent\Model
197
209
198
210
#### Restrict Indexing to a Subset of Your Data
199
211
200
-
You can add constraints controlling if a record must be indexed by defining indexOnly function.
212
+
You can add constraints controlling if a record must be indexed by defining `indexOnly()` method.
201
213
202
214
```php
203
-
class Contact extends \Illuminate\Database\Eloquent\Model
215
+
use Illuminate\Database\Eloquent\Model;
216
+
217
+
class Contact extends Model
204
218
{
205
219
use AlgoliaEloquentTrait;
206
220
207
221
public function indexOnly($index_name)
208
222
{
209
-
if ($condition) {
210
-
return 1;
211
-
}
212
-
213
-
return 0;
223
+
return (bool) $condition;
214
224
}
215
225
}
216
226
```
@@ -219,56 +229,66 @@ class Contact extends \Illuminate\Database\Eloquent\Model
219
229
220
230
#### Manual Indexing
221
231
222
-
You can trigger indexing using the <code>pushToindex</code> instance method.
232
+
You can trigger indexing using the `pushToindex()` instance method.
To *safely* reindex all your records (index to a temporary index + move the temporary index to the current one atomically), use the <code>reindex</code> class method:
249
+
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:
240
250
241
251
```php
242
-
Contact::reindex()
252
+
Contact::reindex();
243
253
```
244
254
245
255
To reindex all your records (in place, without deleting out-dated records):
246
256
247
257
```php
248
-
Contact::reindex(false)
258
+
Contact::reindex(false);
249
259
```
250
260
251
261
#### Clearing an Index
252
262
253
-
To clear an index, use the <code>clear_index!</code> class method:
263
+
To clear an index, use the `clear_index!` class method:
254
264
255
265
```ruby
256
-
Contact::clearIndices()
266
+
Contact::clearIndices();
257
267
```
258
268
259
269
## Master/Slave
260
270
261
271
You can define slave indexes in the `$algolia_settings` variable:
262
272
263
273
```php
264
-
class Contact extends \Illuminate\Database\Eloquent\Model
0 commit comments