Skip to content
This repository was archived by the owner on Jul 31, 2018. It is now read-only.

Commit 083ceae

Browse files
author
maxiloc
authored
Update README.md
1 parent 366cdde commit 083ceae

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

README.md

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This PHP package integrates the Algolia Search API to the Laravel Eloquent ORM.
2525

2626
<!--/NO_HTML-->
2727

28-
# Install
28+
## Install
2929

3030
Add `algolia/algoliasearch-laravel` to your `composer.json` file:
3131

@@ -39,7 +39,7 @@ Add the service provider to `config/app.php` in the `providers` array.
3939
AlgoliaSearch\Laravel\AlgoliaServiceProvider::class
4040
```
4141

42-
# Configuration
42+
## Configuration
4343

4444
Laravel Algolia requires a connection configuration. To get started, you'll need to publish all vendor assets:
4545

@@ -51,7 +51,7 @@ You can add the ```--provider="Vinkla\Algolia\AlgoliaServiceProvider"``` option
5151

5252
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.
5353

54-
# Quick Start
54+
## Quick Start
5555

5656
The following code adds search capabilities to your `Contact` model creating a `Contact` index:
5757

@@ -73,7 +73,7 @@ use Illuminate\Database\Eloquent\Model;
7373
class Contact extends Model
7474
{
7575
use AlgoliaEloquentTrait;
76-
76+
7777
public function getAlgoliaRecord()
7878
{
7979
return array_merge($this->toArray(), [
@@ -83,7 +83,7 @@ class Contact extends Model
8383
}
8484
```
8585

86-
## Ranking & Relevance
86+
### Ranking & Relevance
8787

8888
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:
8989

@@ -93,14 +93,14 @@ use Illuminate\Database\Eloquent\Model;
9393
class Contact extends Model
9494
{
9595
use AlgoliaEloquentTrait;
96-
96+
9797
public $algoliaSettings = [
9898
'attributesToIndex' => [
99-
'id',
99+
'id',
100100
'name',
101101
],
102102
'customRanking' => [
103-
'desc(popularity)',
103+
'desc(popularity)',
104104
'asc(name)',
105105
],
106106
];
@@ -113,7 +113,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
113113
Contact::setSettings();
114114
```
115115

116-
#### Synonyms
116+
##### Synonyms
117117

118118
Synonyms are used to tell the engine about words or expressions that should be considered equal in regard to the textual relevance.
119119

@@ -146,7 +146,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
146146
Contact::setSettings();
147147
```
148148

149-
## Frontend Search (realtime experience)
149+
### Frontend Search (realtime experience)
150150

151151
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.
152152

@@ -162,34 +162,34 @@ index.search('something', function(success, hits) {
162162
}, { hitsPerPage: 10, page: 0 });
163163
```
164164

165-
## Backend Search
165+
### Backend Search
166166

167167
You could also use the `search` method but it's not recommended to implement instant/realtime search experience:
168168

169169
```php
170170
Contact::search('jon doe');
171171
```
172172

173-
# Options
173+
## Options
174174

175-
## Auto-indexing & Asynchronism
175+
### Auto-indexing & Asynchronism
176176

177177
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.
178178

179179
You can disable the auto-indexing and auto-removing setting the following options:
180-
180+
181181
```php
182182
use Illuminate\Database\Eloquent\Model;
183183

184184
class Contact extends Model
185185
{
186186
use AlgoliaEloquentTrait;
187-
187+
188188
public static $autoIndex = false;
189189
public static $autoDelete = false;
190190
}
191191
```
192-
192+
193193
You can temporary disable auto-indexing. This is often used for performance reason.
194194

195195
```php
@@ -237,7 +237,7 @@ Be careful those two methods are defined in AlgoliaEloquentTrait.
237237
When putting those methods in a parent class they will be "erased" by AlgoliaEloquentTrait if used in a child class
238238
(because of php inheritance)
239239

240-
## Custom Index Name
240+
### Custom Index Name
241241

242242
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:
243243

@@ -247,12 +247,12 @@ use Illuminate\Database\Eloquent\Model;
247247
class Contact extends Model
248248
{
249249
use AlgoliaEloquentTrait;
250-
250+
251251
public $indices = ['contact_all'];
252252
}
253253
```
254254

255-
## Per-environment Indexes
255+
### Per-environment Indexes
256256

257257
You can suffix the index name with the current App environment using the following option:
258258

@@ -262,12 +262,12 @@ use Illuminate\Database\Eloquent\Model;
262262
class Contact extends Model
263263
{
264264
use AlgoliaEloquentTrait;
265-
265+
266266
public static $perEnvironment = true; // Index name will be 'Contacts_{\App::environnement()}';
267267
}
268268
```
269269

270-
## Custom `objectID`
270+
### Custom `objectID`
271271

272272
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).
273273

