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

Commit d3c55e9

Browse files
algoliareadmebotmaxiloc
authored andcommitted
Update README [skip ci] (#116)
1 parent 32c5420 commit d3c55e9

File tree

1 file changed

+118
-52
lines changed

1 file changed

+118
-52
lines changed

README.md

Lines changed: 118 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<!--NO_HTML-->
2-
# Laravel Algolia Search
3-
<!--/NO_HTML-->
1+
# Algolia Search API Client for Laravel
2+
3+
[Algolia Search](https://www.algolia.com) is a hosted full-text, numerical, and faceted search engine capable of delivering realtime results from the first keystroke.
44

55
This PHP package integrates the Algolia Search API to the Laravel Eloquent ORM. It's based on the [algoliasearch-client-php](https://github.com/algolia/algoliasearch-client-php) package. PHP 5.5.9+ is supported.
66

@@ -10,40 +10,98 @@ This PHP package integrates the Algolia Search API to the Laravel Eloquent ORM.
1010

1111
**Note:** If you're using Laravel 4, checkout the [algoliasearch-laravel-4](https://github.com/algolia/algoliasearch-laravel-4) repository.
1212

13-
<!--NO_HTML-->
1413

15-
## Table of Content
14+
# Table of Contents
15+
16+
17+
**Install**
18+
19+
1. [Install via composer](#install-via-composer)
20+
1. [Service provider](#service-provider)
21+
22+
**Configuration**
23+
24+
1. [Publish vendor](#publish-vendor)
25+
26+
**Quick Start**
27+
28+
1. [Quick Start](#quick-start)
29+
1. [Ranking &amp; Relevance](#ranking--relevance)
30+
1. [Frontend Search (realtime experience)](#frontend-search-realtime-experience)
31+
1. [Backend Search](#backend-search)
32+
33+
**Options**
34+
35+
1. [Auto-indexing &amp; Asynchronism](#auto-indexing--asynchronism)
36+
1. [Custom Index Name](#custom-index-name)
37+
1. [Per-environment Indexes](#per-environment-indexes)
38+
1. [Custom `objectID`](#custom-objectid)
39+
1. [Restrict Indexing to a Subset of Your Data](#restrict-indexing-to-a-subset-of-your-data)
40+
41+
**Relationships**
42+
43+
1. [Relationships](#relationships)
44+
45+
**Indexing**
1646

17-
1. [Install](#install)
18-
2. [Configuration](#configuration)
19-
3. [Quick Start](#quick-start)
20-
4. [Ranking & Relevance](#ranking--relevance)
21-
5. [Options](#options)
22-
6. [Indexing](#indexing)
23-
7. [Primary/Replica](#primaryreplica)
24-
8. [Target multiple indexes](#target-multiple-indexes)
47+
1. [Manual Indexing](#manual-indexing)
48+
1. [Manual Removal](#manual-removal)
49+
1. [Reindexing](#reindexing)
50+
1. [Clearing an Index](#clearing-an-index)
2551

26-
<!--/NO_HTML-->
52+
**Manage indices**
2753

28-
## Install
54+
1. [Primary/Replica](#primaryreplica)
55+
1. [Target Multiple Indexes](#target-multiple-indexes)
2956

30-
### Install via composer
57+
**Eloquent compatibility**
58+
59+
1. [Eloquent compatibility](#eloquent-compatibility)
60+
1. [Compatibility](#compatibility)
61+
62+
63+
# Guides & Tutorials
64+
65+
Check our [online guides](https://www.algolia.com/doc):
66+
67+
* [Data Formatting](https://www.algolia.com/doc/indexing/formatting-your-data)
68+
* [Import and Synchronize data](https://www.algolia.com/doc/indexing/import-synchronize-data/php)
69+
* [Autocomplete](https://www.algolia.com/doc/search/auto-complete)
70+
* [Instant search page](https://www.algolia.com/doc/search/instant-search)
71+
* [Filtering and Faceting](https://www.algolia.com/doc/search/filtering-faceting)
72+
* [Sorting](https://www.algolia.com/doc/relevance/sorting)
73+
* [Ranking Formula](https://www.algolia.com/doc/relevance/ranking)
74+
* [Typo-Tolerance](https://www.algolia.com/doc/relevance/typo-tolerance)
75+
* [Geo-Search](https://www.algolia.com/doc/geo-search/geo-search-overview)
76+
* [Security](https://www.algolia.com/doc/security/best-security-practices)
77+
* [API-Keys](https://www.algolia.com/doc/security/api-keys)
78+
* [REST API](https://www.algolia.com/doc/rest)
79+
80+
81+
# Install
82+
83+
84+
85+
## Install via composer
3186
Add `algolia/algoliasearch-laravel` to your `composer.json` file:
3287

3388
```bash
3489
composer require algolia/algoliasearch-laravel
3590
```
3691

37-
### Service provider
92+
## Service provider
3893
Add the service provider to `config/app.php` in the `providers` array.
3994

4095
```php
4196
AlgoliaSearch\Laravel\AlgoliaServiceProvider::class
4297
```
4398

44-
## Configuration
4599

46-
### Publish vendor
100+
# Configuration
101+
102+
103+
104+
## Publish vendor
47105

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

@@ -55,9 +113,12 @@ You can add the ```--provider="Vinkla\Algolia\AlgoliaServiceProvider"``` option
55113

56114
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.
57115

58-
## Quick Start
59116

60-
### Quick Start
117+
# Quick Start
118+
119+
120+
121+
## Quick Start
61122

62123
The following code adds search capabilities to your `Contact` model creating a `Contact` index:
63124

@@ -95,7 +156,7 @@ After setting up your model, you need to manually do the initial import of your
95156
Contact::reindex();
96157
```
97158

98-
### Ranking & Relevance
159+
## Ranking & Relevance
99160

100161
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:
101162

@@ -125,7 +186,7 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
125186
Contact::setSettings();
126187
```
127188

128-
##### Synonyms
189+
#### Synonyms
129190

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

@@ -158,11 +219,11 @@ You can propagate (save) the settings to algolia using the `setSetting` method:
158219
Contact::setSettings();
159220
```
160221

161-
### Frontend Search (realtime experience)
222+
## Frontend Search (realtime experience)
162223

163224
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.
164225

165-
Implementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of the extra network and processing latency. We highly recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-js) issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.
226+
Implementing search on the backend is no longer necessary. In fact, in most cases it is harmful to performance because of the extra network and processing latency. We highly recommend the usage of our [JavaScript API Client](https://github.com/algolia/algoliasearch-client-javascript) issuing all search requests directly from the end user's browser, mobile device, or client. It will reduce the overall search latency while offloading your servers at the same time.
166227

167228
In your JavaScript code you can do:
168229

@@ -174,17 +235,20 @@ index.search('something', function(success, hits) {
174235
}, { hitsPerPage: 10, page: 0 });
175236
```
176237

177-
### Backend Search
238+
## Backend Search
178239

179240
You could also use the `search` method but it's not recommended to implement a instant/realtime search experience from the backend (having a frontend search gives a better user experience):
180241

181242
```php
182243
Contact::search('jon doe');
183244
```
184245

185-
## Options
186246

187-
### Auto-indexing & Asynchronism
247+
# Options
248+
249+
250+
251+
## Auto-indexing & Asynchronism
188252

189253
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.
190254

@@ -250,7 +314,7 @@ Be careful those two methods are defined in AlgoliaEloquentTrait.
250314
When putting those methods in a parent class they will be "erased" by AlgoliaEloquentTrait if used in a child class
251315
(because of php inheritance)
252316

253-
### Custom Index Name
317+
## Custom Index Name
254318

255319
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:
256320

@@ -265,7 +329,7 @@ class Contact extends Model
265329
}
266330
```
267331

268-
### Per-environment Indexes
332+
## Per-environment Indexes
269333

270334
You can suffix the index name with the current App environment using the following option:
271335

@@ -280,7 +344,7 @@ class Contact extends Model
280344
}
281345
```
282346

283-
### Custom `objectID`
347+
## Custom `objectID`
284348

285349
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).
286350

@@ -295,7 +359,7 @@ class Contact extends Model
295359
}
296360
```
297361

298-
### Restrict Indexing to a Subset of Your Data
362+
## Restrict Indexing to a Subset of Your Data
299363

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

@@ -313,9 +377,12 @@ class Contact extends Model
313377
}
314378
```
315379

316-
## Relationships
317380

318-
### Relationships
381+
# Relationships
382+
383+
384+
385+
## Relationships
319386

320387
By default the Algolia package will fetch the **loaded** relationships.
321388

@@ -355,10 +422,11 @@ public function getAlgoliaRecord()
355422
```
356423

357424

425+
# Indexing
426+
358427

359-
## Indexing
360428

361-
### Manual Indexing
429+
## Manual Indexing
362430

363431
You can trigger indexing using the `pushToIndex` instance method.
364432

@@ -367,7 +435,7 @@ $contact = Contact::firstOrCreate(['name' => 'Jean']);
367435
$contact->pushToIndex();
368436
```
369437

370-
### Manual Removal
438+
## Manual Removal
371439

372440
And trigger the removing using the `removeFromIndex` instance method.
373441

@@ -376,7 +444,7 @@ $contact = Contact::firstOrCreate(['name' => 'Jean']);
376444
$contact->removeFromIndex();
377445
```
378446

379-
### Reindexing
447+
## Reindexing
380448

381449
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:
382450

@@ -414,17 +482,20 @@ Contact::reindex(true, true, false, function ($entities)
414482
});
415483
```
416484

417-
### Clearing an Index
485+
## Clearing an Index
418486

419487
To clear an index, use the `clearIndices` class method:
420488

421489
```ruby
422490
Contact::clearIndices();
423491
```
424492

425-
## Manage indices
426493

427-
### Primary/Replica
494+
# Manage indices
495+
496+
497+
498+
## Primary/Replica
428499

429500
You can define replica indexes using the `$algolia_settings` variable:
430501

@@ -472,7 +543,7 @@ To search using a replica use the following code:
472543
Book::search('foo bar', ['index' => 'contacts_desc']);
473544
```
474545

475-
### Target Multiple Indexes
546+
## Target Multiple Indexes
476547

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

@@ -505,9 +576,12 @@ To search using an extra index, use the following code:
505576
Book::search('foo bar', ['index' => 'contacts_private']);
506577
```
507578

508-
## Eloquent compatibility
509579

510-
### Eloquent compatibility
580+
# Eloquent compatibility
581+
582+
583+
584+
## Eloquent compatibility
511585

512586
Doing :
513587

@@ -524,16 +598,8 @@ To make this query work with Algolia you need to do it like that:
524598
Ad::find($id)->update($attributes);
525599
```
526600

527-
<!--NO_HTML-->
528601
## Compatibility
529602

530-
### Compatibility
531-
532603
Compatible with 5.x applications
533604

534-
## License
535-
### License
536-
537-
Laravel Algolia Search is licensed under [The MIT License (MIT)](LICENSE).
538605

539-
<!--/NO_HTML-->

0 commit comments

Comments
 (0)