@@ -277,12 +277,12 @@ use Illuminate\Database\Eloquent\Model;
277277
class Contact extends Model
278278
{
279279
use AlgoliaEloquentTrait;
280-
280+
281281
public static $objectIdKey = 'new_key';
282282
}
283283
```
284284

285-
## Restrict Indexing to a Subset of Your Data
285+
### Restrict Indexing to a Subset of Your Data
286286

287287
You can add constraints controlling if a record must be indexed by defining the `indexOnly()` method.
288288

@@ -292,15 +292,15 @@ use Illuminate\Database\Eloquent\Model;
292292
class Contact extends Model
293293
{
294294
use AlgoliaEloquentTrait;
295-
295+
296296
public function indexOnly($index_name)
297297
{
298298
return (bool) $condition;
299299
}
300300
}
301301
```
302302

303-
# Relationships
303+
## Relationships
304304

305305
By default the Algolia package will fetch the **loaded** relationships.
306306

@@ -315,8 +315,8 @@ public function getAlgoliaRecord()
315315
* Load the categories relation so that it's available
316316
* in the laravel toArray method
317317
*/
318-
$this->categories;
319-
318+
$this->categories;
319+
320320
return $this->toArray();
321321
}
322322
```
@@ -334,16 +334,16 @@ public function getAlgoliaRecord()
334334
$extra_data['categories'] = array_map(function ($data) {
335335
return $data['name'];
336336
}, $this->categories->toArray();
337-
337+
338338
return array_merge($this->toArray(), $extra_data);
339339
}
340340
```
341341

342342

343343

344-
# Indexing
344+
## Indexing
345345

346-
## Manual Indexing
346+
### Manual Indexing
347347

348348
You can trigger indexing using the `pushToIndex` instance method.
349349

@@ -352,7 +352,7 @@ $contact = Contact::firstOrCreate(['name' => 'Jean']);
352352
$contact->pushToIndex();
353353
```
354354

355-
## Manual Removal
355+
### Manual Removal
356356

357357
And trigger the removing using the `removeFromIndex` instance method.
358358

@@ -361,7 +361,7 @@ $contact = Contact::firstOrCreate(['name' => 'Jean']);
361361
$contact->removeFromIndex();
362362
```
363363

364-
## Reindexing
364+
### Reindexing
365365

366366
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:
367367

@@ -375,15 +375,15 @@ To reindex all your records (in place, without deleting out-dated records):
375375
Contact::reindex(false);
376376
```
377377

378-
## Clearing an Index
378+
### Clearing an Index
379379

380380
To clear an index, use the `clearIndices` class method:
381381

382382
```ruby
383383
Contact::clearIndices();
384384
```
385385

386-
# Master/Slave
386+
## Master/Slave
387387

388388
You can define slave indexes using the `$algolia_settings` variable:
389389

@@ -393,14 +393,14 @@ use Illuminate\Database\Eloquent\Model;
393393
class Contact extends Model
394394
{
395395
use AlgoliaEloquentTrait;
396-
396+
397397
public $algoliaSettings = [
398398
'attributesToIndex' => [
399-
'id',
399+
'id',
400400
'name',
401401
],
402402
'customRanking' => [
403-
'desc(popularity)',
403+
'desc(popularity)',
404404
'asc(name)',
405405
],
406406
'slaves' => [
@@ -431,7 +431,7 @@ To search using a slave use the following code:
431431
Book::search('foo bar', ['index' => 'contacts_desc']);
432432
```
433433

434-
# Target Multiple Indexes
434+
## Target Multiple Indexes
435435

436436
You can index a record in several indexes using the <code>$indices</code> property:
437437

@@ -441,12 +441,12 @@ use Illuminate\Database\Eloquent\Model;
441441
class Contact extends Model
442442
{
443443
use AlgoliaEloquentTrait;
444-
444+
445445
public $indices = [
446-
'contact_public',
446+
'contact_public',
447447
'contact_private',
448448
];
449-
449+
450450
public function indexOnly($indexName)
451451
{
452452
if ($indexName == 'contact_public')
@@ -464,7 +464,7 @@ To search using an extra index, use the following code:
464464
Book::search('foo bar', ['index' => 'contacts_private']);
465465
```
466466

467-
# Eloquent compatibility
467+
## Eloquent compatibility
468468

469469
Doing :
470470

@@ -482,11 +482,11 @@ Ad::find($id)->update($attributes);
482482
```
483483

484484
<!--NO_HTML-->
485-
# Compatibility
485+
## Compatibility
486486

487487
Compatible with 5.x applications
488488

489-
## License
489+
### License
490490

491491
Laravel Algolia Search is licensed under [The MIT License (MIT)](LICENSE).
492492

0 commit comments

Comments
 (0)